Skip to content

fix(indexer): correct v2 event attribution and record-value handling - #138

Merged
mdtanrikulu merged 3 commits into
fix/heal-stall-per-reorgfrom
fix/v2-event-attribution
Sep 30, 2026
Merged

mdtanrikulu merged 3 commits into
fix/heal-stall-per-reorgfrom
fix/v2-event-attribution

Conversation

@mdtanrikulu

Copy link
Copy Markdown
Contributor

DataChanged: the only shape Sepolia emits was being dropped

indexed is not part of an event signature hash, so one topic0 is emitted by
contracts that disagree on how many parameters reach data. A census of every
DataChanged(bytes32,string,string,bytes) log on Sepolia — re-run twice,
independently:

  • 79 logs, 26 distinct emitters, blocks 9.5M–11.8M
  • topic counts: {4: 79} — the 3-topic form has never occurred there
  • keccak256(payload string) == topics[2] for 79/79, zero mismatches
  • payload is exactly one head word + one padded string, no trailing words
  • 1 log carries topics[3] == keccak256("")

So the emitters mark value as indexed too: data holds only the key, and
topics[3] is keccak256(value). A topics.len != 3 guard rejected all 79, and
decoding a 4-topic payload against the two-parameter schema read the key's length
word as the value's tail offset — which is how one such log reached an unchecked
add in the codec and stalled a sync.

Both shapes are now handled, and the 4-topic arm proves its layout (the
decoded key must hash to topics[2]) rather than trusting the topic count.

Why no value is stored

A keccak preimage search over each transaction's calldata and sibling logs
recovers 41 of 78 non-empty values — sound, since a preimage match is proof,
but it needs an extra RPC plus an unbounded scan per event and still leaves 37
unknowable forever. So the honest representation is required either way.

resolver_datas.value is TEXT NOT NULL and "" already means cleared, so
there is nothing truthful to put there: the hash would be served as a 32-byte
value. Therefore keccak256("") takes the existing delete path, and any other
hash stores no row — dropping a pre-existing one, since the chain says the
value changed — while the hash travels in event history as valueHash, never
value. Replay is taught the same distinction.

Three more attribution defects

DNS root vs. malformed. decodeDNSNameToString collapsed both into null,
so a handler discarded three legitimate root-name records as undecodable while
its sibling correctly read the same null as the default binding. Fixed at the
wrapper: null means the root and nothing else; a malformed encoding propagates
and is skipped per-event with its coordinates. The test that pinned the
conflation now pins them apart.

Transfer ownership was keyed wrongly in two of three places. A tokenId
collides across registries, so ownership must key on (tokenId, emitting registry). The live path did; replay and at-block reconstruction keyed on the
events row's namehash — a denormalised copy that is NULL on an orphaned transfer.
Both now re-derive it, matching the resolver_updated arms that already did. A
transfer for an unknown token records a tokenId:<dec> placeholder so the
existing repair ledger can heal it, instead of a row unreachable from its name.

The approvals re-key was gated on a namehash it never reads. It keys on
(tokenId, registry), both present in the log, so an un-indexed name left the
approval pointing at a retired token id permanently — the name row is re-keyed on
a later sighting, the approval never was.

Two fixture bugs found along the way

Replay's and conformance's .transfer rows were {"to":…} with
contract_address = Address.zero — a shape the live indexer never emits. That
is what made a golden fail, so the fixtures were corrected (and a foreign-registry
transfer added, which must no-op); no golden was regenerated.

resolver_datas, resolver_links and resolver_named_resources were in
neither replay-parity gate, and the two gates disagreed on which they covered
— so the new replay arm would have shipped unverified. Added to both.

Schema descriptions that were false

data(key) documented its null as "unset" and dataKeys as "All data(key)
keys set". Neither holds for a record whose value was only ever on chain as a
hash. Both now say what is true and point at the event surface.

Verification

Lane Result
test-all 89/89 steps, 1483/1483
test-pg 6/6 steps, 20/20
test-storage-pg 28/28 steps, 278/279 (1 skipped, baseline parity)
test-integration-pg 4/4 steps, 41/41

Seven sabotage checks — each fix reverted, the suite confirmed to fail. Two of the
new tests initially passed under sabotage because they were guarded on a
configured contract address that is zero in the test environment; they were made
config-independent. Three existing tests are no-ops for that same reason and are
called out below.

Known limitations

  • The fail-fast delete on the unassertable-value path is reasoned, not
    test-pinned
    — exercising it needs database fault injection.
  • Legacy DataChanged writes under the raw node while reads map through
    resolveRecordKey, so on a resolver carrying a Linked row even a plain value
    lands where no read looks. Pre-existing; separate fix.
  • Replay's .data_updated arm has no valueHash branch. Latent today, since
    that path is always plaintext.
  • Three tests are silently skipped wherever the deployment env is absent
    (including CI) because they guard on a configured registry address.
  • Surfacing these 79 keys through dataKeys/data(key) needs a schema column and
    a product decision on how a hashed record reads; not attempted here.

@mdtanrikulu
mdtanrikulu added this pull request to stack #139 September 30, 2026 12:36
Index the indexed-value DataChanged variant, split the DNS root name from a malformed encoding, key transfer ownership on (token id,
  emitting registry) in replay and at-block too, and degate the approvals re-key.
@mdtanrikulu
mdtanrikulu force-pushed the fix/v2-event-attribution branch from 5662057 to b946c1f Compare September 30, 2026 12:41
@mdtanrikulu
mdtanrikulu merged commit 68f11ca into staging Sep 30, 2026
4 checks passed
@mdtanrikulu
mdtanrikulu deleted the fix/v2-event-attribution branch September 30, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant