11use crate :: {
22 trevm_bail, trevm_ensure, unwrap_or_trevm_err, Block , BundleDriver , DriveBundleResult ,
33} ;
4+ use alloc:: vec:: Vec ;
45use alloy:: {
56 consensus:: { Transaction , TxEip4844Variant , TxEnvelope } ,
67 eips:: { eip2718:: Decodable2718 , BlockNumberOrTag } ,
@@ -11,51 +12,82 @@ use alloy::{
1112} ;
1213use alloy_primitives:: { bytes:: Buf , keccak256, Address , Bytes , TxKind , U256 } ;
1314use revm:: primitives:: { EVMError , ExecutionResult , MAX_BLOB_GAS_PER_BLOCK } ;
14- use thiserror:: Error ;
1515
1616/// Possible errors that can occur while driving a bundle.
17- #[ derive( Error ) ]
1817pub enum BundleError < Db : revm:: Database > {
1918 /// The block number of the bundle does not match the block number of the revm block configuration.
20- #[ error( "revm block number must match the bundle block number" ) ]
2119 BlockNumberMismatch ,
2220 /// The timestamp of the bundle is out of range.
23- #[ error( "timestamp out of range" ) ]
2421 TimestampOutOfRange ,
2522 /// The bundle was reverted (or halted).
26- #[ error( "bundle reverted" ) ]
2723 BundleReverted ,
2824 /// The bundle has no transactions
29- #[ error( "bundle has no transactions" ) ]
3025 BundleEmpty ,
3126 /// Too many blob transactions
32- #[ error( "max blob gas limit exceeded" ) ]
3327 Eip4844BlobGasExceeded ,
3428 /// An unsupported transaction type was encountered.
35- #[ error( "unsupported transaction type" ) ]
3629 UnsupportedTransactionType ,
3730 /// An error occurred while decoding a transaction contained in the bundle.
38- #[ error( "transaction decoding error" ) ]
39- TransactionDecodingError ( #[ from] alloy:: eips:: eip2718:: Eip2718Error ) ,
40- /// An error ocurred while recovering the sender of a transaction
41- #[ error( "transaction sender recovery error" ) ]
42- TransactionSenderRecoveryError ( #[ from] alloy_primitives:: SignatureError ) ,
31+ TransactionDecodingError ( alloy:: eips:: eip2718:: Eip2718Error ) ,
32+ /// An error occurred while recovering the sender of a transaction.
33+ TransactionSenderRecoveryError ( alloy_primitives:: SignatureError ) ,
4334 /// An error occurred while running the EVM.
44- #[ error( "internal EVM Error" ) ]
4535 EVMError {
4636 /// The error that occurred while running the EVM.
4737 inner : EVMError < Db :: Error > ,
4838 } ,
4939}
5040
41+ impl < Db : revm:: Database > core:: fmt:: Display for BundleError < Db > {
42+ fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
43+ match self {
44+ Self :: BlockNumberMismatch => {
45+ write ! ( f, "revm block number must match the bundle block number" )
46+ }
47+ Self :: TimestampOutOfRange => write ! ( f, "timestamp out of range" ) ,
48+ Self :: BundleReverted => write ! ( f, "bundle reverted" ) ,
49+ Self :: BundleEmpty => write ! ( f, "bundle has no transactions" ) ,
50+ Self :: Eip4844BlobGasExceeded => write ! ( f, "max blob gas limit exceeded" ) ,
51+ Self :: UnsupportedTransactionType => write ! ( f, "unsupported transaction type" ) ,
52+ Self :: TransactionDecodingError ( _) => write ! ( f, "transaction decoding error" ) ,
53+ Self :: TransactionSenderRecoveryError ( _) => {
54+ write ! ( f, "transaction sender recovery error" )
55+ }
56+ Self :: EVMError { inner : _ } => write ! ( f, "internal EVM Error" ) ,
57+ }
58+ }
59+ }
60+
61+ impl < Db : revm:: Database > From < alloy:: eips:: eip2718:: Eip2718Error > for BundleError < Db > {
62+ fn from ( err : alloy:: eips:: eip2718:: Eip2718Error ) -> Self {
63+ Self :: TransactionDecodingError ( err)
64+ }
65+ }
66+
67+ impl < Db : revm:: Database > From < alloy_primitives:: SignatureError > for BundleError < Db > {
68+ fn from ( err : alloy_primitives:: SignatureError ) -> Self {
69+ Self :: TransactionSenderRecoveryError ( err)
70+ }
71+ }
72+
5173impl < Db : revm:: Database > From < EVMError < Db :: Error > > for BundleError < Db > {
5274 fn from ( inner : EVMError < Db :: Error > ) -> Self {
5375 Self :: EVMError { inner }
5476 }
5577}
5678
57- impl < Db : revm:: Database > std:: fmt:: Debug for BundleError < Db > {
58- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
79+ impl < Db : revm:: Database > core:: error:: Error for BundleError < Db > {
80+ fn source ( & self ) -> Option < & ( dyn core:: error:: Error + ' static ) > {
81+ match self {
82+ Self :: TransactionDecodingError ( err) => Some ( err) ,
83+ Self :: TransactionSenderRecoveryError ( err) => Some ( err) ,
84+ _ => None ,
85+ }
86+ }
87+ }
88+
89+ impl < Db : revm:: Database > core:: fmt:: Debug for BundleError < Db > {
90+ fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
5991 match self {
6092 Self :: TimestampOutOfRange => write ! ( f, "TimestampOutOfRange" ) ,
6193 Self :: BlockNumberMismatch => write ! ( f, "BlockNumberMismatch" ) ,
94126 /// Clear the driver, resetting the response. This resets the driver,
95127 /// allowing for resimulation of the same bundle.
96128 pub fn clear ( & mut self ) -> R {
97- std :: mem:: take ( & mut self . response )
129+ core :: mem:: take ( & mut self . response )
98130 }
99131}
100132
0 commit comments