Skip to content

Commit

Permalink
chore: rename OpHaltReason (#2042)
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr authored Jan 31, 2025
1 parent 62119ca commit 5407d7a
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 28 deletions.
6 changes: 3 additions & 3 deletions crates/optimism/src/api/exec_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ use revm::{
use crate::{
handler::{precompiles::OpPrecompileProvider, OpHandler},
transaction::abstraction::OpTxGetter,
L1BlockInfoGetter, OpSpec, OpTransactionError, OptimismHaltReason,
L1BlockInfoGetter, OpHaltReason, OpSpec, OpTransactionError,
};

/// Helper function that executed a transaction and commits the state.
pub fn transact_op<CTX: EthContext + OpTxGetter + L1BlockInfoGetter>(
ctx: &mut CTX,
) -> Result<
ResultAndState<OptimismHaltReason>,
ResultAndState<OpHaltReason>,
EVMError<<<CTX as DatabaseGetter>::Database as Database>::Error, OpTransactionError>,
>
where
Expand All @@ -37,7 +37,7 @@ where
pub fn transact_op_commit<CTX: EthContext + OpTxGetter + L1BlockInfoGetter>(
ctx: &mut CTX,
) -> Result<
ExecutionResult<OptimismHaltReason>,
ExecutionResult<OpHaltReason>,
EVMError<<<CTX as DatabaseGetter>::Database as Database>::Error, OpTransactionError>,
>
where
Expand Down
9 changes: 3 additions & 6 deletions crates/optimism/src/api/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
context::OpContext,
handler::{precompiles::OpPrecompileProvider, OpHandler},
transaction::{abstraction::OpTxGetter, OpTxTrait},
L1BlockInfoGetter, OpSpec, OpTransactionError, OptimismHaltReason,
L1BlockInfoGetter, OpHaltReason, OpSpec, OpTransactionError,
};
use inspector::{
exec::InspectEvm,
Expand Down Expand Up @@ -83,7 +83,7 @@ impl<

pub fn inspect_op<DB, CTX>(
ctx: &mut CTX,
) -> Result<ResultAndState<OptimismHaltReason>, EVMError<<DB as Database>::Error, OpTransactionError>>
) -> Result<ResultAndState<OpHaltReason>, EVMError<<DB as Database>::Error, OpTransactionError>>
where
DB: Database,
CTX: EthContext
Expand Down Expand Up @@ -119,10 +119,7 @@ where

pub fn inspect_op_commit<DB: Database + DatabaseCommit, CTX>(
ctx: &mut CTX,
) -> Result<
ExecutionResult<OptimismHaltReason>,
EVMError<<DB as Database>::Error, OpTransactionError>,
>
) -> Result<ExecutionResult<OpHaltReason>, EVMError<<DB as Database>::Error, OpTransactionError>>
where
CTX: EthContext
+ OpTxGetter
Expand Down
12 changes: 5 additions & 7 deletions crates/optimism/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{
api::exec_op::transact_op,
transaction::{abstraction::OpTxGetter, OpTxTrait},
L1BlockInfo, L1BlockInfoGetter, OpSpec, OpSpecId, OpTransaction, OpTransactionError,
OptimismHaltReason,
L1BlockInfo, L1BlockInfoGetter, OpHaltReason, OpSpec, OpSpecId, OpTransaction,
OpTransactionError,
};
use derive_more::derive::{AsMut, AsRef, Deref, DerefMut};
use inspector::journal::{JournalExt, JournalExtGetter};
Expand Down Expand Up @@ -240,10 +240,8 @@ where
DB: Database,
JOURNAL: Journal<Database = DB, FinalOutput = (EvmState, Vec<Log>)>,
{
type Output = Result<
ResultAndState<OptimismHaltReason>,
EVMError<<DB as Database>::Error, OpTransactionError>,
>;
type Output =
Result<ResultAndState<OpHaltReason>, EVMError<<DB as Database>::Error, OpTransactionError>>;

fn exec_previous(&mut self) -> Self::Output {
transact_op(self)
Expand All @@ -259,7 +257,7 @@ where
JOURNAL: Journal<Database = DB, FinalOutput = (EvmState, Vec<Log>)>,
{
type CommitOutput = Result<
ExecutionResult<OptimismHaltReason>,
ExecutionResult<OpHaltReason>,
EVMError<<DB as Database>::Error, OpTransactionError>,
>;

Expand Down
8 changes: 4 additions & 4 deletions crates/optimism/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
deposit::{DepositTransaction, DEPOSIT_TRANSACTION_TYPE},
OpTransactionError, OpTxTrait,
},
L1BlockInfoGetter, OpSpec, OpSpecId, OptimismHaltReason, BASE_FEE_RECIPIENT, L1_FEE_RECIPIENT,
L1BlockInfoGetter, OpHaltReason, OpSpec, OpSpecId, BASE_FEE_RECIPIENT, L1_FEE_RECIPIENT,
};
use precompiles::OpPrecompileProvider;
use revm::{
Expand Down Expand Up @@ -89,7 +89,7 @@ where
type Frame = FRAME;
type Precompiles = OpPrecompileProvider<CTX, ERROR>;
type Instructions = INSTRUCTIONS;
type HaltReason = OptimismHaltReason;
type HaltReason = OpHaltReason;

fn precompile(&self, _context: &mut Self::Context) -> Self::Precompiles {
OpPrecompileProvider::default()
Expand Down Expand Up @@ -310,7 +310,7 @@ where
result: <Self::Frame as Frame>::FrameResult,
) -> Result<ResultAndState<Self::HaltReason>, Self::Error> {
let result = self.main.output(context, result)?;
let result = result.map_haltreason(OptimismHaltReason::Base);
let result = result.map_haltreason(OpHaltReason::Base);
if result.result.is_halt() {
// Post-regolith, if the transaction is a deposit transaction and it halts,
// we bubble up to the global return handler. The mint value will be persisted
Expand Down Expand Up @@ -378,7 +378,7 @@ where

Ok(ResultAndState {
result: ExecutionResult::Halt {
reason: OptimismHaltReason::FailedDeposit,
reason: OpHaltReason::FailedDeposit,
gas_used,
},
state,
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ pub mod transaction;
pub use l1block::{
L1BlockInfo, L1BlockInfoGetter, BASE_FEE_RECIPIENT, L1_BLOCK_CONTRACT, L1_FEE_RECIPIENT,
};
pub use result::OptimismHaltReason;
pub use result::OpHaltReason;
pub use spec::*;
pub use transaction::{error::OpTransactionError, estimate_tx_compressed_size, OpTransaction};
4 changes: 2 additions & 2 deletions crates/optimism/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use revm::context_interface::result::HaltReason;

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum OptimismHaltReason {
pub enum OpHaltReason {
Base(HaltReason),
FailedDeposit,
}

impl From<HaltReason> for OptimismHaltReason {
impl From<HaltReason> for OpHaltReason {
fn from(value: HaltReason) -> Self {
Self::Base(value)
}
Expand Down
10 changes: 5 additions & 5 deletions crates/optimism/src/transaction/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@ pub enum OpTransactionError {
/// was deprecated in the Regolith hardfork, and this error is thrown if a `Deposit` transaction
/// is found with this field set to `true` after the hardfork activation.
///
/// In addition, this error is internal, and bubbles up into a [OptimismHaltReason::FailedDeposit][crate::OptimismHaltReason::FailedDeposit] error
/// In addition, this error is internal, and bubbles up into a [OpHaltReason::FailedDeposit][crate::OpHaltReason::FailedDeposit] error
/// in the `revm` handler for the consumer to easily handle. This is due to a state transition
/// rule on OP Stack chains where, if for any reason a deposit transaction fails, the transaction
/// must still be included in the block, the sender nonce is bumped, the `mint` value persists, and
/// special gas accounting rules are applied. Normally on L1, [EVMError::Transaction] errors
/// are cause for non-inclusion, so a special [OptimismHaltReason][crate::OptimismHaltReason] variant was introduced to handle this
/// are cause for non-inclusion, so a special [OpHaltReason][crate::OpHaltReason] variant was introduced to handle this
/// case for failed deposit transactions.
DepositSystemTxPostRegolith,
/// Deposit transaction haults bubble up to the global main return handler, wiping state and
/// only increasing the nonce + persisting the mint value.
///
/// This is a catch-all error for any deposit transaction that is results in a [OptimismHaltReason][crate::OptimismHaltReason] error
/// This is a catch-all error for any deposit transaction that is results in a [OpHaltReason][crate::OpHaltReason] error
/// post-regolith hardfork. This allows for a consumer to easily handle special cases where
/// a deposit transaction fails during validation, but must still be included in the block.
///
/// In addition, this error is internal, and bubbles up into a [OptimismHaltReason::FailedDeposit][crate::OptimismHaltReason::FailedDeposit] error
/// In addition, this error is internal, and bubbles up into a [OpHaltReason::FailedDeposit][crate::OpHaltReason::FailedDeposit] error
/// in the `revm` handler for the consumer to easily handle. This is due to a state transition
/// rule on OP Stack chains where, if for any reason a deposit transaction fails, the transaction
/// must still be included in the block, the sender nonce is bumped, the `mint` value persists, and
/// special gas accounting rules are applied. Normally on L1, [EVMError::Transaction] errors
/// are cause for non-inclusion, so a special [OptimismHaltReason][crate::OptimismHaltReason] variant was introduced to handle this
/// are cause for non-inclusion, so a special [OpHaltReason][crate::OpHaltReason] variant was introduced to handle this
/// case for failed deposit transactions.
HaltedDepositPostRegolith,
}
Expand Down

0 comments on commit 5407d7a

Please sign in to comment.