diff --git a/Cargo.lock b/Cargo.lock index 816158ace4..67885143e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5160,7 +5160,6 @@ dependencies = [ name = "reth-revm" version = "0.1.0" dependencies = [ - "reth-blockchain-tree", "reth-consensus-common", "reth-interfaces", "reth-primitives", diff --git a/crates/blockchain-tree/src/blockchain_tree/block_indices.rs b/crates/blockchain-tree/src/block_indices.rs similarity index 100% rename from crates/blockchain-tree/src/blockchain_tree/block_indices.rs rename to crates/blockchain-tree/src/block_indices.rs diff --git a/crates/blockchain-tree/src/blockchain_tree/mod.rs b/crates/blockchain-tree/src/blockchain_tree.rs similarity index 98% rename from crates/blockchain-tree/src/blockchain_tree/mod.rs rename to crates/blockchain-tree/src/blockchain_tree.rs index 2138be4148..e4f9e1eb01 100644 --- a/crates/blockchain-tree/src/blockchain_tree/mod.rs +++ b/crates/blockchain-tree/src/blockchain_tree.rs @@ -1,5 +1,4 @@ //! Implementation of [`BlockchainTree`] -use chain::BlockChainId; use reth_db::{cursor::DbCursorRO, database::Database, tables, transaction::DbTx}; use reth_interfaces::{ blockchain_tree::BlockStatus, consensus::Consensus, executor::Error as ExecError, Error, @@ -18,23 +17,10 @@ use std::{ sync::Arc, }; -pub mod block_indices; -use block_indices::BlockIndices; - -pub mod chain; -pub use chain::AppendableChain; - -pub mod config; -use config::BlockchainTreeConfig; - -pub mod externals; -use externals::TreeExternals; - -pub mod shareable; -pub use shareable::ShareableBlockchainTree; - -pub mod post_state_data; -pub use post_state_data::{PostStateData, PostStateDataRef}; +use crate::{ + chain::BlockChainId, AppendableChain, BlockIndices, BlockchainTreeConfig, PostStateData, + TreeExternals, +}; #[cfg_attr(doc, aquamarine::aquamarine)] /// Tree of chains and its identifications. @@ -696,7 +682,6 @@ impl BlockchainTree #[cfg(test)] mod tests { use super::*; - use crate::test_utils::TestExecutorFactory; use assert_matches::assert_matches; use reth_db::{ mdbx::{test_utils::create_test_rw_db, Env, WriteMap}, @@ -705,7 +690,9 @@ mod tests { use reth_interfaces::test_utils::TestConsensus; use reth_primitives::{proofs::EMPTY_ROOT, ChainSpecBuilder, H256, MAINNET}; use reth_provider::{ - insert_block, post_state::PostState, test_utils::blocks::BlockChainTestData, + insert_block, + post_state::PostState, + test_utils::{blocks::BlockChainTestData, TestExecutorFactory}, }; use std::{collections::HashSet, sync::Arc}; diff --git a/crates/blockchain-tree/src/blockchain_tree/chain.rs b/crates/blockchain-tree/src/chain.rs similarity index 98% rename from crates/blockchain-tree/src/blockchain_tree/chain.rs rename to crates/blockchain-tree/src/chain.rs index 619a1031b7..d4a3b5d67c 100644 --- a/crates/blockchain-tree/src/blockchain_tree/chain.rs +++ b/crates/blockchain-tree/src/chain.rs @@ -2,7 +2,7 @@ //! //! A [`Chain`] contains the state of accounts for the chain after execution of its constituent //! blocks, as well as a list of the blocks the chain is composed of. -use crate::{blockchain_tree::PostStateDataRef, post_state::PostState}; +use crate::{post_state::PostState, PostStateDataRef}; use reth_db::database::Database; use reth_interfaces::{consensus::Consensus, executor::Error as ExecError, Error}; use reth_primitives::{ diff --git a/crates/blockchain-tree/src/blockchain_tree/config.rs b/crates/blockchain-tree/src/config.rs similarity index 100% rename from crates/blockchain-tree/src/blockchain_tree/config.rs rename to crates/blockchain-tree/src/config.rs diff --git a/crates/blockchain-tree/src/blockchain_tree/externals.rs b/crates/blockchain-tree/src/externals.rs similarity index 100% rename from crates/blockchain-tree/src/blockchain_tree/externals.rs rename to crates/blockchain-tree/src/externals.rs diff --git a/crates/blockchain-tree/src/lib.rs b/crates/blockchain-tree/src/lib.rs index 5ba25b8e98..6452ad2d38 100644 --- a/crates/blockchain-tree/src/lib.rs +++ b/crates/blockchain-tree/src/lib.rs @@ -4,17 +4,28 @@ no_crate_inject, attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables)) ))] - -//! Reth executor executes transaction in block of data. - -pub mod eth_dao_fork; +//! Implementation of the [BlockchainTree] /// Execution result types. pub use reth_provider::post_state; pub mod blockchain_tree; -pub use blockchain_tree::*; +pub use blockchain_tree::{BlockHashes, BlockchainTree}; -#[cfg(any(test, feature = "test-utils"))] -/// Common test helpers for mocking out executor and executor factory -pub mod test_utils; +pub mod block_indices; +pub use block_indices::BlockIndices; + +pub mod chain; +pub use chain::AppendableChain; + +pub mod config; +pub use config::BlockchainTreeConfig; + +pub mod externals; +pub use externals::TreeExternals; + +pub mod shareable; +pub use shareable::ShareableBlockchainTree; + +pub mod post_state_data; +pub use post_state_data::{PostStateData, PostStateDataRef}; diff --git a/crates/blockchain-tree/src/blockchain_tree/post_state_data.rs b/crates/blockchain-tree/src/post_state_data.rs similarity index 100% rename from crates/blockchain-tree/src/blockchain_tree/post_state_data.rs rename to crates/blockchain-tree/src/post_state_data.rs diff --git a/crates/blockchain-tree/src/blockchain_tree/shareable.rs b/crates/blockchain-tree/src/shareable.rs similarity index 100% rename from crates/blockchain-tree/src/blockchain_tree/shareable.rs rename to crates/blockchain-tree/src/shareable.rs diff --git a/crates/blockchain-tree/src/test_utils/executor.rs b/crates/blockchain-tree/src/test_utils/executor.rs deleted file mode 100644 index d09338fd5e..0000000000 --- a/crates/blockchain-tree/src/test_utils/executor.rs +++ /dev/null @@ -1,26 +0,0 @@ -use reth_interfaces::executor::Error as ExecutionError; -use reth_primitives::{Address, Block, U256}; -use reth_provider::{post_state::PostState, BlockExecutor, StateProvider}; - -/// Test executor with mocked result. -pub struct TestExecutor(pub Option); - -impl BlockExecutor for TestExecutor { - fn execute( - &mut self, - _block: &Block, - _total_difficulty: U256, - _senders: Option>, - ) -> Result { - self.0.clone().ok_or(ExecutionError::VerificationFailed) - } - - fn execute_and_verify_receipt( - &mut self, - _block: &Block, - _total_difficulty: U256, - _senders: Option>, - ) -> Result { - self.0.clone().ok_or(ExecutionError::VerificationFailed) - } -} diff --git a/crates/blockchain-tree/src/test_utils/mod.rs b/crates/blockchain-tree/src/test_utils/mod.rs deleted file mode 100644 index 86ef2f53ae..0000000000 --- a/crates/blockchain-tree/src/test_utils/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -mod executor; -pub use executor::*; - -mod factory; -pub use factory::*; diff --git a/crates/consensus/beacon/src/engine/mod.rs b/crates/consensus/beacon/src/engine/mod.rs index 802a5e29bd..56729d31e3 100644 --- a/crates/consensus/beacon/src/engine/mod.rs +++ b/crates/consensus/beacon/src/engine/mod.rs @@ -631,18 +631,14 @@ mod tests { use crate::engine::error::BeaconForkChoiceUpdateError; use assert_matches::assert_matches; use reth_blockchain_tree::{ - blockchain_tree::{ - config::BlockchainTreeConfig, externals::TreeExternals, BlockchainTree, - ShareableBlockchainTree, - }, - post_state::PostState, - test_utils::TestExecutorFactory, + config::BlockchainTreeConfig, externals::TreeExternals, post_state::PostState, + BlockchainTree, ShareableBlockchainTree, }; use reth_db::mdbx::{test_utils::create_test_rw_db, Env, WriteMap}; use reth_interfaces::{sync::NoopSyncStateUpdate, test_utils::TestConsensus}; use reth_payload_builder::test_utils::spawn_test_payload_service; use reth_primitives::{ChainSpec, ChainSpecBuilder, SealedBlockWithSenders, H256, MAINNET}; - use reth_provider::Transaction; + use reth_provider::{test_utils::TestExecutorFactory, Transaction}; use reth_stages::{test_utils::TestStages, ExecOutput, PipelineError, StageError}; use reth_tasks::TokioTaskExecutor; use std::{collections::VecDeque, time::Duration}; diff --git a/crates/revm/Cargo.toml b/crates/revm/Cargo.toml index 7c5fb9afe0..6c27fd78e0 100644 --- a/crates/revm/Cargo.toml +++ b/crates/revm/Cargo.toml @@ -13,7 +13,6 @@ reth-interfaces = { path = "../interfaces" } reth-provider = { path = "../storage/provider" } reth-revm-primitives = { path = "./revm-primitives" } reth-revm-inspectors = { path = "./revm-inspectors" } -reth-blockchain-tree = { path = "../blockchain-tree" } reth-consensus-common = { path = "../consensus/common" } # revm diff --git a/crates/blockchain-tree/src/eth_dao_fork.rs b/crates/revm/src/eth_dao_fork.rs similarity index 100% rename from crates/blockchain-tree/src/eth_dao_fork.rs rename to crates/revm/src/eth_dao_fork.rs diff --git a/crates/revm/src/executor.rs b/crates/revm/src/executor.rs index 19122be34f..d6d4cabac1 100644 --- a/crates/revm/src/executor.rs +++ b/crates/revm/src/executor.rs @@ -1,18 +1,18 @@ use crate::{ database::SubState, env::{fill_cfg_and_block_env, fill_tx_env}, + eth_dao_fork::{DAO_HARDFORK_BENEFICIARY, DAO_HARDKFORK_ACCOUNTS}, into_reth_log, stack::{InspectorStack, InspectorStackConfig}, to_reth_acc, }; -use reth_blockchain_tree::post_state::PostState; use reth_consensus_common::calc; use reth_interfaces::executor::Error; use reth_primitives::{ Account, Address, Block, BlockNumber, Bloom, Bytecode, ChainSpec, Hardfork, Header, Receipt, ReceiptWithBloom, TransactionSigned, Withdrawal, H256, U256, }; -use reth_provider::{BlockExecutor, StateProvider}; +use reth_provider::{BlockExecutor, PostState, StateProvider}; use revm::{ db::{AccountState, CacheDB, DatabaseRef}, primitives::{ @@ -140,7 +140,7 @@ where let mut drained_balance = U256::ZERO; // drain all accounts ether - for address in reth_blockchain_tree::eth_dao_fork::DAO_HARDKFORK_ACCOUNTS { + for address in DAO_HARDKFORK_ACCOUNTS { let db_account = db.load_account(address).map_err(|_| Error::ProviderError)?; let old = to_reth_acc(&db_account.info); // drain balance @@ -151,7 +151,7 @@ where } // add drained ether to beneficiary. - let beneficiary = reth_blockchain_tree::eth_dao_fork::DAO_HARDFORK_BENEFICIARY; + let beneficiary = DAO_HARDFORK_BENEFICIARY; self.increment_account_balance(block_number, beneficiary, drained_balance, post_state)?; Ok(()) @@ -860,9 +860,7 @@ mod tests { let mut db = StateProviderTest::default(); let mut beneficiary_balance = 0; - for (i, dao_address) in - reth_blockchain_tree::eth_dao_fork::DAO_HARDKFORK_ACCOUNTS.iter().enumerate() - { + for (i, dao_address) in DAO_HARDKFORK_ACCOUNTS.iter().enumerate() { db.insert_account( *dao_address, Account { balance: U256::from(i), nonce: 0x00, bytecode_hash: None }, @@ -893,26 +891,21 @@ mod tests { // Check if cache is set // beneficiary let db = executor.db(); - let dao_beneficiary = - db.accounts.get(&reth_blockchain_tree::eth_dao_fork::DAO_HARDFORK_BENEFICIARY).unwrap(); + let dao_beneficiary = db.accounts.get(&DAO_HARDFORK_BENEFICIARY).unwrap(); assert_eq!(dao_beneficiary.info.balance, U256::from(beneficiary_balance)); - for address in reth_blockchain_tree::eth_dao_fork::DAO_HARDKFORK_ACCOUNTS.iter() { + for address in DAO_HARDKFORK_ACCOUNTS.iter() { let account = db.accounts.get(address).unwrap(); assert_eq!(account.info.balance, U256::ZERO); } // check changesets - let beneficiary_state = out - .accounts() - .get(&reth_blockchain_tree::eth_dao_fork::DAO_HARDFORK_BENEFICIARY) - .unwrap() - .unwrap(); + let beneficiary_state = out.accounts().get(&DAO_HARDFORK_BENEFICIARY).unwrap().unwrap(); assert_eq!( beneficiary_state, Account { balance: U256::from(beneficiary_balance), ..Default::default() }, ); - for address in reth_blockchain_tree::eth_dao_fork::DAO_HARDKFORK_ACCOUNTS.iter() { + for address in DAO_HARDKFORK_ACCOUNTS.iter() { let updated_account = out.accounts().get(address).unwrap().unwrap(); assert_eq!(updated_account, Account { balance: U256::ZERO, ..Default::default() }); } diff --git a/crates/revm/src/lib.rs b/crates/revm/src/lib.rs index 134ebf94c0..1d6060097a 100644 --- a/crates/revm/src/lib.rs +++ b/crates/revm/src/lib.rs @@ -24,3 +24,6 @@ pub use reth_revm_primitives::*; /// Re-export everything pub use revm; + +/// Etereum DAO hardfork state change data. +pub mod eth_dao_fork; diff --git a/crates/blockchain-tree/src/test_utils/factory.rs b/crates/storage/provider/src/test_utils/executor.rs similarity index 52% rename from crates/blockchain-tree/src/test_utils/factory.rs rename to crates/storage/provider/src/test_utils/executor.rs index 50e4360ad1..81c6ddbff2 100644 --- a/crates/blockchain-tree/src/test_utils/factory.rs +++ b/crates/storage/provider/src/test_utils/executor.rs @@ -1,8 +1,30 @@ -use super::TestExecutor; +use crate::{post_state::PostState, BlockExecutor, ExecutorFactory, StateProvider}; use parking_lot::Mutex; -use reth_primitives::ChainSpec; -use reth_provider::{post_state::PostState, ExecutorFactory, StateProvider}; +use reth_interfaces::executor::Error as ExecutionError; +use reth_primitives::{Address, Block, ChainSpec, U256}; use std::sync::Arc; +/// Test executor with mocked result. +pub struct TestExecutor(pub Option); + +impl BlockExecutor for TestExecutor { + fn execute( + &mut self, + _block: &Block, + _total_difficulty: U256, + _senders: Option>, + ) -> Result { + self.0.clone().ok_or(ExecutionError::VerificationFailed) + } + + fn execute_and_verify_receipt( + &mut self, + _block: &Block, + _total_difficulty: U256, + _senders: Option>, + ) -> Result { + self.0.clone().ok_or(ExecutionError::VerificationFailed) + } +} /// Executor factory with pre-set execution results. #[derive(Clone, Debug)] diff --git a/crates/storage/provider/src/test_utils/mod.rs b/crates/storage/provider/src/test_utils/mod.rs index 8a72aa01a4..bbbe973908 100644 --- a/crates/storage/provider/src/test_utils/mod.rs +++ b/crates/storage/provider/src/test_utils/mod.rs @@ -1,8 +1,10 @@ pub mod blocks; mod events; +mod executor; mod mock; mod noop; pub use events::TestCanonStateSubscriptions; +pub use executor::{TestExecutor, TestExecutorFactory}; pub use mock::{ExtendedAccount, MockEthProvider}; pub use noop::NoopProvider;