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
26 changes: 11 additions & 15 deletions crates/optimism/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,25 @@ where

fn validate_tx_against_state(&self, evm: &mut Self::Evm) -> Result<(), Self::Error> {
let context = evm.ctx();
let spec = context.cfg().spec();
let block_number = context.block().number();
if context.tx().tx_type() == DEPOSIT_TRANSACTION_TYPE {
return Ok(());
} else {
// The L1-cost fee is only computed for Optimism non-deposit transactions.
if context.chain().l2_block != block_number {
// L1 block info is stored in the context for later use.
// and it will be reloaded from the database if it is not for the current block.
*context.chain() = L1BlockInfo::try_fetch(context.db(), block_number, spec)?;
}
}
let spec = context.cfg().spec();

let enveloped_tx = context
.tx()
.enveloped_tx()
.expect("all not deposit tx have enveloped tx")
.clone();

// compute L1 cost
let mut additional_cost = context.chain().calculate_tx_l1_cost(&enveloped_tx, spec);

Expand All @@ -130,20 +140,6 @@ where
Ok(())
}

fn load_accounts(&self, evm: &mut Self::Evm) -> Result<(), Self::Error> {
// The L1-cost fee is only computed for Optimism non-deposit transactions.
let spec = evm.ctx().cfg().spec();
if evm.ctx().tx().tx_type() != DEPOSIT_TRANSACTION_TYPE {
let l1_block_info: crate::L1BlockInfo =
super::L1BlockInfo::try_fetch(evm.ctx().db(), spec)?;

// Storage L1 block info for later use.
*evm.ctx().chain() = l1_block_info;
}

self.mainnet.load_accounts(evm)
}

fn deduct_caller(&self, evm: &mut Self::Evm) -> Result<(), Self::Error> {
let ctx = evm.ctx();
let spec = ctx.cfg().spec();
Expand Down
5 changes: 5 additions & 0 deletions crates/optimism/src/l1block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ use revm::{
/// For now, we only care about the fields necessary for L1 cost calculation.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct L1BlockInfo {
/// The L2 block number. If not same as the one in the context,
/// L1BlockInfo is not valid and will be reloaded from the database.
pub l2_block: u64,
/// The base fee of the L1 origin block.
pub l1_base_fee: U256,
/// The current L1 fee overhead. None if Ecotone is activated.
Expand All @@ -52,6 +55,7 @@ impl L1BlockInfo {
/// Try to fetch the L1 block info from the database.
pub fn try_fetch<DB: Database>(
db: &mut DB,
l2_block: u64,
spec_id: OpSpecId,
) -> Result<L1BlockInfo, DB::Error> {
// Ensure the L1 Block account is loaded into the cache after Ecotone. With EIP-4788, it is no longer the case
Expand Down Expand Up @@ -116,6 +120,7 @@ impl L1BlockInfo {
.as_ref(),
);
Ok(L1BlockInfo {
l2_block,
l1_base_fee,
l1_base_fee_scalar,
l1_blob_base_fee: Some(l1_blob_base_fee),
Expand Down
Loading