Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/driver/alloy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
system::{MAX_BLOB_GAS_PER_BLOCK_CANCUN, MAX_BLOB_GAS_PER_BLOCK_PRAGUE},
trevm_bail, trevm_ensure, unwrap_or_trevm_err, Block, BundleDriver, DriveBundleResult,
trevm_bail, trevm_ensure, trevm_try, Block, BundleDriver, DriveBundleResult,
};
use alloy::{
consensus::{Transaction, TxEip4844Variant, TxEnvelope},
Expand Down Expand Up @@ -299,10 +299,10 @@ impl<Ext> BundleDriver<Ext> for BundleProcessor<EthCallBundle, EthCallBundleResp
let mut trevm = trevm;

// Decode and validate the transactions in the bundle
let txs = unwrap_or_trevm_err!(Self::decode_and_validate_txs(&self.bundle.txs), trevm);
let txs = trevm_try!(Self::decode_and_validate_txs(&self.bundle.txs), trevm);

// Cache the pre simulation coinbase balance, so we can use it to calculate the coinbase diff after every tx simulated.
let initial_coinbase_balance = unwrap_or_trevm_err!(
let initial_coinbase_balance = trevm_try!(
trevm.try_read_balance(trevm.inner().block().coinbase).map_err(|e| {
BundleError::EVMError { inner: revm::primitives::EVMError::Database(e) }
}),
Expand Down Expand Up @@ -332,7 +332,7 @@ impl<Ext> BundleDriver<Ext> for BundleProcessor<EthCallBundle, EthCallBundleResp
let basefee = committed_trevm.inner().block().basefee;

// Get the post simulation coinbase balance
let post_sim_coinbase_balance = unwrap_or_trevm_err!(
let post_sim_coinbase_balance = trevm_try!(
committed_trevm.try_read_balance(coinbase).map_err(|e| {
BundleError::EVMError {
inner: revm::primitives::EVMError::Database(e),
Expand All @@ -342,7 +342,7 @@ impl<Ext> BundleDriver<Ext> for BundleProcessor<EthCallBundle, EthCallBundleResp
);

// Process the transaction and accumulate the results
let (response, post_sim_coinbase_balance) = unwrap_or_trevm_err!(
let (response, post_sim_coinbase_balance) = trevm_try!(
Self::process_call_bundle_tx(
tx,
pre_sim_coinbase_balance,
Expand Down Expand Up @@ -437,7 +437,7 @@ impl<Ext> BundleDriver<Ext> for BundleProcessor<EthSendBundle, EthBundleHash> {
trevm_ensure!(!self.bundle.txs.is_empty(), trevm, BundleError::BundleEmpty);

// Decode and validate the transactions in the bundle
let txs = unwrap_or_trevm_err!(Self::decode_and_validate_txs(&self.bundle.txs), trevm);
let txs = trevm_try!(Self::decode_and_validate_txs(&self.bundle.txs), trevm);

// Store the current evm state in this mutable variable, so we can continually use the freshest state for each simulation
let mut t = trevm;
Expand Down Expand Up @@ -573,7 +573,7 @@ impl<Ext> BundleDriver<Ext> for EthCallBundle {
let run_result = trevm.try_with_block(&bundle_filler, |trevm| {
let mut trevm = trevm;

let txs = unwrap_or_trevm_err!(
let txs = trevm_try!(
self.txs
.iter()
.map(|tx| TxEnvelope::decode_2718(&mut tx.chunk()))
Expand Down Expand Up @@ -669,7 +669,7 @@ impl<Ext> BundleDriver<Ext> for EthSendBundle {
// Check if the bundle has any transactions
trevm_ensure!(!self.txs.is_empty(), trevm, BundleError::BundleEmpty);

let txs = unwrap_or_trevm_err!(
let txs = trevm_try!(
self.txs
.iter()
.map(|tx| TxEnvelope::decode_2718(&mut tx.chunk()))
Expand Down
15 changes: 6 additions & 9 deletions src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1138,9 +1138,9 @@ impl<'a, Ext, Db: Database + TryStateAcc> EvmNeedsBlock<'a, Ext, Db> {
) -> Result<BundleState, EvmErrored<'a, Ext, Db, <Db as TryStateAcc>::Error>> {
let db = self.inner.db_mut();

unwrap_or_trevm_err!(db.try_merge_transitions(BundleRetention::Reverts), self);
trevm_try!(db.try_merge_transitions(BundleRetention::Reverts), self);

let bundle = unwrap_or_trevm_err!(db.try_take_bundle(), self);
let bundle = trevm_try!(db.try_take_bundle(), self);

Ok(bundle)
}
Expand Down Expand Up @@ -1490,7 +1490,7 @@ impl<'a, Ext, Db: Database + TryStateAcc> EvmNeedsTx<'a, Ext, Db> {
overrides.fill_block(&mut self.inner);

if let Some(hashes) = overrides.block_hash.as_ref() {
unwrap_or_trevm_err!(self.inner.db_mut().try_set_block_hashes(hashes), self);
trevm_try!(self.inner.db_mut().try_set_block_hashes(hashes), self);
}

Ok(self)
Expand Down Expand Up @@ -1707,7 +1707,7 @@ impl<'a, Ext, Db: Database> EvmReady<'a, Ext, Db> {
) -> Result<(crate::EstimationResult, Self), EvmErrored<'a, Ext, Db>> {
use tracing::{debug, enabled};

if let Some(est) = crate::unwrap_or_trevm_err!(self.estimate_gas_simple_transfer(), self) {
if let Some(est) = crate::trevm_try!(self.estimate_gas_simple_transfer(), self) {
return Ok((crate::EstimationResult::basic_transfer_success(est), self));
}

Expand All @@ -1731,7 +1731,7 @@ impl<'a, Ext, Db: Database> EvmReady<'a, Ext, Db> {
let _e = span.enter();

// Cap the gas limit to the caller's allowance and block limit
unwrap_or_trevm_err!(self.cap_tx_gas(), self);
trevm_try!(self.cap_tx_gas(), self);
search_range.maybe_lower_max(self.gas_limit());

// Raise the floor to the amount of gas required to initialize the EVM.
Expand Down Expand Up @@ -2005,10 +2005,7 @@ impl<'a, Ext, Db: Database> EvmTransacted<'a, Ext, Db> {
{
let Trevm { mut inner, state: TransactedState { result } } = self;

unwrap_or_trevm_err!(
inner.db_mut().try_commit(result.state),
Trevm { inner, state: NeedsTx::new() }
);
trevm_try!(inner.db_mut().try_commit(result.state), Trevm { inner, state: NeedsTx::new() });
Ok((result.result, Trevm { inner, state: NeedsTx::new() }))
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
//!
//! [`EVMError<Db>`]: revm::primitives::EVMError<Db>
//! [typestate pattern]: https://cliffle.com/blog/rust-typestate/
//! [crate readme]: https://github.com/init4tt/trevm
//! [crate readme]: https://github.com/init4tech/trevm
//! [EIP-2537]: https://eips.ethereum.org/EIPS/eip-2537
//! [EIP-2935]: https://eips.ethereum.org/EIPS/eip-2935
//! [EIP-4788]: https://eips.ethereum.org/EIPS/eip-4788
Expand Down
12 changes: 12 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// Unwraps a Result, returning the value if successful, or returning an errored `Trevm` if not.
#[macro_export]
#[deprecated = "Please use `trevm_tri!` instead"]
macro_rules! unwrap_or_trevm_err {
($e:expr, $trevm:expr) => {
match $e {
Expand All @@ -9,6 +10,17 @@ macro_rules! unwrap_or_trevm_err {
};
}

/// Unwraps a Result, returning the value if successful, or returning an errored `Trevm` if not.
#[macro_export]
macro_rules! trevm_try {
($e:expr, $trevm:expr) => {
match $e {
Ok(val) => val,
Err(e) => return Err($trevm.errored(e.into())),
}
};
}

/// Executes a condition, returning an errored `Trevm` if not successful.
#[macro_export]
macro_rules! trevm_ensure {
Expand Down
Loading