Skip to content

Commit 05fac0a

Browse files
committed
chore: respect reverts/halts, handle tx decoding errors
1 parent 2da6ae9 commit 05fac0a

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

src/driver/alloy.rs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
use std::fmt::Debug;
1+
use std::{f32::consts::E, fmt::Debug};
22

33
use crate::{Block, BundleDriver, DriveBundleResult};
44
use alloy_consensus::TxEnvelope;
55
use alloy_eips::BlockNumberOrTag;
66
use alloy_primitives::U256;
77
use alloy_rlp::Decodable;
88
use alloy_rpc_types_mev::EthCallBundle;
9-
use revm::primitives::EVMError;
9+
use revm::primitives::{EVMError, ExecutionResult};
1010
use thiserror::Error;
1111

1212
#[derive(Debug, Clone, Error)]
1313
enum BundleError<Db: revm::Database> {
1414
#[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")]
1721
EVMError { inner: EVMError<Db::Error> },
1822
}
1923

@@ -71,7 +75,7 @@ impl<Ext> BundleDriver<Ext> for EthCallBundle {
7175
) -> DriveBundleResult<'a, Ext, Db, Self> {
7276
// 1. Check if the block we're in is valid for this bundle. Both must match
7377
if trevm.inner().block().number.to() != self.block_number {
74-
return Err(trevm.errored(BundleError::BlockNumberMimatch));
78+
return Err(trevm.errored(BundleError::BlockNumberMismatch));
7579
}
7680

7781
let bundle_filler = BundleBlockFiller::from(self.clone());
@@ -81,16 +85,31 @@ impl<Ext> BundleDriver<Ext> for EthCallBundle {
8185
let mut trevm = trevm;
8286

8387
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+
8595
let run_result = trevm.run_tx(&tx);
8696

8797
match run_result {
8898
// 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+
})
93103
}
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+
},
94113
}
95114
}
96115

0 commit comments

Comments
 (0)