mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: rm outdated executor types (#8157)
This commit is contained in:
@ -440,8 +440,8 @@ mod tests {
|
||||
Header, PruneModes, SealedHeader, MAINNET,
|
||||
};
|
||||
use reth_provider::{
|
||||
test_utils::{create_test_provider_factory_with_chain_spec, TestExecutorFactory},
|
||||
BundleStateWithReceipts, StaticFileProviderFactory,
|
||||
test_utils::create_test_provider_factory_with_chain_spec, BundleStateWithReceipts,
|
||||
StaticFileProviderFactory,
|
||||
};
|
||||
use reth_stages::{test_utils::TestStages, ExecOutput, StageError};
|
||||
use reth_static_file::StaticFileProducer;
|
||||
@ -492,9 +492,6 @@ mod tests {
|
||||
fn build(self, chain_spec: Arc<ChainSpec>) -> Pipeline<Arc<TempDatabase<DatabaseEnv>>> {
|
||||
reth_tracing::init_test_tracing();
|
||||
|
||||
let executor_factory = TestExecutorFactory::default();
|
||||
executor_factory.extend(self.executor_results);
|
||||
|
||||
// Setup pipeline
|
||||
let (tip_tx, _tip_rx) = watch::channel(B256::default());
|
||||
let mut pipeline = Pipeline::builder()
|
||||
|
||||
@ -1,71 +0,0 @@
|
||||
use crate::{
|
||||
bundle_state::BundleStateWithReceipts, BlockExecutor, ExecutorFactory, PrunableBlockExecutor,
|
||||
StateProvider,
|
||||
};
|
||||
use parking_lot::Mutex;
|
||||
use reth_interfaces::executor::BlockExecutionError;
|
||||
use reth_primitives::{BlockNumber, BlockWithSenders, PruneModes, Receipt, U256};
|
||||
use std::sync::Arc;
|
||||
/// Test executor with mocked result.
|
||||
#[derive(Debug)]
|
||||
pub struct TestExecutor(pub Option<BundleStateWithReceipts>);
|
||||
|
||||
impl BlockExecutor for TestExecutor {
|
||||
type Error = BlockExecutionError;
|
||||
|
||||
fn execute_and_verify_receipt(
|
||||
&mut self,
|
||||
_block: &BlockWithSenders,
|
||||
_total_difficulty: U256,
|
||||
) -> Result<(), BlockExecutionError> {
|
||||
if self.0.is_none() {
|
||||
return Err(BlockExecutionError::UnavailableForTest)
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn execute_transactions(
|
||||
&mut self,
|
||||
_block: &BlockWithSenders,
|
||||
_total_difficulty: U256,
|
||||
) -> Result<(Vec<Receipt>, u64), BlockExecutionError> {
|
||||
Err(BlockExecutionError::UnavailableForTest)
|
||||
}
|
||||
|
||||
fn take_output_state(&mut self) -> BundleStateWithReceipts {
|
||||
self.0.clone().unwrap_or_default()
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> Option<usize> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl PrunableBlockExecutor for TestExecutor {
|
||||
fn set_tip(&mut self, _tip: BlockNumber) {}
|
||||
|
||||
fn set_prune_modes(&mut self, _prune_modes: PruneModes) {}
|
||||
}
|
||||
|
||||
/// Executor factory with pre-set execution results.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct TestExecutorFactory {
|
||||
exec_results: Arc<Mutex<Vec<BundleStateWithReceipts>>>,
|
||||
}
|
||||
|
||||
impl TestExecutorFactory {
|
||||
/// Extend the mocked execution results
|
||||
pub fn extend(&self, results: Vec<BundleStateWithReceipts>) {
|
||||
self.exec_results.lock().extend(results);
|
||||
}
|
||||
}
|
||||
|
||||
impl ExecutorFactory for TestExecutorFactory {
|
||||
fn with_state<'a, SP: StateProvider + 'a>(
|
||||
&'a self,
|
||||
_sp: SP,
|
||||
) -> Box<dyn PrunableBlockExecutor<Error = <TestExecutor as BlockExecutor>::Error> + 'a> {
|
||||
let exec_res = self.exec_results.lock().pop();
|
||||
Box::new(TestExecutor(exec_res))
|
||||
}
|
||||
}
|
||||
@ -8,12 +8,10 @@ use std::sync::Arc;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@ -1,68 +0,0 @@
|
||||
//! Executor Factory
|
||||
|
||||
use crate::{bundle_state::BundleStateWithReceipts, StateProvider};
|
||||
use reth_interfaces::executor::BlockExecutionError;
|
||||
use reth_primitives::{BlockNumber, BlockWithSenders, PruneModes, Receipt, U256};
|
||||
|
||||
/// A factory capable of creating an executor with the given state provider.
|
||||
pub trait ExecutorFactory: Send + Sync + 'static {
|
||||
/// Executor with [`StateProvider`]
|
||||
fn with_state<'a, SP: StateProvider + 'a>(
|
||||
&'a self,
|
||||
sp: SP,
|
||||
) -> Box<dyn PrunableBlockExecutor<Error = BlockExecutionError> + 'a>;
|
||||
}
|
||||
|
||||
/// An executor capable of executing a block.
|
||||
///
|
||||
/// This type is capable of executing (multiple) blocks by applying the state changes made by each
|
||||
/// block. The final state of the executor can extracted using
|
||||
/// [`Self::take_output_state`].
|
||||
pub trait BlockExecutor {
|
||||
/// The error type returned by the executor.
|
||||
type Error;
|
||||
|
||||
/// Executes the entire block and verifies:
|
||||
/// - receipts (receipts root)
|
||||
///
|
||||
/// This will update the state of the executor with the changes made by the block.
|
||||
fn execute_and_verify_receipt(
|
||||
&mut self,
|
||||
block: &BlockWithSenders,
|
||||
total_difficulty: U256,
|
||||
) -> Result<(), Self::Error>;
|
||||
|
||||
/// Runs the provided transactions and commits their state to the run-time database.
|
||||
///
|
||||
/// The returned [BundleStateWithReceipts] can be used to persist the changes to disk, and
|
||||
/// contains the changes made by each transaction.
|
||||
///
|
||||
/// The changes in [BundleStateWithReceipts] have a transition ID associated with them: there is
|
||||
/// one transition ID for each transaction (with the first executed tx having transition ID
|
||||
/// 0, and so on).
|
||||
///
|
||||
/// The second returned value represents the total gas used by this block of transactions.
|
||||
///
|
||||
/// See [execute_and_verify_receipt](BlockExecutor::execute_and_verify_receipt) for more
|
||||
/// details.
|
||||
fn execute_transactions(
|
||||
&mut self,
|
||||
block: &BlockWithSenders,
|
||||
total_difficulty: U256,
|
||||
) -> Result<(Vec<Receipt>, u64), Self::Error>;
|
||||
|
||||
/// Return bundle state. This is output of executed blocks.
|
||||
fn take_output_state(&mut self) -> BundleStateWithReceipts;
|
||||
|
||||
/// Returns the size hint of current in-memory changes.
|
||||
fn size_hint(&self) -> Option<usize>;
|
||||
}
|
||||
|
||||
/// A [BlockExecutor] capable of in-memory pruning of the data that will be written to the database.
|
||||
pub trait PrunableBlockExecutor: BlockExecutor {
|
||||
/// Set tip - highest known block number.
|
||||
fn set_tip(&mut self, tip: BlockNumber);
|
||||
|
||||
/// Set prune modes.
|
||||
fn set_prune_modes(&mut self, prune_modes: PruneModes);
|
||||
}
|
||||
@ -48,9 +48,6 @@ pub use transactions::{TransactionsProvider, TransactionsProviderExt};
|
||||
mod withdrawals;
|
||||
pub use withdrawals::WithdrawalsProvider;
|
||||
|
||||
mod executor;
|
||||
pub use executor::{BlockExecutor, ExecutorFactory, PrunableBlockExecutor};
|
||||
|
||||
mod chain;
|
||||
pub use chain::{
|
||||
CanonStateNotification, CanonStateNotificationSender, CanonStateNotificationStream,
|
||||
|
||||
Reference in New Issue
Block a user