Skip to content

Commit 7b7626a

Browse files
committed
chain/ethereum: Check block cache before RPC in fetch_full_block_with_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.
1 parent 97c117b commit 7b7626a

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

chain/ethereum/src/chain.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,16 +1284,14 @@ impl TriggersAdapter {
12841284
adapters: &EthereumNetworkAdapters,
12851285
block_ptr: &BlockPtr,
12861286
) -> Result<Option<EthereumBlock>, Error> {
1287-
let adapter = adapters.cheapest_with(&self.capabilities).await?;
1288-
1289-
let block = adapter
1290-
.block_by_hash(&self.logger, block_ptr.hash.as_b256())
1291-
.await?;
1292-
1293-
match block {
1294-
Some(block) => {
1287+
// Use the cache-aware light block fetch first; it checks recent_blocks_cache
1288+
// and the DB before falling back to eth_getBlockByHash.
1289+
let light_block = self.fetch_light_block_with_rpc(adapters, block_ptr).await?;
1290+
match light_block {
1291+
Some(light_block) => {
1292+
let adapter = adapters.cheapest_with(&self.capabilities).await?;
12951293
let ethereum_block = adapter
1296-
.load_full_block(&self.logger, block)
1294+
.load_full_block(&self.logger, light_block.inner().clone())
12971295
.await
12981296
.map_err(|e| anyhow!("Failed to load full block: {}", e))?;
12991297
Ok(Some(ethereum_block))

0 commit comments

Comments
 (0)