1use crate::{execute::Executor, Database, OnStateHook};
4
5pub use futures_util::future::Either;
7use reth_execution_types::{BlockExecutionOutput, BlockExecutionResult};
8use reth_primitives_traits::{NodePrimitives, RecoveredBlock};
9
10impl<A, B, DB> Executor<DB> for Either<A, B>
11where
12 A: Executor<DB>,
13 B: Executor<DB, Primitives = A::Primitives, Error = A::Error>,
14 DB: Database,
15{
16 type Primitives = A::Primitives;
17 type Error = A::Error;
18
19 fn execute_one(
20 &mut self,
21 block: &RecoveredBlock<<Self::Primitives as NodePrimitives>::Block>,
22 ) -> Result<BlockExecutionResult<<Self::Primitives as NodePrimitives>::Receipt>, Self::Error>
23 {
24 match self {
25 Self::Left(a) => a.execute_one(block),
26 Self::Right(b) => b.execute_one(block),
27 }
28 }
29
30 fn execute_one_with_state_hook<F>(
31 &mut self,
32 block: &RecoveredBlock<<Self::Primitives as NodePrimitives>::Block>,
33 state_hook: F,
34 ) -> Result<BlockExecutionResult<<Self::Primitives as NodePrimitives>::Receipt>, Self::Error>
35 where
36 F: OnStateHook + 'static,
37 {
38 match self {
39 Self::Left(a) => a.execute_one_with_state_hook(block, state_hook),
40 Self::Right(b) => b.execute_one_with_state_hook(block, state_hook),
41 }
42 }
43
44 fn execute(
45 self,
46 block: &RecoveredBlock<<Self::Primitives as NodePrimitives>::Block>,
47 ) -> Result<BlockExecutionOutput<<Self::Primitives as NodePrimitives>::Receipt>, Self::Error>
48 {
49 match self {
50 Self::Left(a) => a.execute(block),
51 Self::Right(b) => b.execute(block),
52 }
53 }
54
55 fn execute_with_state_closure<F>(
56 self,
57 block: &RecoveredBlock<<Self::Primitives as NodePrimitives>::Block>,
58 state: F,
59 ) -> Result<BlockExecutionOutput<<Self::Primitives as NodePrimitives>::Receipt>, Self::Error>
60 where
61 F: FnMut(&revm::database::State<DB>),
62 {
63 match self {
64 Self::Left(a) => a.execute_with_state_closure(block, state),
65 Self::Right(b) => b.execute_with_state_closure(block, state),
66 }
67 }
68
69 fn into_state(self) -> revm::database::State<DB> {
70 match self {
71 Self::Left(a) => a.into_state(),
72 Self::Right(b) => b.into_state(),
73 }
74 }
75
76 fn size_hint(&self) -> usize {
77 match self {
78 Self::Left(a) => a.size_hint(),
79 Self::Right(b) => b.size_hint(),
80 }
81 }
82}