diff --git a/README.md b/README.md index 8a6b8ddb42fb..54d9f98e7a35 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ | [Crate Docs](https://reth.rs/docs) [gh-ci]: https://github.com/paradigmxyz/reth/actions/workflows/unit.yml -[gh-deny]: https://github.com/paradigmxyz/reth/actions/workflows/deny.yml +[gh-deny]: https://github.com/paradigmxyz/reth/actions/workflows/lint.yml [tg-badge]: https://img.shields.io/endpoint?color=neon&logo=telegram&label=chat&url=https%3A%2F%2Ftg.sumanjay.workers.dev%2Fparadigm%5Freth ## What is Reth? diff --git a/crates/cli/commands/src/stage/unwind.rs b/crates/cli/commands/src/stage/unwind.rs index e5ff56055977..7171a45bb23c 100644 --- a/crates/cli/commands/src/stage/unwind.rs +++ b/crates/cli/commands/src/stage/unwind.rs @@ -17,7 +17,6 @@ use reth_provider::{ providers::ProviderNodeTypes, BlockExecutionWriter, BlockNumReader, ChainStateBlockReader, ChainStateBlockWriter, ProviderFactory, StaticFileProviderFactory, StorageLocation, }; -use reth_prune::PruneModes; use reth_stages::{ sets::{DefaultStages, OfflineStages}, stages::ExecutionStage, @@ -120,7 +119,7 @@ impl> Command let builder = if self.offline { Pipeline::::builder().add_stages( - OfflineStages::new(executor, config.stages, PruneModes::default()) + OfflineStages::new(executor, config.stages, prune_modes.clone()) .builder() .disable(reth_stages::StageId::SenderRecovery), ) @@ -145,7 +144,7 @@ impl> Command max_duration: None, }, stage_conf.execution_external_clean_threshold(), - prune_modes, + prune_modes.clone(), ExExManagerHandle::empty(), )), ) @@ -153,7 +152,7 @@ impl> Command let pipeline = builder.build( provider_factory.clone(), - StaticFileProducer::new(provider_factory, PruneModes::default()), + StaticFileProducer::new(provider_factory, prune_modes), ); Ok(pipeline) } diff --git a/crates/engine/invalid-block-hooks/src/witness.rs b/crates/engine/invalid-block-hooks/src/witness.rs index 9614e64c2076..b7e3b4f19126 100644 --- a/crates/engine/invalid-block-hooks/src/witness.rs +++ b/crates/engine/invalid-block-hooks/src/witness.rs @@ -6,15 +6,14 @@ use pretty_assertions::Comparison; use reth_chainspec::{EthChainSpec, EthereumHardforks}; use reth_engine_primitives::InvalidBlockHook; use reth_evm::{ - env::EvmEnv, state_change::post_block_balance_increments, system_calls::SystemCaller, - ConfigureEvm, + state_change::post_block_balance_increments, system_calls::SystemCaller, ConfigureEvm, }; use reth_primitives::{NodePrimitives, RecoveredBlock, SealedHeader}; use reth_primitives_traits::{BlockBody, SignedTransaction}; use reth_provider::{BlockExecutionOutput, ChainSpecProvider, StateProviderFactory}; use reth_revm::{ - database::StateProviderDatabase, db::states::bundle_state::BundleRetention, - primitives::EnvWithHandlerCfg, DatabaseCommit, StateBuilder, + database::StateProviderDatabase, db::states::bundle_state::BundleRetention, DatabaseCommit, + StateBuilder, }; use reth_rpc_api::DebugApiClient; use reth_tracing::tracing::warn; @@ -77,19 +76,8 @@ where .with_bundle_update() .build(); - // Setup environment for the execution. - let EvmEnv { cfg_env_with_handler_cfg, block_env } = - self.evm_config.cfg_and_block_env(block.header()); - // Setup EVM - let mut evm = self.evm_config.evm_with_env( - &mut db, - EnvWithHandlerCfg::new_with_cfg_env( - cfg_env_with_handler_cfg, - block_env, - Default::default(), - ), - ); + let mut evm = self.evm_config.evm_for_block(&mut db, block.header()); let mut system_caller = SystemCaller::new(self.evm_config.clone(), self.provider.chain_spec()); diff --git a/crates/engine/util/src/reorg.rs b/crates/engine/util/src/reorg.rs index 69a6d98d2713..2136c92a014e 100644 --- a/crates/engine/util/src/reorg.rs +++ b/crates/engine/util/src/reorg.rs @@ -14,8 +14,8 @@ use reth_engine_primitives::{ use reth_errors::{BlockExecutionError, BlockValidationError, RethError, RethResult}; use reth_ethereum_forks::EthereumHardforks; use reth_evm::{ - env::EvmEnv, state_change::post_block_withdrawals_balance_increments, - system_calls::SystemCaller, ConfigureEvm, + state_change::post_block_withdrawals_balance_increments, system_calls::SystemCaller, + ConfigureEvm, }; use reth_payload_validator::ExecutionPayloadValidator; use reth_primitives::{ @@ -29,7 +29,7 @@ use reth_revm::{ DatabaseCommit, }; use reth_rpc_types_compat::engine::payload::block_to_payload; -use revm_primitives::{EVMError, EnvWithHandlerCfg}; +use revm_primitives::EVMError; use std::{ collections::VecDeque, future::Future, @@ -297,15 +297,8 @@ where .with_bundle_update() .build(); - // Configure environments - let EvmEnv { cfg_env_with_handler_cfg, block_env } = - evm_config.cfg_and_block_env(&reorg_target.header); - let env = EnvWithHandlerCfg::new_with_cfg_env( - cfg_env_with_handler_cfg, - block_env, - Default::default(), - ); - let mut evm = evm_config.evm_with_env(&mut state, env); + // Configure EVM + let mut evm = evm_config.evm_for_block(&mut state, &reorg_target.header); // apply eip-4788 pre block contract call let mut system_caller = SystemCaller::new(evm_config.clone(), chain_spec.clone()); diff --git a/crates/ethereum/evm/src/execute.rs b/crates/ethereum/evm/src/execute.rs index 986c13c7e18b..99975734ea0e 100644 --- a/crates/ethereum/evm/src/execute.rs +++ b/crates/ethereum/evm/src/execute.rs @@ -12,7 +12,6 @@ use reth_chainspec::{ChainSpec, EthereumHardfork, EthereumHardforks, MAINNET}; use reth_consensus::ConsensusError; use reth_ethereum_consensus::validate_block_post_execution; use reth_evm::{ - env::EvmEnv, execute::{ balance_increment_state, BasicBlockExecutorProvider, BlockExecutionError, BlockExecutionStrategy, BlockExecutionStrategyFactory, BlockValidationError, ExecuteOutput, @@ -27,7 +26,7 @@ use reth_primitives_traits::BlockBody; use reth_revm::db::State; use revm_primitives::{ db::{Database, DatabaseCommit}, - EnvWithHandlerCfg, ResultAndState, + ResultAndState, }; /// Factory for [`EthExecutionStrategy`]. @@ -114,23 +113,6 @@ where } } -impl EthExecutionStrategy -where - DB: Database + Display>, - EvmConfig: ConfigureEvm, -{ - /// Configures a new evm configuration and block environment for the given block. - /// - /// # Caution - /// - /// This does not initialize the tx environment. - fn evm_env_for_block(&self, header: &EvmConfig::Header) -> EnvWithHandlerCfg { - let EvmEnv { cfg_env_with_handler_cfg, block_env } = - self.evm_config.cfg_and_block_env(header); - EnvWithHandlerCfg::new_with_cfg_env(cfg_env_with_handler_cfg, block_env, Default::default()) - } -} - impl BlockExecutionStrategy for EthExecutionStrategy where DB: Database + Display>, @@ -157,8 +139,7 @@ where (*self.chain_spec).is_spurious_dragon_active_at_block(block.number()); self.state.set_state_clear_flag(state_clear_flag); - let env = self.evm_env_for_block(block.header()); - let mut evm = self.evm_config.evm_with_env(&mut self.state, env); + let mut evm = self.evm_config.evm_for_block(&mut self.state, block.header()); self.system_caller.apply_pre_execution_changes(block.header(), &mut evm)?; @@ -169,8 +150,7 @@ where &mut self, block: &RecoveredBlock, ) -> Result, Self::Error> { - let env = self.evm_env_for_block(block.header()); - let mut evm = self.evm_config.evm_with_env(&mut self.state, env); + let mut evm = self.evm_config.evm_for_block(&mut self.state, block.header()); let mut cumulative_gas_used = 0; let mut receipts = Vec::with_capacity(block.body().transaction_count()); @@ -231,8 +211,7 @@ where block: &RecoveredBlock, receipts: &[Receipt], ) -> Result { - let env = self.evm_env_for_block(block.header()); - let mut evm = self.evm_config.evm_with_env(&mut self.state, env); + let mut evm = self.evm_config.evm_for_block(&mut self.state, block.header()); let requests = if self.chain_spec.is_prague_active_at_timestamp(block.timestamp) { // Collect all EIP-6110 deposits diff --git a/crates/evm/src/lib.rs b/crates/evm/src/lib.rs index eff95cea696c..2eb5fc04c413 100644 --- a/crates/evm/src/lib.rs +++ b/crates/evm/src/lib.rs @@ -18,6 +18,7 @@ extern crate alloc; use crate::builder::RethEvmBuilder; +use alloc::boxed::Box; use alloy_consensus::BlockHeader as _; use alloy_primitives::{Address, Bytes, B256, U256}; use reth_primitives_traits::{BlockHeader, SignedTransaction}; @@ -41,7 +42,6 @@ pub mod system_calls; pub mod test_utils; /// Trait for configuring the EVM for executing full blocks. -#[auto_impl::auto_impl(&, Arc)] pub trait ConfigureEvm: ConfigureEvmEnv { /// Associated type for the default external context that should be configured for the EVM. type DefaultExternalContext<'a>; @@ -70,6 +70,31 @@ pub trait ConfigureEvm: ConfigureEvmEnv { evm } + /// Returns a new EVM with the given database configured with `cfg` and `block_env` + /// configuration derived from the given header. Relies on + /// [`ConfigureEvmEnv::cfg_and_block_env`]. + /// + /// # Caution + /// + /// This does not initialize the tx environment. + fn evm_for_block( + &self, + db: DB, + header: &Self::Header, + ) -> Evm<'_, Self::DefaultExternalContext<'_>, DB> { + let EvmEnv { + cfg_env_with_handler_cfg: CfgEnvWithHandlerCfg { cfg_env, handler_cfg }, + block_env, + } = self.cfg_and_block_env(header); + self.evm_with_env( + db, + EnvWithHandlerCfg { + env: Box::new(Env { cfg: cfg_env, block: block_env, tx: Default::default() }), + handler_cfg, + }, + ) + } + /// Returns a new EVM with the given database configured with the given environment settings, /// including the spec id. /// @@ -109,6 +134,59 @@ pub trait ConfigureEvm: ConfigureEvmEnv { fn default_external_context<'a>(&self) -> Self::DefaultExternalContext<'a>; } +impl<'b, T> ConfigureEvm for &'b T +where + T: ConfigureEvm, + &'b T: ConfigureEvmEnv
, +{ + type DefaultExternalContext<'a> = T::DefaultExternalContext<'a>; + + fn default_external_context<'a>(&self) -> Self::DefaultExternalContext<'a> { + (*self).default_external_context() + } + + fn evm(&self, db: DB) -> Evm<'_, Self::DefaultExternalContext<'_>, DB> { + (*self).evm(db) + } + + fn evm_for_block( + &self, + db: DB, + header: &Self::Header, + ) -> Evm<'_, Self::DefaultExternalContext<'_>, DB> { + (*self).evm_for_block(db, header) + } + + fn evm_with_env( + &self, + db: DB, + env: EnvWithHandlerCfg, + ) -> Evm<'_, Self::DefaultExternalContext<'_>, DB> { + (*self).evm_with_env(db, env) + } + + fn evm_with_env_and_inspector( + &self, + db: DB, + env: EnvWithHandlerCfg, + inspector: I, + ) -> Evm<'_, I, DB> + where + DB: Database, + I: GetInspector, + { + (*self).evm_with_env_and_inspector(db, env, inspector) + } + + fn evm_with_inspector(&self, db: DB, inspector: I) -> Evm<'_, I, DB> + where + DB: Database, + I: GetInspector, + { + (*self).evm_with_inspector(db, inspector) + } +} + /// This represents the set of methods used to configure the EVM's environment before block /// execution. /// diff --git a/crates/exex/types/src/notification.rs b/crates/exex/types/src/notification.rs index 10f6f530346e..fb3d6c506957 100644 --- a/crates/exex/types/src/notification.rs +++ b/crates/exex/types/src/notification.rs @@ -75,7 +75,6 @@ impl From> for ExExNotification

pub(super) mod serde_bincode_compat { use reth_execution_types::serde_bincode_compat::Chain; use reth_primitives::{EthPrimitives, NodePrimitives}; - use reth_primitives_traits::serde_bincode_compat::SerdeBincodeCompat; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde_with::{DeserializeAs, SerializeAs}; use std::sync::Arc; diff --git a/crates/net/eth-wire/src/errors/p2p.rs b/crates/net/eth-wire/src/errors/p2p.rs index f24e2cebc784..c77816b48b10 100644 --- a/crates/net/eth-wire/src/errors/p2p.rs +++ b/crates/net/eth-wire/src/errors/p2p.rs @@ -63,10 +63,6 @@ pub enum P2PStreamError { #[error("mismatched protocol version in Hello message: {0}")] MismatchedProtocolVersion(GotExpected), - /// Ping started before the handshake completed. - #[error("started ping task before the handshake completed")] - PingBeforeHandshake, - /// Too many messages buffered before sending. #[error("too many messages buffered before sending")] SendBufferFull, diff --git a/crates/optimism/evm/src/execute.rs b/crates/optimism/evm/src/execute.rs index 91a3993d13f9..a50114f89a3e 100644 --- a/crates/optimism/evm/src/execute.rs +++ b/crates/optimism/evm/src/execute.rs @@ -2,14 +2,13 @@ use crate::{l1::ensure_create2_deployer, OpBlockExecutionError, OpEvmConfig}; use alloc::{boxed::Box, sync::Arc, vec::Vec}; -use alloy_consensus::{BlockHeader, Eip658Value, Header, Receipt, Transaction as _}; +use alloy_consensus::{BlockHeader, Eip658Value, Receipt, Transaction as _}; use alloy_eips::eip7685::Requests; use core::fmt::Display; use op_alloy_consensus::{OpDepositReceipt, OpTxType}; use reth_chainspec::EthereumHardforks; use reth_consensus::ConsensusError; use reth_evm::{ - env::EvmEnv, execute::{ balance_increment_state, BasicBlockExecutorProvider, BlockExecutionError, BlockExecutionStrategy, BlockExecutionStrategyFactory, BlockValidationError, ExecuteOutput, @@ -26,7 +25,7 @@ use reth_optimism_primitives::{OpBlock, OpPrimitives, OpReceipt, OpTransactionSi use reth_primitives::RecoveredBlock; use reth_primitives_traits::{BlockBody, SignedTransaction}; use reth_revm::{Database, State}; -use revm_primitives::{db::DatabaseCommit, EnvWithHandlerCfg, ResultAndState}; +use revm_primitives::{db::DatabaseCommit, ResultAndState}; use tracing::trace; /// Factory for [`OpExecutionStrategy`]. @@ -104,21 +103,6 @@ where } } -impl OpExecutionStrategy -where - DB: Database + Display>, - EvmConfig: ConfigureEvm

, -{ - /// Configures a new evm configuration and block environment for the given block. - /// - /// Caution: this does not initialize the tx environment. - fn evm_env_for_block(&self, header: &Header) -> EnvWithHandlerCfg { - let evm_env = self.evm_config.cfg_and_block_env(header); - let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env; - EnvWithHandlerCfg::new_with_cfg_env(cfg_env_with_handler_cfg, block_env, Default::default()) - } -} - impl BlockExecutionStrategy for OpExecutionStrategy where DB: Database + Display>, @@ -141,8 +125,7 @@ where (*self.chain_spec).is_spurious_dragon_active_at_block(block.number()); self.state.set_state_clear_flag(state_clear_flag); - let env = self.evm_env_for_block(block.header()); - let mut evm = self.evm_config.evm_with_env(&mut self.state, env); + let mut evm = self.evm_config.evm_for_block(&mut self.state, block.header()); self.system_caller.apply_beacon_root_contract_call( block.timestamp, @@ -165,11 +148,10 @@ where &mut self, block: &RecoveredBlock, ) -> Result, Self::Error> { - let env = self.evm_env_for_block(block.header()); - let mut evm = self.evm_config.evm_with_env(&mut self.state, env); + let mut evm = self.evm_config.evm_for_block(&mut self.state, block.header()); let is_regolith = - self.chain_spec.fork(OpHardfork::Regolith).active_at_timestamp(block.timestamp); + self.chain_spec.fork(OpHardfork::Regolith).active_at_timestamp(block.timestamp()); let mut cumulative_gas_used = 0; let mut receipts = Vec::with_capacity(block.body().transaction_count()); @@ -317,7 +299,7 @@ impl OpExecutorProvider { mod tests { use super::*; use crate::OpChainSpec; - use alloy_consensus::TxEip1559; + use alloy_consensus::{Header, TxEip1559}; use alloy_primitives::{ b256, Address, PrimitiveSignature as Signature, StorageKey, StorageValue, U256, }; diff --git a/crates/trie/trie/src/proof/blinded.rs b/crates/trie/trie/src/proof/blinded.rs index c8d0f3bb5a22..57d0de97fbe7 100644 --- a/crates/trie/trie/src/proof/blinded.rs +++ b/crates/trie/trie/src/proof/blinded.rs @@ -8,6 +8,7 @@ use reth_execution_errors::{SparseTrieError, SparseTrieErrorKind}; use reth_trie_common::{prefix_set::TriePrefixSetsMut, Nibbles}; use reth_trie_sparse::blinded::{pad_path_to_key, BlindedProvider, BlindedProviderFactory}; use std::sync::Arc; +use tracing::trace; /// Factory for instantiating providers capable of retrieving blinded trie nodes via proofs. #[derive(Debug)] @@ -91,8 +92,10 @@ where .with_prefix_sets_mut(self.prefix_sets.as_ref().clone()) .multiproof(targets) .map_err(|error| SparseTrieErrorKind::Other(Box::new(error)))?; + let node = proof.account_subtree.into_inner().remove(path); - Ok(proof.account_subtree.into_inner().remove(path)) + trace!(target: "trie::proof::blinded", ?path, ?node, "Blinded node for account trie"); + Ok(node) } } @@ -138,7 +141,9 @@ where .with_prefix_set_mut(storage_prefix_set) .storage_multiproof(targets) .map_err(|error| SparseTrieErrorKind::Other(Box::new(error)))?; + let node = proof.subtree.into_inner().remove(path); - Ok(proof.subtree.into_inner().remove(path)) + trace!(target: "trie::proof::blinded", account = ?self.account, ?path, ?node, "Blinded node for storage trie"); + Ok(node) } } diff --git a/examples/custom-beacon-withdrawals/src/main.rs b/examples/custom-beacon-withdrawals/src/main.rs index f80d9b75aa6b..7bb8a77d2598 100644 --- a/examples/custom-beacon-withdrawals/src/main.rs +++ b/examples/custom-beacon-withdrawals/src/main.rs @@ -10,23 +10,20 @@ use alloy_sol_types::SolCall; #[cfg(feature = "optimism")] use reth::revm::primitives::OptimismFields; use reth::{ - api::{ConfigureEvm, ConfigureEvmEnv, NodeTypesWithEngine}, + api::{ConfigureEvm, NodeTypesWithEngine}, builder::{components::ExecutorBuilder, BuilderContext, FullNodeTypes}, cli::Cli, providers::ProviderError, revm::{ interpreter::Host, - primitives::{address, Address, Bytes, Env, EnvWithHandlerCfg, TransactTo, TxEnv, U256}, + primitives::{address, Address, Bytes, Env, TransactTo, TxEnv, U256}, Database, DatabaseCommit, Evm, State, }, }; use reth_chainspec::{ChainSpec, EthereumHardforks}; -use reth_evm::{ - env::EvmEnv, - execute::{ - BlockExecutionError, BlockExecutionStrategy, BlockExecutionStrategyFactory, ExecuteOutput, - InternalBlockExecutionError, - }, +use reth_evm::execute::{ + BlockExecutionError, BlockExecutionStrategy, BlockExecutionStrategyFactory, ExecuteOutput, + InternalBlockExecutionError, }; use reth_evm_ethereum::EthEvmConfig; use reth_node_ethereum::{node::EthereumAddOns, BasicBlockExecutorProvider, EthereumNode}; @@ -121,22 +118,6 @@ where state: State, } -impl CustomExecutorStrategy -where - DB: Database + Display>, -{ - /// Configures a new evm configuration and block environment for the given block. - /// - /// # Caution - /// - /// This does not initialize the tx environment. - fn evm_env_for_block(&self, header: &alloy_consensus::Header) -> EnvWithHandlerCfg { - let evm_env = self.evm_config.cfg_and_block_env(header); - let EvmEnv { cfg_env_with_handler_cfg, block_env } = evm_env; - EnvWithHandlerCfg::new_with_cfg_env(cfg_env_with_handler_cfg, block_env, Default::default()) - } -} - impl BlockExecutionStrategy for CustomExecutorStrategy where DB: Database + Display>, @@ -169,8 +150,7 @@ where block: &RecoveredBlock, _receipts: &[Receipt], ) -> Result { - let env = self.evm_env_for_block(block.header()); - let mut evm = self.evm_config.evm_with_env(&mut self.state, env); + let mut evm = self.evm_config.evm_for_block(&mut self.state, block.header()); if let Some(withdrawals) = block.body().withdrawals.as_ref() { apply_withdrawals_contract_call(withdrawals, &mut evm)?;