chain/ethereum: Reduce unnecessary eth_getBlockByHash and eth_getBlockByNumber RPC calls#6491
Open
chain/ethereum: Reduce unnecessary eth_getBlockByHash and eth_getBlockByNumber RPC calls#6491
Conversation
…block_pointer_from_number Both methods previously always made an eth_getBlockByNumber RPC call. is_on_main_chain is called every reconciliation cycle for subgraphs that are beyond the reorg threshold, so with many syncing subgraphs this generated a flood of unnecessary calls for blocks already in the cache. Both methods now check chain_store.block_ptrs_by_numbers first and only fall back to RPC when the cache has no entry or an ambiguous result (multiple blocks at the same number due to a recorded reorg).
…_rpc fetch_full_block_with_rpc previously called adapter.block_by_hash() directly, bypassing the block cache and always making an eth_getBlockByHash RPC call. It is called from ancestor_block when the cached block has no receipts, or after walking back the chain via parent_ptr (which populates the cache). In both cases the block may already be available in the cache. Change it to delegate the light block fetch to fetch_light_block_with_rpc, which goes through adapter.load_blocks() and chain_store.blocks() — checking recent_blocks_cache and the DB before falling back to RPC.
incrypto32
approved these changes
Apr 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Both eth_getBlockByHash and eth_getBlockByNumber were being called unconditionally in several places, even when the block data was already available in the block cache. With many syncing subgraphs this generates a flood of redundant RPC calls.
This PR makes three methods cache-aware before falling back to RPC:
No semantic changes — RPC is still the fallback whenever the cache doesn't have a definitive answer.