Skip to content

Commit

Permalink
Merge pull request #22 from anton-rs/refcell/optional-envelope
Browse files Browse the repository at this point in the history
fix: Update the enveloped tx to be optional
  • Loading branch information
refcell authored Sep 8, 2023
2 parents ad2c951 + 2962e7a commit bd03c2f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
5 changes: 4 additions & 1 deletion crates/primitives/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ pub struct OptimismFields {
/// to compute the L1 tx cost using the L1 block info, as
/// opposed to requiring downstream apps to compute the cost
/// externally.
pub enveloped_tx: Bytes,
/// This field is optional to allow the [TxEnv] to be constructed
/// for non-optimism chains when the `optimism` feature is enabled,
/// but the [CfgEnv] `optimism` field is set to false.
pub enveloped_tx: Option<Bytes>,
}

#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down
19 changes: 13 additions & 6 deletions crates/revm/src/evm_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,14 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> Transact<DB::Error>

// Perform this calculation optimistically to avoid cloning the enveloped tx.
let tx_l1_cost = l1_block_info.as_ref().map(|l1_block_info| {
l1_block_info
.calculate_tx_l1_cost::<GSPEC>(&env.tx.optimism.enveloped_tx, is_deposit)
env.tx
.optimism
.enveloped_tx
.as_ref()
.map(|enveloped_tx| {
l1_block_info.calculate_tx_l1_cost::<GSPEC>(enveloped_tx, is_deposit)
})
.unwrap_or(U256::ZERO)
});

(
Expand Down Expand Up @@ -503,10 +509,11 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB,
panic!("[OPTIMISM] Failed to load L1 block information.");
};

let l1_cost = l1_block_info.calculate_tx_l1_cost::<SPEC>(
&self.data.env.tx.optimism.enveloped_tx,
is_deposit,
);
let Some(enveloped_tx) = &self.data.env.tx.optimism.enveloped_tx else {
panic!("[OPTIMISM] Failed to load enveloped transaction.");
};

let l1_cost = l1_block_info.calculate_tx_l1_cost::<SPEC>(enveloped_tx, is_deposit);

// Send the L1 cost of the transaction to the L1 Fee Vault.
let Ok((l1_fee_vault_account, _)) = self
Expand Down

0 comments on commit bd03c2f

Please sign in to comment.