chore(rpc): remove redundant LoadFee::provider (#12122)

This commit is contained in:
Emilia Hane
2024-10-28 18:14:11 +08:00
committed by GitHub
parent e4bd13534d
commit 77e5748124
4 changed files with 28 additions and 42 deletions

View File

@ -14,15 +14,15 @@ use std::{fmt, sync::Arc};
use alloy_primitives::U256;
use derive_more::Deref;
use op_alloy_network::Optimism;
use reth_chainspec::EthereumHardforks;
use reth_chainspec::{EthChainSpec, EthereumHardforks};
use reth_evm::ConfigureEvm;
use reth_network_api::NetworkInfo;
use reth_node_api::{FullNodeComponents, NodeTypes};
use reth_node_builder::EthApiBuilderCtx;
use reth_primitives::Header;
use reth_provider::{
BlockIdReader, BlockNumReader, BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider,
HeaderProvider, StageCheckpointReader, StateProviderFactory,
BlockNumReader, BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider, EvmEnvProvider,
StageCheckpointReader, StateProviderFactory,
};
use reth_rpc::eth::{core::EthApiInner, DevSigner};
use reth_rpc_eth_api::{
@ -184,23 +184,21 @@ where
impl<N> LoadFee for OpEthApi<N>
where
Self: LoadBlock,
N: FullNodeComponents<Types: NodeTypes<ChainSpec: EthereumHardforks>>,
Self: LoadBlock<Provider = N::Provider>,
N: RpcNodeCore<
Provider: BlockReaderIdExt
+ EvmEnvProvider
+ ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
+ StateProviderFactory,
>,
{
#[inline]
fn provider(
&self,
) -> impl BlockIdReader + HeaderProvider + ChainSpecProvider<ChainSpec: EthereumHardforks> {
self.inner.provider()
}
#[inline]
fn cache(&self) -> &EthStateCache {
self.inner.cache()
}
#[inline]
fn gas_oracle(&self) -> &GasPriceOracle<impl BlockReaderIdExt> {
fn gas_oracle(&self) -> &GasPriceOracle<Self::Provider> {
self.inner.gas_oracle()
}

View File

@ -20,7 +20,7 @@ pub type BlockAndReceiptsResult<E> = Result<Option<(SealedBlock, Arc<Vec<Receipt
/// Block related functions for the [`EthApiServer`](crate::EthApiServer) trait in the
/// `eth_` namespace.
pub trait EthBlocks: LoadBlock<Provider: HeaderProvider> {
pub trait EthBlocks: LoadBlock {
/// Returns the block header for the given block id.
fn rpc_block_header(
&self,

View File

@ -3,8 +3,8 @@
use alloy_primitives::U256;
use alloy_rpc_types::{BlockNumberOrTag, FeeHistory};
use futures::Future;
use reth_chainspec::{EthChainSpec, EthereumHardforks};
use reth_provider::{BlockIdReader, BlockReaderIdExt, ChainSpecProvider, HeaderProvider};
use reth_chainspec::EthChainSpec;
use reth_provider::{BlockIdReader, ChainSpecProvider, HeaderProvider};
use reth_rpc_eth_types::{
fee_history::calculate_reward_percentiles_for_block, EthApiError, EthStateCache,
FeeHistoryCache, FeeHistoryEntry, GasPriceOracle, RpcInvalidTransactionError,
@ -82,7 +82,8 @@ pub trait EthFees: LoadFee {
block_count = block_count.saturating_sub(1);
}
let end_block = LoadFee::provider(self)
let end_block = self
.provider()
.block_number_for_id(newest_block.into())
.map_err(Self::Error::from_eth_err)?
.ok_or(EthApiError::HeaderNotFound(newest_block.into()))?;
@ -147,13 +148,12 @@ pub trait EthFees: LoadFee {
// Also need to include the `base_fee_per_gas` and `base_fee_per_blob_gas` for the
// next block
base_fee_per_gas
.push(last_entry.next_block_base_fee(LoadFee::provider(self).chain_spec())
as u128);
.push(last_entry.next_block_base_fee(self.provider().chain_spec()) as u128);
base_fee_per_blob_gas.push(last_entry.next_block_blob_fee().unwrap_or_default());
} else {
// read the requested header range
let headers = LoadFee::provider(self)
let headers = self.provider()
.sealed_headers_range(start_block..=end_block)
.map_err(Self::Error::from_eth_err)?;
if headers.len() != block_count as usize {
@ -197,7 +197,7 @@ pub trait EthFees: LoadFee {
// The unwrap is safe since we checked earlier that we got at least 1 header.
let last_header = headers.last().expect("is present");
base_fee_per_gas.push(
LoadFee::provider(self)
self.provider()
.chain_spec()
.base_fee_params_at_timestamp(last_header.timestamp)
.next_block_base_fee(
@ -242,13 +242,6 @@ pub trait EthFees: LoadFee {
///
/// Behaviour shared by several `eth_` RPC methods, not exclusive to `eth_` fees RPC methods.
pub trait LoadFee: LoadBlock {
// Returns a handle for reading data from disk.
///
/// Data access in default (L1) trait method implementations.
fn provider(
&self,
) -> impl BlockIdReader + HeaderProvider + ChainSpecProvider<ChainSpec: EthereumHardforks>;
/// Returns a handle for reading data from memory.
///
/// Data access in default (L1) trait method implementations.
@ -257,7 +250,7 @@ pub trait LoadFee: LoadBlock {
/// Returns a handle for reading gas price.
///
/// Data access in default (L1) trait method implementations.
fn gas_oracle(&self) -> &GasPriceOracle<impl BlockReaderIdExt>;
fn gas_oracle(&self) -> &GasPriceOracle<Self::Provider>;
/// Returns a handle for reading fee history data from memory.
///

View File

@ -1,8 +1,7 @@
//! Contains RPC handler implementations for fee history.
use reth_chainspec::EthereumHardforks;
use reth_provider::{BlockIdReader, BlockReaderIdExt, ChainSpecProvider, HeaderProvider};
use reth_chainspec::{EthChainSpec, EthereumHardforks};
use reth_provider::{BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, StateProviderFactory};
use reth_rpc_eth_api::helpers::{EthFees, LoadBlock, LoadFee};
use reth_rpc_eth_types::{EthStateCache, FeeHistoryCache, GasPriceOracle};
@ -15,23 +14,19 @@ impl<Provider, Pool, Network, EvmConfig> EthFees for EthApi<Provider, Pool, Netw
impl<Provider, Pool, Network, EvmConfig> LoadFee for EthApi<Provider, Pool, Network, EvmConfig>
where
Self: LoadBlock,
Provider: BlockReaderIdExt + HeaderProvider + ChainSpecProvider<ChainSpec: EthereumHardforks>,
Self: LoadBlock<Provider = Provider>,
Provider: BlockReaderIdExt
+ EvmEnvProvider
+ ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
+ StateProviderFactory,
{
#[inline]
fn provider(
&self,
) -> impl BlockIdReader + HeaderProvider + ChainSpecProvider<ChainSpec: EthereumHardforks> {
self.inner.provider()
}
#[inline]
fn cache(&self) -> &EthStateCache {
self.inner.cache()
}
#[inline]
fn gas_oracle(&self) -> &GasPriceOracle<impl BlockReaderIdExt> {
fn gas_oracle(&self) -> &GasPriceOracle<Self::Provider> {
self.inner.gas_oracle()
}