Skip to content

Commit

Permalink
fix: resolve merge conflicts in block.rs and cache mod
Browse files Browse the repository at this point in the history
  • Loading branch information
lean-apple committed Dec 20, 2024
1 parent 3c35322 commit acc7fb0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 29 deletions.
74 changes: 47 additions & 27 deletions crates/rpc/rpc-eth-api/src/helpers/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::Arc;
use alloy_eips::BlockId;
use alloy_primitives::Sealable;
use alloy_rlp::Encodable;
use alloy_rpc_types_eth::{Block, BlockTransactions, Header, Index};
use alloy_rpc_types_eth::{Block, BlockNumberOrTag, BlockTransactions, Header, Index};
use futures::Future;
use reth_node_api::BlockBody;
use reth_primitives::{SealedBlockFor, SealedBlockWithSenders};
Expand Down Expand Up @@ -91,21 +91,31 @@ pub trait EthBlocks: LoadBlock {
.map(|block| block.body.transactions().len()))
}

let block_hash = match self
.provider()
.block_hash_for_id(block_id)
.map_err(Self::Error::from_eth_err)?
{
Some(block_hash) => block_hash,
None => return Ok(None),
};
match block_id {
BlockId::Number(BlockNumberOrTag::Latest) => Ok(self
.cache()
.latest_block_with_senders()
.await
.map_err(Self::Error::from_eth_err)?
.map(|b| b.body.transactions().len())),
_ => {
let block_hash = match self
.provider()
.block_hash_for_id(block_id)
.map_err(Self::Error::from_eth_err)?
{
Some(block_hash) => block_hash,
None => return Ok(None),
};

Ok(self
.cache()
.get_sealed_block_with_senders(block_hash)
.await
.map_err(Self::Error::from_eth_err)?
.map(|b| b.body.transactions().len()))
Ok(self
.cache()
.get_sealed_block_with_senders(block_hash)
.await
.map_err(Self::Error::from_eth_err)?
.map(|b| b.body.transactions().len()))
}
}
}
}

Expand Down Expand Up @@ -241,19 +251,29 @@ pub trait LoadBlock: LoadPendingBlock + SpawnBlocking + RpcNodeCoreExt {
};
}

let block_hash = match self
.provider()
.block_hash_for_id(block_id)
.map_err(Self::Error::from_eth_err)?
{
Some(block_hash) => block_hash,
None => return Ok(None),
};
let block = match block_id {
BlockId::Number(BlockNumberOrTag::Latest) => self
.cache()
.latest_block_with_senders()
.await
.map_err(Self::Error::from_eth_err)?,
_ => {
let block_hash = match self
.provider()
.block_hash_for_id(block_id)
.map_err(Self::Error::from_eth_err)?
{
Some(block_hash) => block_hash,
None => return Ok(None),
};

self.cache()
.get_sealed_block_with_senders(block_hash)
.await
.map_err(Self::Error::from_eth_err)
self.cache()
.get_sealed_block_with_senders(block_hash)
.await
.map_err(Self::Error::from_eth_err)?
}
};
Ok(block)
}
}
}
4 changes: 2 additions & 2 deletions crates/rpc/rpc-eth-types/src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ impl<B: Block, R: Send + Sync> EthStateCache<B, R> {

/// Returns the most recent canonical block from the cache, if available.
/// Used to efficiently handle latest block requests and avoid race conditions during chain
/// reorgs.
/// Returns None if no canonical chain is tracked or during reorgs.
/// reorgs.
/// Returns `None` if no canonical chain is tracked or during reorgs.
pub async fn latest_block_with_senders(
&self,
) -> ProviderResult<Option<Arc<SealedBlockWithSenders<B>>>> {
Expand Down

0 comments on commit acc7fb0

Please sign in to comment.