Skip to content

Commit

Permalink
chore: rm evmenvprovider trait (#13503)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Dec 23, 2024
1 parent a0dcb0c commit ec21e89
Show file tree
Hide file tree
Showing 25 changed files with 53 additions and 215 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions crates/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ reth-prune-types.workspace = true
reth-revm.workspace = true
reth-storage-errors.workspace = true

reth-storage-api = { workspace = true, optional = true }

revm.workspace = true
revm-primitives.workspace = true

Expand Down Expand Up @@ -68,7 +66,6 @@ test-utils = [
"reth-primitives/test-utils",
"reth-primitives-traits/test-utils",
"reth-revm/test-utils",
"dep:reth-storage-api",
"revm/test-utils",
"reth-prune-types/test-utils"
]
1 change: 0 additions & 1 deletion crates/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use env::EvmEnv;
#[cfg(feature = "std")]
pub mod metrics;
pub mod noop;
pub mod provider;
pub mod state_change;
pub mod system_calls;
#[cfg(any(test, feature = "test-utils"))]
Expand Down
23 changes: 0 additions & 23 deletions crates/evm/src/provider.rs

This file was deleted.

20 changes: 1 addition & 19 deletions crates/evm/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
//! Helpers for testing.
use crate::{
env::EvmEnv,
execute::{
BasicBatchExecutor, BasicBlockExecutor, BatchExecutor, BlockExecutionOutput,
BlockExecutionStrategy, BlockExecutorProvider, Executor,
},
provider::EvmEnvProvider,
system_calls::OnStateHook,
ConfigureEvmEnv,
};
use alloy_eips::eip7685::Requests;
use alloy_primitives::BlockNumber;
Expand All @@ -17,26 +14,11 @@ use reth_execution_errors::BlockExecutionError;
use reth_execution_types::ExecutionOutcome;
use reth_primitives::{BlockWithSenders, EthPrimitives, NodePrimitives, Receipt, Receipts};
use reth_prune_types::PruneModes;
use reth_storage_errors::provider::{ProviderError, ProviderResult};
use reth_storage_errors::provider::ProviderError;
use revm::State;
use revm_primitives::db::Database;
use std::{fmt::Display, sync::Arc};

impl<C: Send + Sync, N: NodePrimitives> EvmEnvProvider<N::BlockHeader>
for reth_storage_api::noop::NoopProvider<C, N>
{
fn env_with_header<EvmConfig>(
&self,
header: &N::BlockHeader,
evm_config: EvmConfig,
) -> ProviderResult<EvmEnv>
where
EvmConfig: ConfigureEvmEnv<Header = N::BlockHeader>,
{
Ok(evm_config.cfg_and_block_env(header))
}
}

/// A [`BlockExecutorProvider`] that returns mocked execution results.
#[derive(Clone, Debug, Default)]
pub struct MockExecutorProvider {
Expand Down
5 changes: 2 additions & 3 deletions crates/optimism/rpc/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use reth_network_api::NetworkInfo;
use reth_node_builder::EthApiBuilderCtx;
use reth_provider::{
BlockNumReader, BlockReader, BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider,
EvmEnvProvider, NodePrimitivesProvider, ProviderBlock, ProviderHeader, ProviderReceipt,
ProviderTx, StageCheckpointReader, StateProviderFactory,
NodePrimitivesProvider, ProviderBlock, ProviderHeader, ProviderReceipt, ProviderTx,
StageCheckpointReader, StateProviderFactory,
};
use reth_rpc::eth::{core::EthApiInner, DevSigner};
use reth_rpc_eth_api::{
Expand Down Expand Up @@ -203,7 +203,6 @@ where
Self: LoadBlock<Provider = N::Provider>,
N: OpNodeCore<
Provider: BlockReaderIdExt
+ EvmEnvProvider
+ ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
+ StateProviderFactory,
>,
Expand Down
7 changes: 3 additions & 4 deletions crates/optimism/rpc/src/eth/pending_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use reth_evm::ConfigureEvm;
use reth_optimism_consensus::calculate_receipt_root_no_memo_optimism;
use reth_primitives::{logs_bloom, BlockBody, Receipt, SealedBlockWithSenders, TransactionSigned};
use reth_provider::{
BlockReader, BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, ProviderBlock,
ProviderHeader, ProviderReceipt, ProviderTx, ReceiptProvider, StateProviderFactory,
BlockReader, BlockReaderIdExt, ChainSpecProvider, ProviderBlock, ProviderHeader,
ProviderReceipt, ProviderTx, ReceiptProvider, StateProviderFactory,
};
use reth_rpc_eth_api::{
helpers::{LoadPendingBlock, SpawnBlocking},
Expand All @@ -37,8 +37,7 @@ where
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
Header = reth_primitives::Header,
> + EvmEnvProvider
+ ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
> + ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
+ StateProviderFactory,
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = ProviderTx<N::Provider>>>,
Evm: ConfigureEvm<Header = Header, Transaction = TransactionSigned>,
Expand Down
5 changes: 2 additions & 3 deletions crates/rpc/rpc-builder/src/eth.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use reth_evm::ConfigureEvm;
use reth_primitives::NodePrimitives;
use reth_provider::{BlockReader, CanonStateSubscriptions, EvmEnvProvider, StateProviderFactory};
use reth_provider::{BlockReader, CanonStateSubscriptions, StateProviderFactory};
use reth_rpc::{EthFilter, EthPubSub};
use reth_rpc_eth_api::EthApiTypes;
use reth_rpc_eth_types::{
Expand Down Expand Up @@ -31,8 +31,7 @@ where
+ BlockReader<
Block = <Events::Primitives as NodePrimitives>::Block,
Receipt = <Events::Primitives as NodePrimitives>::Receipt,
> + EvmEnvProvider
+ Clone
> + Clone
+ Unpin
+ 'static,
Events: CanonStateSubscriptions + Clone + 'static,
Expand Down
8 changes: 3 additions & 5 deletions crates/rpc/rpc-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ use reth_network_api::{noop::NoopNetwork, NetworkInfo, Peers};
use reth_primitives::NodePrimitives;
use reth_provider::{
AccountReader, BlockReader, CanonStateSubscriptions, ChainSpecProvider, ChangeSetReader,
EvmEnvProvider, FullRpcProvider, ProviderBlock, ProviderHeader, ProviderReceipt,
StateProviderFactory,
FullRpcProvider, ProviderBlock, ProviderHeader, ProviderReceipt, StateProviderFactory,
};
use reth_rpc::{
AdminApi, DebugApi, EngineEthApi, EthBundle, MinerApi, NetApi, OtterscanApi, RPCApi, RethApi,
Expand Down Expand Up @@ -403,7 +402,7 @@ impl<Provider, Pool, Network, Tasks, Events, EvmConfig, BlockExecutor, Consensus
provider: P,
) -> RpcModuleBuilder<P, Pool, Network, Tasks, Events, EvmConfig, BlockExecutor, Consensus>
where
P: BlockReader + StateProviderFactory + EvmEnvProvider + 'static,
P: BlockReader + StateProviderFactory + 'static,
{
let Self { pool, network, executor, events, evm_config, block_executor, consensus, .. } =
self;
Expand Down Expand Up @@ -1004,8 +1003,7 @@ where
+ BlockReader<
Block = <Events::Primitives as NodePrimitives>::Block,
Receipt = <Events::Primitives as NodePrimitives>::Receipt,
> + EvmEnvProvider
+ Clone
> + Clone
+ Unpin
+ 'static,
Pool: Send + Sync + Clone + 'static,
Expand Down
1 change: 0 additions & 1 deletion crates/rpc/rpc-engine-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ reth-payload-primitives.workspace = true
reth-tasks.workspace = true
reth-rpc-types-compat.workspace = true
reth-engine-primitives.workspace = true
reth-evm.workspace = true
reth-transaction-pool.workspace = true

# ethereum
Expand Down
5 changes: 2 additions & 3 deletions crates/rpc/rpc-engine-api/src/engine_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use parking_lot::Mutex;
use reth_beacon_consensus::BeaconConsensusEngineHandle;
use reth_chainspec::{EthereumHardforks, Hardforks};
use reth_engine_primitives::{EngineTypes, EngineValidator};
use reth_evm::provider::EvmEnvProvider;
use reth_payload_builder::PayloadStore;
use reth_payload_primitives::{
validate_payload_timestamp, EngineApiMessageVersion, PayloadBuilderAttributes,
Expand Down Expand Up @@ -80,7 +79,7 @@ struct EngineApiInner<Provider, EngineT: EngineTypes, Pool, Validator, ChainSpec
impl<Provider, EngineT, Pool, Validator, ChainSpec>
EngineApi<Provider, EngineT, Pool, Validator, ChainSpec>
where
Provider: HeaderProvider + BlockReader + StateProviderFactory + EvmEnvProvider + 'static,
Provider: HeaderProvider + BlockReader + StateProviderFactory + 'static,
EngineT: EngineTypes,
Pool: TransactionPool + 'static,
Validator: EngineValidator<EngineT>,
Expand Down Expand Up @@ -744,7 +743,7 @@ where
impl<Provider, EngineT, Pool, Validator, ChainSpec> EngineApiServer<EngineT>
for EngineApi<Provider, EngineT, Pool, Validator, ChainSpec>
where
Provider: HeaderProvider + BlockReader + StateProviderFactory + EvmEnvProvider + 'static,
Provider: HeaderProvider + BlockReader + StateProviderFactory + 'static,
EngineT: EngineTypes,
Pool: TransactionPool + 'static,
Validator: EngineValidator<EngineT>,
Expand Down
13 changes: 4 additions & 9 deletions crates/rpc/rpc-eth-api/src/helpers/pending_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use reth_evm::{
use reth_primitives::{BlockExt, InvalidTransactionError, SealedBlockWithSenders};
use reth_primitives_traits::Receipt;
use reth_provider::{
BlockReader, BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, ProviderBlock, ProviderError,
ProviderHeader, ProviderReceipt, ProviderTx, ReceiptProvider, StateProviderFactory,
BlockReader, BlockReaderIdExt, ChainSpecProvider, ProviderBlock, ProviderError, ProviderHeader,
ProviderReceipt, ProviderTx, ReceiptProvider, StateProviderFactory,
};
use reth_revm::{
database::StateProviderDatabase,
Expand Down Expand Up @@ -48,7 +48,6 @@ pub trait LoadPendingBlock:
>,
> + RpcNodeCore<
Provider: BlockReaderIdExt<Receipt: Receipt>
+ EvmEnvProvider<ProviderHeader<Self::Provider>>
+ ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
+ StateProviderFactory,
Pool: TransactionPool<Transaction: PoolTransaction<Consensus = ProviderTx<Self::Provider>>>,
Expand Down Expand Up @@ -87,12 +86,8 @@ pub trait LoadPendingBlock:
// Note: for the PENDING block we assume it is past the known merge block and
// thus this will not fail when looking up the total
// difficulty value for the blockenv.
let evm_env = self
.provider()
.env_with_header(block.header(), self.evm_config().clone())
.map_err(Self::Error::from_eth_err)?;

let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env;
let EvmEnv { cfg_env_with_handler_cfg, block_env } =
self.evm_config().cfg_and_block_env(block.header());

return Ok(PendingBlockEnv::new(
cfg_env_with_handler_cfg,
Expand Down
12 changes: 5 additions & 7 deletions crates/rpc/rpc-eth-api/src/helpers/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use alloy_serde::JsonStorageKey;
use futures::Future;
use reth_chainspec::{EthChainSpec, EthereumHardforks};
use reth_errors::RethError;
use reth_evm::env::EvmEnv;
use reth_evm::{env::EvmEnv, ConfigureEvmEnv};
use reth_provider::{
BlockIdReader, BlockNumReader, ChainSpecProvider, EvmEnvProvider as _, StateProvider,
StateProviderBox, StateProviderFactory,
BlockIdReader, BlockNumReader, ChainSpecProvider, StateProvider, StateProviderBox,
StateProviderFactory,
};
use reth_rpc_eth_types::{EthApiError, PendingBlockEnv, RpcInvalidTransactionError};
use reth_transaction_pool::TransactionPool;
Expand Down Expand Up @@ -231,10 +231,8 @@ pub trait LoadState:

let header =
self.cache().get_header(block_hash).await.map_err(Self::Error::from_eth_err)?;
let evm_env = self
.provider()
.env_with_header(&header, self.evm_config().clone())
.map_err(Self::Error::from_eth_err)?;
let evm_env = self.evm_config().cfg_and_block_env(&header);

Ok((evm_env, block_hash.into()))
}
}
Expand Down
11 changes: 4 additions & 7 deletions crates/rpc/rpc/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use reth_evm::{
use reth_primitives::{BlockExt, NodePrimitives, ReceiptWithBloom, SealedBlockWithSenders};
use reth_primitives_traits::{Block as _, BlockBody, SignedTransaction};
use reth_provider::{
BlockIdReader, BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, HeaderProvider,
ProviderBlock, ReceiptProviderIdExt, StateProofProvider, TransactionVariant,
BlockIdReader, BlockReaderIdExt, ChainSpecProvider, HeaderProvider, ProviderBlock,
ReceiptProviderIdExt, StateProofProvider, TransactionVariant,
};
use reth_revm::{database::StateProviderDatabase, witness::ExecutionWitnessRecord};
use reth_rpc_api::DebugApiServer;
Expand Down Expand Up @@ -162,11 +162,8 @@ where
.map_err(BlockError::RlpDecodeRawBlock)
.map_err(Eth::Error::from_eth_err)?;

// Note: we assume the block has a valid height
let EvmEnv { cfg_env_with_handler_cfg, block_env } = self
.provider()
.env_with_header(block.header(), self.eth_api().evm_config().clone())
.map_err(Eth::Error::from_eth_err)?;
let EvmEnv { cfg_env_with_handler_cfg, block_env } =
self.eth_api().evm_config().cfg_and_block_env(block.header());

// Depending on EIP-2 we need to recover the transactions differently
let senders =
Expand Down
3 changes: 1 addition & 2 deletions crates/rpc/rpc/src/eth/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ mod tests {
use reth_primitives::{Block, BlockBody, TransactionSigned};
use reth_provider::{
test_utils::{MockEthProvider, NoopProvider},
BlockReader, BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, StateProviderFactory,
BlockReader, BlockReaderIdExt, ChainSpecProvider, StateProviderFactory,
};
use reth_rpc_eth_api::EthApiServer;
use reth_rpc_eth_types::{
Expand All @@ -484,7 +484,6 @@ mod tests {
Header = reth_primitives::Header,
> + BlockReader
+ ChainSpecProvider<ChainSpec = ChainSpec>
+ EvmEnvProvider
+ StateProviderFactory
+ Unpin
+ Clone
Expand Down
5 changes: 1 addition & 4 deletions crates/rpc/rpc/src/eth/helpers/fees.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! Contains RPC handler implementations for fee history.
use reth_chainspec::{EthChainSpec, EthereumHardforks};
use reth_provider::{
BlockReader, BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, StateProviderFactory,
};
use reth_provider::{BlockReader, BlockReaderIdExt, ChainSpecProvider, StateProviderFactory};
use reth_rpc_eth_api::helpers::{EthFees, LoadBlock, LoadFee};
use reth_rpc_eth_types::{FeeHistoryCache, GasPriceOracle};

Expand All @@ -20,7 +18,6 @@ impl<Provider, Pool, Network, EvmConfig> LoadFee for EthApi<Provider, Pool, Netw
where
Self: LoadBlock<Provider = Provider>,
Provider: BlockReaderIdExt
+ EvmEnvProvider
+ ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
+ StateProviderFactory,
{
Expand Down
7 changes: 3 additions & 4 deletions crates/rpc/rpc/src/eth/helpers/pending_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use reth_primitives::{
BlockBody, Receipt,
};
use reth_provider::{
BlockReader, BlockReaderIdExt, ChainSpecProvider, EvmEnvProvider, ProviderBlock,
ProviderReceipt, ProviderTx, StateProviderFactory,
BlockReader, BlockReaderIdExt, ChainSpecProvider, ProviderBlock, ProviderReceipt, ProviderTx,
StateProviderFactory,
};
use reth_rpc_eth_api::{
helpers::{LoadPendingBlock, SpawnBlocking},
Expand All @@ -35,8 +35,7 @@ where
Block = reth_primitives::Block,
Receipt = reth_primitives::Receipt,
Header = reth_primitives::Header,
> + EvmEnvProvider
+ ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
> + ChainSpecProvider<ChainSpec: EthChainSpec + EthereumHardforks>
+ StateProviderFactory,
Pool: TransactionPool<
Transaction: PoolTransaction<Consensus = ProviderTx<Self::Provider>>,
Expand Down
Loading

0 comments on commit ec21e89

Please sign in to comment.