1
- use std:: fmt:: Debug ;
1
+ use std:: { f32 :: consts :: E , fmt:: Debug } ;
2
2
3
3
use crate :: { Block , BundleDriver , DriveBundleResult } ;
4
4
use alloy_consensus:: TxEnvelope ;
5
5
use alloy_eips:: BlockNumberOrTag ;
6
6
use alloy_primitives:: U256 ;
7
7
use alloy_rlp:: Decodable ;
8
8
use alloy_rpc_types_mev:: EthCallBundle ;
9
- use revm:: primitives:: EVMError ;
9
+ use revm:: primitives:: { EVMError , ExecutionResult } ;
10
10
use thiserror:: Error ;
11
11
12
12
#[ derive( Debug , Clone , Error ) ]
13
13
enum BundleError < Db : revm:: Database > {
14
14
#[ error( "revm block number must match the bundle block number" ) ]
15
- BlockNumberMimatch ,
16
- #[ error( "Internal EVM Error" ) ]
15
+ BlockNumberMismatch ,
16
+ #[ error( "bundle reverted" ) ]
17
+ BundleReverted ,
18
+ #[ error( "transaction decoding error" ) ]
19
+ TransactionDecodingError ( #[ from] alloy_rlp:: Error ) ,
20
+ #[ error( "internal EVM Error" ) ]
17
21
EVMError { inner : EVMError < Db :: Error > } ,
18
22
}
19
23
@@ -71,7 +75,7 @@ impl<Ext> BundleDriver<Ext> for EthCallBundle {
71
75
) -> DriveBundleResult < ' a , Ext , Db , Self > {
72
76
// 1. Check if the block we're in is valid for this bundle. Both must match
73
77
if trevm. inner ( ) . block ( ) . number . to ( ) != self . block_number {
74
- return Err ( trevm. errored ( BundleError :: BlockNumberMimatch ) ) ;
78
+ return Err ( trevm. errored ( BundleError :: BlockNumberMismatch ) ) ;
75
79
}
76
80
77
81
let bundle_filler = BundleBlockFiller :: from ( self . clone ( ) ) ;
@@ -81,16 +85,31 @@ impl<Ext> BundleDriver<Ext> for EthCallBundle {
81
85
let mut trevm = trevm;
82
86
83
87
for raw_tx in self . txs . into_iter ( ) {
84
- let tx = TxEnvelope :: decode ( & mut raw_tx. to_vec ( ) . as_slice ( ) ) . unwrap ( ) ;
88
+ let tx = TxEnvelope :: decode ( & mut raw_tx. to_vec ( ) . as_slice ( ) ) ;
89
+
90
+ let tx = match tx {
91
+ Ok ( tx) => tx,
92
+ Err ( e) => return trevm. errored ( BundleError :: TransactionDecodingError ( e) ) ,
93
+ } ;
94
+
85
95
let run_result = trevm. run_tx ( & tx) ;
86
96
87
97
match run_result {
88
98
// return immediately if errored
89
- Err ( e) => return e ,
90
- // Accept the state, and move on
91
- Ok ( res ) => {
92
- trevm = res . accept_state ( ) ;
99
+ Err ( e) => {
100
+ return trevm . errored ( BundleError :: EVMError {
101
+ inner : EVMError :: Database ( e . error ( ) ) ,
102
+ } )
93
103
}
104
+ // Accept the state, and move on
105
+ Ok ( res) => match res. result ( ) {
106
+ ExecutionResult :: Revert { .. } | ExecutionResult :: Halt { .. } => {
107
+ return trevm. errored ( BundleError :: BundleReverted ) ;
108
+ }
109
+ ExecutionResult :: Success { .. } => {
110
+ trevm = res. accept_state ( ) ;
111
+ }
112
+ } ,
94
113
}
95
114
}
96
115
0 commit comments