//! Helper type that represents one of two possible executor types use crate::{ execute::{BlockExecutorProvider, Executor}, Database, OnStateHook, }; // re-export Either pub use futures_util::future::Either; use reth_execution_types::{BlockExecutionOutput, BlockExecutionResult}; use reth_primitives_traits::{NodePrimitives, RecoveredBlock}; impl BlockExecutorProvider for Either where A: BlockExecutorProvider, B: BlockExecutorProvider, { type Primitives = A::Primitives; type Executor = Either, B::Executor>; fn executor(&self, db: DB) -> Self::Executor where DB: Database, { match self { Self::Left(a) => Either::Left(a.executor(db)), Self::Right(b) => Either::Right(b.executor(db)), } } } impl Executor for Either where A: Executor, B: Executor, DB: Database, { type Primitives = A::Primitives; type Error = A::Error; fn execute_one( &mut self, block: &RecoveredBlock<::Block>, ) -> Result::Receipt>, Self::Error> { match self { Self::Left(a) => a.execute_one(block), Self::Right(b) => b.execute_one(block), } } fn execute_one_with_state_hook( &mut self, block: &RecoveredBlock<::Block>, state_hook: F, ) -> Result::Receipt>, Self::Error> where F: OnStateHook + 'static, { match self { Self::Left(a) => a.execute_one_with_state_hook(block, state_hook), Self::Right(b) => b.execute_one_with_state_hook(block, state_hook), } } fn execute( self, block: &RecoveredBlock<::Block>, ) -> Result::Receipt>, Self::Error> { match self { Self::Left(a) => a.execute(block), Self::Right(b) => b.execute(block), } } fn execute_with_state_closure( self, block: &RecoveredBlock<::Block>, state: F, ) -> Result::Receipt>, Self::Error> where F: FnMut(&revm::database::State), { match self { Self::Left(a) => a.execute_with_state_closure(block, state), Self::Right(b) => b.execute_with_state_closure(block, state), } } fn into_state(self) -> revm::database::State { match self { Self::Left(a) => a.into_state(), Self::Right(b) => b.into_state(), } } fn size_hint(&self) -> usize { match self { Self::Left(a) => a.size_hint(), Self::Right(b) => b.size_hint(), } } }