chore(tree): Move tree related files to root of the lib (#2359)

This commit is contained in:
rakita
2023-04-23 17:30:17 +02:00
committed by GitHub
parent e2c27073e6
commit 07efa2db45
18 changed files with 69 additions and 88 deletions

1
Cargo.lock generated
View File

@@ -5160,7 +5160,6 @@ dependencies = [
name = "reth-revm"
version = "0.1.0"
dependencies = [
"reth-blockchain-tree",
"reth-consensus-common",
"reth-interfaces",
"reth-primitives",

View File

@@ -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<DB: Database, C: Consensus, EF: ExecutorFactory> BlockchainTree<DB, C, EF>
#[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};

View File

@@ -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::{

View File

@@ -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};

View File

@@ -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<PostState>);
impl<SP: StateProvider> BlockExecutor<SP> for TestExecutor {
fn execute(
&mut self,
_block: &Block,
_total_difficulty: U256,
_senders: Option<Vec<Address>>,
) -> Result<PostState, ExecutionError> {
self.0.clone().ok_or(ExecutionError::VerificationFailed)
}
fn execute_and_verify_receipt(
&mut self,
_block: &Block,
_total_difficulty: U256,
_senders: Option<Vec<Address>>,
) -> Result<PostState, ExecutionError> {
self.0.clone().ok_or(ExecutionError::VerificationFailed)
}
}

View File

@@ -1,5 +0,0 @@
mod executor;
pub use executor::*;
mod factory;
pub use factory::*;

View File

@@ -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};

View File

@@ -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

View File

@@ -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() });
}

View File

@@ -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;

View File

@@ -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<PostState>);
impl<SP: StateProvider> BlockExecutor<SP> for TestExecutor {
fn execute(
&mut self,
_block: &Block,
_total_difficulty: U256,
_senders: Option<Vec<Address>>,
) -> Result<PostState, ExecutionError> {
self.0.clone().ok_or(ExecutionError::VerificationFailed)
}
fn execute_and_verify_receipt(
&mut self,
_block: &Block,
_total_difficulty: U256,
_senders: Option<Vec<Address>>,
) -> Result<PostState, ExecutionError> {
self.0.clone().ok_or(ExecutionError::VerificationFailed)
}
}
/// Executor factory with pre-set execution results.
#[derive(Clone, Debug)]

View File

@@ -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;