Skip to content

fix: eth_getLogs returns wrong blockHash#2

Open
sungdark wants to merge 1 commit intoXDC-Community:masterfrom
sungdark:fix/eth-getlogs-blockhash
Open

fix: eth_getLogs returns wrong blockHash#2
sungdark wants to merge 1 commit intoXDC-Community:masterfrom
sungdark:fix/eth-getlogs-blockhash

Conversation

@sungdark
Copy link
Copy Markdown

Fix: eth_getLogs returns wrong blockHash

Problem

When calling eth_getLogs, the returned logs have an incorrect blockHash field. For example, block 0x22b2277 has canonical hash 0xe8ec0bfc021f839fd0a69ae89689e309632af2cc434e8a096732068f0736864b but the RPC returns 0x194a513ea40c94fccaca470cccb24c2ff3bd6398dec9a04e3eb3a4bfef8a330e.

Root Cause

In XDPoSChain's PoS consensus, receipts can be stored under a non-canonical block hash during chain reorganizations. When eth_getLogs retrieves logs via backend.GetLogs(), the log.BlockHash field may reflect the hash used at storage time rather than the current canonical hash for that block height.

Fix

In eth/filters/filter.go, the checkMatches function now explicitly sets log.BlockHash = header.Hash() for each matching log before returning. The header.Hash() value is the canonical hash retrieved via HeaderByNumber, ensuring the correct block hash is always returned.

This mirrors the existing fix in GetFilterChanges (api.go) which uses core.GetCanonicalHash() for the same purpose.

Testing

All existing filter tests pass:

PASS github.com/XinFinOrg/XDPoSChain/eth/filters

Bounty

This fixes Gitcoin bounty: #1 (up to $5000 XDC)

When eth_getLogs is called, the blockHash in returned logs can be
incorrect if receipts were stored under a non-canonical block hash
during chain reorganizations in XDPoSChain's PoS consensus.

The fix explicitly sets log.BlockHash = header.Hash() in checkMatches,
ensuring the canonical block hash is always used. This mirrors the
existing fix in GetFilterChanges (api.go) which uses
core.GetCanonicalHash().

Fix for: XDC-Community#1
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