Skip to content

store, chain/ethereum: Add header-only ChainStore query methods#6456

Merged
lutter merged 2 commits intomasterfrom
lutter/block-ptr
Mar 26, 2026
Merged

store, chain/ethereum: Add header-only ChainStore query methods#6456
lutter merged 2 commits intomasterfrom
lutter/block-ptr

Conversation

@lutter
Copy link
Collaborator

@lutter lutter commented Mar 25, 2026

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.

@lutter lutter requested a review from incrypto32 March 25, 2026 23:24
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.
@lutter lutter force-pushed the lutter/block-ptr branch from 15826fb to ac28b4d Compare March 25, 2026 23:25
.map(|(parent_hash, number)| {
BlockPtr::new(
BlockHash::from(parent_hash),
i32::try_from(number).unwrap() - 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Collaborator Author

@lutter lutter Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).
@lutter lutter merged commit 9bf36c7 into master Mar 26, 2026
6 checks passed
@lutter lutter deleted the lutter/block-ptr branch March 26, 2026 19:33
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.

2 participants