Skip to content

Commit 97c117b

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

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

chain/ethereum/src/chain.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,18 @@ impl Blockchain for Chain {
581581
.await
582582
.map_err(IngestorError::Unknown),
583583
ChainClient::Rpc(adapters) => {
584+
let cached = self
585+
.chain_store
586+
.cheap_clone()
587+
.block_ptrs_by_numbers(vec![number])
588+
.await
589+
.unwrap_or_default();
590+
if let Some(ptrs) = cached.get(&number) {
591+
if ptrs.len() == 1 {
592+
return Ok(BlockPtr::new(ptrs[0].hash.clone(), ptrs[0].number));
593+
}
594+
}
595+
584596
let adapter = adapters
585597
.cheapest()
586598
.await
@@ -1075,6 +1087,18 @@ impl TriggersAdapterTrait<Chain> for TriggersAdapter {
10751087
Ok(block.hash() == ptr.hash)
10761088
}
10771089
ChainClient::Rpc(adapter) => {
1090+
let cached = self
1091+
.chain_store
1092+
.cheap_clone()
1093+
.block_ptrs_by_numbers(vec![ptr.number])
1094+
.await
1095+
.unwrap_or_default();
1096+
if let Some(ptrs) = cached.get(&ptr.number) {
1097+
if ptrs.len() == 1 {
1098+
return Ok(ptrs[0].hash == ptr.hash);
1099+
}
1100+
}
1101+
10781102
let adapter = adapter
10791103
.cheapest()
10801104
.await

0 commit comments

Comments
 (0)