mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-26 15:48:13 -05:00
chore(rpc): set RpcNodeCore as supertrait for LoadState (#12094)
This commit is contained in:
@@ -143,7 +143,6 @@ where
|
||||
|
||||
impl<N> EthApiSpec for OpEthApi<N>
|
||||
where
|
||||
Self: Send + Sync,
|
||||
N: RpcNodeCore<
|
||||
Provider: ChainSpecProvider<ChainSpec: EthereumHardforks>
|
||||
+ BlockNumReader
|
||||
@@ -213,25 +212,15 @@ where
|
||||
|
||||
impl<N> LoadState for OpEthApi<N>
|
||||
where
|
||||
Self: Send + Sync + Clone,
|
||||
N: FullNodeComponents<Types: NodeTypes<ChainSpec: EthereumHardforks>>,
|
||||
N: RpcNodeCore<
|
||||
Provider: StateProviderFactory + ChainSpecProvider<ChainSpec: EthereumHardforks>,
|
||||
Pool: TransactionPool,
|
||||
>,
|
||||
{
|
||||
#[inline]
|
||||
fn provider(
|
||||
&self,
|
||||
) -> impl StateProviderFactory + ChainSpecProvider<ChainSpec: EthereumHardforks> {
|
||||
self.inner.provider()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn cache(&self) -> &EthStateCache {
|
||||
self.inner.cache()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn pool(&self) -> impl TransactionPool {
|
||||
self.inner.pool()
|
||||
}
|
||||
}
|
||||
|
||||
impl<N> EthState for OpEthApi<N>
|
||||
|
||||
@@ -486,7 +486,7 @@ pub trait Call: LoadState + SpawnBlocking {
|
||||
DB: Database,
|
||||
EthApiError: From<DB::Error>,
|
||||
{
|
||||
let mut evm = self.evm_config().evm_with_env(db, env);
|
||||
let mut evm = Call::evm_config(self).evm_with_env(db, env);
|
||||
let res = evm.transact().map_err(Self::Error::from_evm_err)?;
|
||||
let (_, env) = evm.into_db_and_env_with_handler_cfg();
|
||||
Ok((res, env))
|
||||
@@ -504,7 +504,7 @@ pub trait Call: LoadState + SpawnBlocking {
|
||||
DB: Database,
|
||||
EthApiError: From<DB::Error>,
|
||||
{
|
||||
let mut evm = self.evm_config().evm_with_env_and_inspector(db, env, inspector);
|
||||
let mut evm = Call::evm_config(self).evm_with_env_and_inspector(db, env, inspector);
|
||||
let res = evm.transact().map_err(Self::Error::from_evm_err)?;
|
||||
let (_, env) = evm.into_db_and_env_with_handler_cfg();
|
||||
Ok((res, env))
|
||||
@@ -669,7 +669,7 @@ pub trait Call: LoadState + SpawnBlocking {
|
||||
{
|
||||
let env = EnvWithHandlerCfg::new_with_cfg_env(cfg, block_env, Default::default());
|
||||
|
||||
let mut evm = self.evm_config().evm_with_env(db, env);
|
||||
let mut evm = Call::evm_config(self).evm_with_env(db, env);
|
||||
let mut index = 0;
|
||||
for (sender, tx) in transactions {
|
||||
if tx.hash() == target_tx_hash {
|
||||
@@ -677,7 +677,7 @@ pub trait Call: LoadState + SpawnBlocking {
|
||||
break
|
||||
}
|
||||
|
||||
self.evm_config().fill_tx_env(evm.tx_mut(), tx, *sender);
|
||||
Call::evm_config(self).fill_tx_env(evm.tx_mut(), tx, *sender);
|
||||
evm.transact_commit().map_err(Self::Error::from_evm_err)?;
|
||||
index += 1;
|
||||
}
|
||||
|
||||
@@ -16,12 +16,11 @@ use crate::{helpers::EthSigner, RpcNodeCore};
|
||||
#[auto_impl::auto_impl(&, Arc)]
|
||||
pub trait EthApiSpec:
|
||||
RpcNodeCore<
|
||||
Provider: ChainSpecProvider<ChainSpec: EthereumHardforks>
|
||||
+ BlockNumReader
|
||||
+ StageCheckpointReader,
|
||||
Network: NetworkInfo,
|
||||
> + Send
|
||||
+ Sync
|
||||
Provider: ChainSpecProvider<ChainSpec: EthereumHardforks>
|
||||
+ BlockNumReader
|
||||
+ StageCheckpointReader,
|
||||
Network: NetworkInfo,
|
||||
>
|
||||
{
|
||||
/// Returns the block node is started on.
|
||||
fn starting_block(&self) -> U256;
|
||||
|
||||
@@ -18,7 +18,7 @@ use reth_rpc_types_compat::proof::from_primitive_account_proof;
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
use revm_primitives::{BlockEnv, CfgEnvWithHandlerCfg, SpecId};
|
||||
|
||||
use crate::{EthApiTypes, FromEthApiError};
|
||||
use crate::{EthApiTypes, FromEthApiError, RpcNodeCore};
|
||||
|
||||
use super::{EthApiSpec, LoadPendingBlock, SpawnBlocking};
|
||||
|
||||
@@ -105,7 +105,8 @@ pub trait EthState: LoadState + SpawnBlocking {
|
||||
let block_id = block_id.unwrap_or_default();
|
||||
|
||||
// Check whether the distance to the block exceeds the maximum configured window.
|
||||
let block_number = LoadState::provider(self)
|
||||
let block_number = self
|
||||
.provider()
|
||||
.block_number_for_id(block_id)
|
||||
.map_err(Self::Error::from_eth_err)?
|
||||
.ok_or(EthApiError::HeaderNotFound(block_id))?;
|
||||
@@ -138,9 +139,9 @@ pub trait EthState: LoadState + SpawnBlocking {
|
||||
let Some(account) = account else { return Ok(None) };
|
||||
|
||||
// Check whether the distance to the block exceeds the maximum configured proof window.
|
||||
let chain_info =
|
||||
LoadState::provider(&this).chain_info().map_err(Self::Error::from_eth_err)?;
|
||||
let block_number = LoadState::provider(&this)
|
||||
let chain_info = this.provider().chain_info().map_err(Self::Error::from_eth_err)?;
|
||||
let block_number = this
|
||||
.provider()
|
||||
.block_number_for_id(block_id)
|
||||
.map_err(Self::Error::from_eth_err)?
|
||||
.ok_or(EthApiError::HeaderNotFound(block_id))?;
|
||||
@@ -167,24 +168,19 @@ pub trait EthState: LoadState + SpawnBlocking {
|
||||
/// Loads state from database.
|
||||
///
|
||||
/// Behaviour shared by several `eth_` RPC methods, not exclusive to `eth_` state RPC methods.
|
||||
pub trait LoadState: EthApiTypes {
|
||||
/// Returns a handle for reading state from database.
|
||||
///
|
||||
/// Data access in default trait method implementations.
|
||||
fn provider(
|
||||
&self,
|
||||
) -> impl StateProviderFactory + ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>;
|
||||
|
||||
pub trait LoadState:
|
||||
EthApiTypes
|
||||
+ RpcNodeCore<
|
||||
Provider: StateProviderFactory
|
||||
+ ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>,
|
||||
Pool: TransactionPool,
|
||||
>
|
||||
{
|
||||
/// Returns a handle for reading data from memory.
|
||||
///
|
||||
/// Data access in default (L1) trait method implementations.
|
||||
fn cache(&self) -> &EthStateCache;
|
||||
|
||||
/// Returns a handle for reading data from transaction pool.
|
||||
///
|
||||
/// Data access in default trait method implementations.
|
||||
fn pool(&self) -> impl TransactionPool;
|
||||
|
||||
/// Returns the state at the given block number
|
||||
fn state_at_hash(&self, block_hash: B256) -> Result<StateProviderBox, Self::Error> {
|
||||
self.provider().history_by_block_hash(block_hash).map_err(Self::Error::from_eth_err)
|
||||
@@ -266,7 +262,7 @@ pub trait LoadState: EthApiTypes {
|
||||
let (cfg, mut block_env, _) = self.evm_env_at(header.parent_hash.into()).await?;
|
||||
|
||||
let after_merge = cfg.handler_cfg.spec_id >= SpecId::MERGE;
|
||||
self.evm_config().fill_block_env(&mut block_env, header, after_merge);
|
||||
LoadPendingBlock::evm_config(self).fill_block_env(&mut block_env, header, after_merge);
|
||||
|
||||
Ok((cfg, block_env))
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::FromEvmError;
|
||||
use crate::{FromEvmError, RpcNodeCore};
|
||||
use alloy_primitives::B256;
|
||||
use alloy_rpc_types::{BlockId, TransactionInfo};
|
||||
use futures::Future;
|
||||
@@ -60,7 +60,7 @@ pub trait Trace: LoadState {
|
||||
|
||||
I: GetInspector<DB>,
|
||||
{
|
||||
let mut evm = self.evm_config().evm_with_env_and_inspector(db, env, inspector);
|
||||
let mut evm = Trace::evm_config(self).evm_with_env_and_inspector(db, env, inspector);
|
||||
let res = evm.transact().map_err(Self::Error::from_evm_err)?;
|
||||
let (db, env) = evm.into_db_and_env_with_handler_cfg();
|
||||
Ok((res, env, db))
|
||||
@@ -202,7 +202,7 @@ pub trait Trace: LoadState {
|
||||
// apply relevant system calls
|
||||
let mut system_caller = SystemCaller::new(
|
||||
Trace::evm_config(&this).clone(),
|
||||
LoadState::provider(&this).chain_spec(),
|
||||
RpcNodeCore::provider(&this).chain_spec(),
|
||||
);
|
||||
system_caller
|
||||
.pre_block_beacon_root_contract_call(
|
||||
@@ -345,7 +345,7 @@ pub trait Trace: LoadState {
|
||||
// apply relevant system calls
|
||||
let mut system_caller = SystemCaller::new(
|
||||
Trace::evm_config(&this).clone(),
|
||||
LoadState::provider(&this).chain_spec(),
|
||||
RpcNodeCore::provider(&this).chain_spec(),
|
||||
);
|
||||
system_caller
|
||||
.pre_block_beacon_root_contract_call(
|
||||
|
||||
@@ -21,7 +21,9 @@ use reth_rpc_types_compat::transaction::{from_recovered, from_recovered_with_blo
|
||||
use reth_transaction_pool::{PoolTransaction, TransactionOrigin, TransactionPool};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::{FromEthApiError, FullEthApiTypes, IntoEthApiError, RpcReceipt, RpcTransaction};
|
||||
use crate::{
|
||||
FromEthApiError, FullEthApiTypes, IntoEthApiError, RpcNodeCore, RpcReceipt, RpcTransaction,
|
||||
};
|
||||
|
||||
use super::{
|
||||
Call, EthApiSpec, EthSigner, LoadBlock, LoadPendingBlock, LoadReceipt, LoadState, SpawnBlocking,
|
||||
@@ -235,7 +237,7 @@ pub trait EthTransactions: LoadTransaction {
|
||||
// Check the pool first
|
||||
if include_pending {
|
||||
if let Some(tx) =
|
||||
LoadState::pool(self).get_transaction_by_sender_and_nonce(sender, nonce)
|
||||
RpcNodeCore::pool(self).get_transaction_by_sender_and_nonce(sender, nonce)
|
||||
{
|
||||
let transaction = tx.transaction.clone().into_consensus();
|
||||
return Ok(Some(from_recovered(transaction.into(), self.tx_resp_builder())));
|
||||
|
||||
@@ -8,7 +8,7 @@ use reth_node_api::FullNodeComponents;
|
||||
/// `N: RpcNodeCore` instead, allows access to all the associated types on [`FullNodeComponents`]
|
||||
/// that are used in RPC, but with more flexibility since they have no trait bounds (asides auto
|
||||
/// traits).
|
||||
pub trait RpcNodeCore: Clone {
|
||||
pub trait RpcNodeCore: Clone + Send + Sync {
|
||||
/// The provider type used to interact with the node.
|
||||
type Provider: Send + Sync + Clone + Unpin;
|
||||
/// The transaction pool of the node.
|
||||
|
||||
@@ -27,8 +27,8 @@ use reth_provider::{
|
||||
use reth_revm::database::StateProviderDatabase;
|
||||
use reth_rpc_api::DebugApiServer;
|
||||
use reth_rpc_eth_api::{
|
||||
helpers::{Call, EthApiSpec, EthTransactions, LoadState, TraceExt},
|
||||
EthApiTypes, FromEthApiError,
|
||||
helpers::{Call, EthApiSpec, EthTransactions, TraceExt},
|
||||
EthApiTypes, FromEthApiError, RpcNodeCore,
|
||||
};
|
||||
use reth_rpc_eth_types::{EthApiError, StateCacheDb};
|
||||
use reth_rpc_server_types::{result::internal_rpc_err, ToRpcResult};
|
||||
@@ -264,7 +264,7 @@ where
|
||||
// apply relevant system calls
|
||||
let mut system_caller = SystemCaller::new(
|
||||
Call::evm_config(this.eth_api()).clone(),
|
||||
LoadState::provider(this.eth_api()).chain_spec(),
|
||||
RpcNodeCore::provider(this.eth_api()).chain_spec(),
|
||||
);
|
||||
|
||||
system_caller
|
||||
|
||||
@@ -4,7 +4,10 @@ use reth_chainspec::EthereumHardforks;
|
||||
use reth_provider::{ChainSpecProvider, StateProviderFactory};
|
||||
use reth_transaction_pool::TransactionPool;
|
||||
|
||||
use reth_rpc_eth_api::helpers::{EthState, LoadState, SpawnBlocking};
|
||||
use reth_rpc_eth_api::{
|
||||
helpers::{EthState, LoadState, SpawnBlocking},
|
||||
RpcNodeCore,
|
||||
};
|
||||
use reth_rpc_eth_types::EthStateCache;
|
||||
|
||||
use crate::EthApi;
|
||||
@@ -20,26 +23,15 @@ where
|
||||
|
||||
impl<Provider, Pool, Network, EvmConfig> LoadState for EthApi<Provider, Pool, Network, EvmConfig>
|
||||
where
|
||||
Self: Send + Sync,
|
||||
Provider: StateProviderFactory + ChainSpecProvider<ChainSpec: EthereumHardforks>,
|
||||
Pool: TransactionPool,
|
||||
Self: RpcNodeCore<
|
||||
Provider: StateProviderFactory + ChainSpecProvider<ChainSpec: EthereumHardforks>,
|
||||
Pool: TransactionPool,
|
||||
>,
|
||||
{
|
||||
#[inline]
|
||||
fn provider(
|
||||
&self,
|
||||
) -> impl StateProviderFactory + ChainSpecProvider<ChainSpec: EthereumHardforks> {
|
||||
self.inner.provider()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn cache(&self) -> &EthStateCache {
|
||||
self.inner.cache()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn pool(&self) -> impl TransactionPool {
|
||||
self.inner.pool()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user