Skip to content

Commit

Permalink
fix: fix with fallback for lastest hash not cached
Browse files Browse the repository at this point in the history
  • Loading branch information
lean-apple committed Dec 20, 2024
1 parent 88a8516 commit 3761549
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions crates/rpc/rpc-eth-api/src/helpers/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub trait EthBlocks: LoadBlock {
.provider()
.pending_block()
.map_err(Self::Error::from_eth_err)?
.map(|block| block.body.transactions().len()))
.map(|block| block.body.transactions().len()));
}

match block_id {
Expand Down Expand Up @@ -165,7 +165,7 @@ pub trait EthBlocks: LoadBlock {
.get_block_and_receipts(block_hash)
.await
.map_err(Self::Error::from_eth_err)
.map(|b| b.map(|(b, r)| (b.block.clone(), r)))
.map(|b| b.map(|(b, r)| (b.block.clone(), r)));
}

Ok(None)
Expand Down Expand Up @@ -252,11 +252,30 @@ pub trait LoadBlock: LoadPendingBlock + SpawnBlocking + RpcNodeCoreExt {
}

let block = match block_id {
BlockId::Number(BlockNumberOrTag::Latest) => self
.cache()
.latest_block_with_senders()
.await
.map_err(Self::Error::from_eth_err)?,
BlockId::Number(BlockNumberOrTag::Latest) => {
if let Some(block) = self
.cache()
.latest_block_with_senders()
.await
.map_err(Self::Error::from_eth_err)?
{
Some(block)
} else {
// Fallback to traditional lookup if latest isn't cached
match self
.provider()
.block_hash_for_id(block_id)
.map_err(Self::Error::from_eth_err)?
{
Some(block_hash) => self
.cache()
.get_sealed_block_with_senders(block_hash)
.await
.map_err(Self::Error::from_eth_err)?,
None => None,
}
}
}
_ => {
let block_hash = match self
.provider()
Expand Down

0 comments on commit 3761549

Please sign in to comment.