From 06087268654a3c512f0dec7fa4c1661ff2f2f500 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 9 Jun 2023 19:32:10 +0200 Subject: [PATCH] perf: cache all receipts of new chain (#3079) --- crates/rpc/rpc/src/eth/cache.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/crates/rpc/rpc/src/eth/cache.rs b/crates/rpc/rpc/src/eth/cache.rs index 0ac644b170..55f50103a1 100644 --- a/crates/rpc/rpc/src/eth/cache.rs +++ b/crates/rpc/rpc/src/eth/cache.rs @@ -499,19 +499,16 @@ where let blocks = blocks.iter().map(|(_, block)| block.block.clone()).collect::>(); - let mut receipts = Vec::new(); - - // TODO ideally we can map all receipts to their respective blocks - - // we only have 1 block in the new chain, so we know all the receipts belong to the - // block - if blocks.len() == 1 { + // also cache all receipts of the blocks + let mut receipts = Vec::with_capacity(blocks.len()); + for block in &blocks { let block_receipts = BlockReceipts { - block_hash: blocks[0].hash, - receipts: state.receipts(blocks[0].number).to_vec(), + block_hash: block.hash, + receipts: state.receipts(block.number).to_vec(), }; receipts.push(block_receipts); } + let _ = eth_state_cache .to_service .send(CacheAction::CacheNewCanonicalChain { blocks, receipts });