store, chain/ethereum: Add header-only ChainStore query methods#6456
Merged
store, chain/ethereum: Add header-only ChainStore query methods#6456
Conversation
Add `ancestor_block_ptr` and `block_parent_ptr` to the `ChainStore` trait. These methods read only header columns (hash, number, parent_hash) and skip fetching/deserializing the `data` JSONB column, which is significant for callers that never use the block body. `ancestor_block_ptr` reuses the existing recursive CTE but omits the second SQL query that fetches `data`. `block_parent_ptr` queries only the parent_hash and number columns for a given block hash. Update the two callers that were discarding block data anyway: - graphman `chain info` now uses `ancestor_block_ptr` - Ethereum `parent_ptr` (Firehose path) now uses `block_parent_ptr` This is preparatory work for the block cache revamp where the data column becomes nullable for old blocks.
15826fb to
ac28b4d
Compare
incrypto32
approved these changes
Mar 26, 2026
store/postgres/src/chain_store.rs
Outdated
| .map(|(parent_hash, number)| { | ||
| BlockPtr::new( | ||
| BlockHash::from(parent_hash), | ||
| i32::try_from(number).unwrap() - 1, |
Member
There was a problem hiding this comment.
nit: number - 1 assumes consecutive block numbers, I wrote the previous code in same file with the same assumption 😅. maybe worth a discussion if we still want to support these chains that skip blocks like Filecoin
Collaborator
Author
There was a problem hiding this comment.
Good point. We should have a discussion about that; in the meantime, I am changing that so that we use the parent_hash to look up the block number to avoid issues with chains that have gaps.
Besides Filecoin, I think NEAR has that, too.
Look up the parent block's actual number instead of computing `current_number - 1`, which is incorrect for blockchains with gaps in block numbers (e.g., NEAR).
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.
Add
ancestor_block_ptrandblock_parent_ptrto theChainStoretrait. These methods read only header columns (hash, number, parent_hash) and skip fetching/deserializing thedataJSONB column, which is significant for callers that never use the block body.ancestor_block_ptrreuses the existing recursive CTE but omits the second SQL query that fetchesdata.block_parent_ptrqueries only the parent_hash and number columns for a given block hash.Update the two callers that were discarding block data anyway:
chain infonow usesancestor_block_ptrparent_ptr(Firehose path) now usesblock_parent_ptrThis is preparatory work for the block cache revamp where the data column becomes nullable for old blocks.