Skip to content

Commit

Permalink
Remove redundant trait method LoadBlock::provider
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane committed Oct 26, 2024
1 parent 255e296 commit d5fedd9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 27 deletions.
7 changes: 1 addition & 6 deletions crates/optimism/rpc/src/eth/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use reth_chainspec::ChainSpecProvider;
use reth_node_api::{FullNodeComponents, NodeTypes};
use reth_optimism_chainspec::OpChainSpec;
use reth_primitives::TransactionMeta;
use reth_provider::{BlockReaderIdExt, HeaderProvider};
use reth_provider::HeaderProvider;
use reth_rpc_eth_api::{
helpers::{EthBlocks, LoadBlock, LoadPendingBlock, LoadReceipt, SpawnBlocking},
RpcReceipt,
Expand Down Expand Up @@ -87,11 +87,6 @@ where
Self: LoadPendingBlock + SpawnBlocking,
N: FullNodeComponents,
{
#[inline]
fn provider(&self) -> impl BlockReaderIdExt {
self.inner.provider()
}

#[inline]
fn cache(&self) -> &EthStateCache {
self.inner.cache()
Expand Down
25 changes: 11 additions & 14 deletions crates/rpc/rpc-eth-api/src/helpers/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ pub trait EthBlocks: LoadBlock {
async move {
if block_id.is_pending() {
// Pending block can be fetched directly without need for caching
return Ok(LoadBlock::provider(self)
return Ok(RpcNodeCore::provider(self)
.pending_block()
.map_err(Self::Error::from_eth_err)?
.map(|block| block.body.transactions.len()))
}

let block_hash = match LoadBlock::provider(self)
let block_hash = match RpcNodeCore::provider(self)
.block_hash_for_id(block_id)
.map_err(Self::Error::from_eth_err)?
{
Expand Down Expand Up @@ -132,7 +132,7 @@ pub trait EthBlocks: LoadBlock {
if block_id.is_pending() {
// First, try to get the pending block from the provider, in case we already
// received the actual pending block from the CL.
if let Some((block, receipts)) = LoadBlock::provider(self)
if let Some((block, receipts)) = RpcNodeCore::provider(self)
.pending_block_and_receipts()
.map_err(Self::Error::from_eth_err)?
{
Expand All @@ -145,7 +145,7 @@ pub trait EthBlocks: LoadBlock {
}
}

if let Some(block_hash) = LoadBlock::provider(self)
if let Some(block_hash) = RpcNodeCore::provider(self)
.block_hash_for_id(block_id)
.map_err(Self::Error::from_eth_err)?
{
Expand All @@ -167,7 +167,7 @@ pub trait EthBlocks: LoadBlock {
&self,
block_id: BlockId,
) -> Result<Option<Vec<reth_primitives::Header>>, Self::Error> {
LoadBlock::provider(self).ommers_by_id(block_id).map_err(Self::Error::from_eth_err)
RpcNodeCore::provider(self).ommers_by_id(block_id).map_err(Self::Error::from_eth_err)
}

/// Returns uncle block at given index in given block.
Expand All @@ -182,12 +182,12 @@ pub trait EthBlocks: LoadBlock {
async move {
let uncles = if block_id.is_pending() {
// Pending block can be fetched directly without need for caching
LoadBlock::provider(self)
RpcNodeCore::provider(self)
.pending_block()
.map_err(Self::Error::from_eth_err)?
.map(|block| block.body.ommers)
} else {
LoadBlock::provider(self)
RpcNodeCore::provider(self)
.ommers_by_id(block_id)
.map_err(Self::Error::from_eth_err)?
}
Expand All @@ -202,11 +202,6 @@ pub trait EthBlocks: LoadBlock {
///
/// Behaviour shared by several `eth_` RPC methods, not exclusive to `eth_` blocks RPC methods.
pub trait LoadBlock: LoadPendingBlock + SpawnBlocking {
// Returns a handle for reading data from disk.
///
/// Data access in default (L1) trait method implementations.
fn provider(&self) -> impl BlockReaderIdExt;

/// Returns a handle for reading data from memory.
///
/// Data access in default (L1) trait method implementations.
Expand All @@ -220,7 +215,8 @@ pub trait LoadBlock: LoadPendingBlock + SpawnBlocking {
async move {
if block_id.is_pending() {
// Pending block can be fetched directly without need for caching
if let Some(pending_block) = RpcNodeCore::provider(self)
if let Some(pending_block) = self
.provider()
.pending_block_with_senders()
.map_err(Self::Error::from_eth_err)?
{
Expand All @@ -234,7 +230,8 @@ pub trait LoadBlock: LoadPendingBlock + SpawnBlocking {
};
}

let block_hash = match RpcNodeCore::provider(self)
let block_hash = match self
.provider()
.block_hash_for_id(block_id)
.map_err(Self::Error::from_eth_err)?
{
Expand Down
3 changes: 2 additions & 1 deletion crates/rpc/rpc-eth-api/src/helpers/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ pub trait EthCall: Call + LoadPendingBlock {
// if it's not pending, we should always use block_hash over block_number to ensure that
// different provider calls query data related to the same block.
if !is_block_target_pending {
target_block = LoadBlock::provider(self)
target_block = self
.provider()
.block_hash_for_id(target_block)
.map_err(|_| EthApiError::HeaderNotFound(target_block))?
.ok_or_else(|| EthApiError::HeaderNotFound(target_block))?
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-eth-api/src/helpers/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ pub trait EthTransactions: LoadTransaction {
return Ok(None);
}

let Ok(high) = LoadBlock::provider(self).best_block_number() else {
let Ok(high) = RpcNodeCore::provider(self).best_block_number() else {
return Err(EthApiError::HeaderNotFound(BlockNumberOrTag::Latest.into()).into());
};

Expand Down
5 changes: 0 additions & 5 deletions crates/rpc/rpc/src/eth/helpers/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ where
Self: LoadPendingBlock + SpawnBlocking,
Provider: BlockReaderIdExt,
{
#[inline]
fn provider(&self) -> impl BlockReaderIdExt {
self.inner.provider()
}

#[inline]
fn cache(&self) -> &EthStateCache {
self.inner.cache()
Expand Down

0 comments on commit d5fedd9

Please sign in to comment.