diff --git a/src/driver/alloy.rs b/src/driver/alloy.rs index ddf8011..fde13b2 100644 --- a/src/driver/alloy.rs +++ b/src/driver/alloy.rs @@ -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}, @@ -299,10 +299,10 @@ impl BundleDriver for BundleProcessor BundleDriver for BundleProcessor BundleDriver for BundleProcessor BundleDriver for BundleProcessor { 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; @@ -573,7 +573,7 @@ impl BundleDriver 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())) @@ -669,7 +669,7 @@ impl BundleDriver 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())) diff --git a/src/evm.rs b/src/evm.rs index 484d213..5df3919 100644 --- a/src/evm.rs +++ b/src/evm.rs @@ -1138,9 +1138,9 @@ impl<'a, Ext, Db: Database + TryStateAcc> EvmNeedsBlock<'a, Ext, Db> { ) -> Result::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) } @@ -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) @@ -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)); } @@ -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. @@ -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() })) } diff --git a/src/lib.rs b/src/lib.rs index 1b6fe9a..9f9d2af 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -336,7 +336,7 @@ //! //! [`EVMError`]: revm::primitives::EVMError //! [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 diff --git a/src/macros.rs b/src/macros.rs index 7135e38..27506fc 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -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 { @@ -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 {