Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #98 from anton-rs/rkrasiuk/perf-address-parsing
Browse files Browse the repository at this point in the history
perf(executor): pre-parse address constants
  • Loading branch information
refcell committed Aug 28, 2023
2 parents 3798be1 + a84ea91 commit 6b110d9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
4 changes: 2 additions & 2 deletions crates/payload/basic/src/optimism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,15 @@ where
&mut db,
&mut post_state,
parent_block.number + 1,
executor::optimism::l1_cost_recipient(),
*executor::optimism::L1_FEE_RECIPIENT,
l1_cost,
)?
}
executor::increment_account_balance(
&mut db,
&mut post_state,
parent_block.number + 1,
executor::optimism::base_fee_recipient(),
*executor::optimism::BASE_FEE_RECIPIENT,
U256::from(base_fee.saturating_mul(result.gas_used())),
)?;
}
Expand Down
3 changes: 3 additions & 0 deletions crates/revm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ revm.workspace = true
# common
tracing.workspace = true

once_cell = { version = "1.17.0", optional = true }

[dev-dependencies]
reth-rlp.workspace = true
once_cell = "1.17.0"
Expand All @@ -33,5 +35,6 @@ optimism = [
"reth-revm-primitives/optimism",
"reth-consensus-common/optimism",
"reth-interfaces/optimism",
"once_cell"
]

4 changes: 2 additions & 2 deletions crates/revm/src/optimism/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,14 @@ where
if let Some(l1_cost) = l1_cost {
self.increment_account_balance(
block.number,
super::l1_cost_recipient(),
*super::L1_FEE_RECIPIENT,
l1_cost,
&mut post_state,
)?
}
self.increment_account_balance(
block.number,
super::base_fee_recipient(),
*super::BASE_FEE_RECIPIENT,
U256::from(
block
.base_fee_per_gas
Expand Down
41 changes: 21 additions & 20 deletions crates/revm/src/optimism/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
use std::{ops::Mul, str::FromStr, sync::Arc};

pub mod executor;

use once_cell::sync::Lazy;
use reth_interfaces::executor as reth_executor;
use reth_primitives::{Address, Block, Bytes, ChainSpec, Hardfork, TransactionKind, U256};
use std::{ops::Mul, str::FromStr, sync::Arc};

const L1_FEE_RECIPIENT: &str = "0x420000000000000000000000000000000000001A";
const BASE_FEE_RECIPIENT: &str = "0x4200000000000000000000000000000000000019";
const L1_BLOCK_CONTRACT: &str = "0x4200000000000000000000000000000000000015";
pub mod executor;

const ZERO_BYTE_COST: u64 = 4;
const NON_ZERO_BYTE_COST: u64 = 16;

/// The address of L1 fee recipient.
pub static L1_FEE_RECIPIENT: Lazy<Address> = Lazy::new(|| {
Address::from_str("0x420000000000000000000000000000000000001A")
.expect("failed to parse l1 fee recipient address")
});

/// The address of the base fee recipient.
pub static BASE_FEE_RECIPIENT: Lazy<Address> = Lazy::new(|| {
Address::from_str("0x4200000000000000000000000000000000000019")
.expect("failed to parse base fee recipient address")
});

static L1_BLOCK_CONTRACT: Lazy<Address> = Lazy::new(|| {
Address::from_str("0x4200000000000000000000000000000000000015")
.expect("failed to parse l1 block contract address")
});

/// L1 block info
///
/// We can extract L1 epoch data from each L2 block, by looking at the `setL1BlockValues`
Expand All @@ -37,12 +50,10 @@ impl TryFrom<&Block> for L1BlockInfo {
type Error = reth_executor::BlockExecutionError;

fn try_from(block: &Block) -> Result<Self, Self::Error> {
let l1_block_contract = Address::from_str(L1_BLOCK_CONTRACT).unwrap();

let l1_info_tx_data = block
.body
.iter()
.find(|tx| matches!(tx.kind(), TransactionKind::Call(to) if to == &l1_block_contract))
.find(|tx| matches!(tx.kind(), TransactionKind::Call(to) if to == &*L1_BLOCK_CONTRACT))
.ok_or(reth_executor::BlockExecutionError::L1BlockInfoError {
message: "could not find l1 block info tx in the L2 block".to_string(),
})
Expand Down Expand Up @@ -138,16 +149,6 @@ impl L1BlockInfo {
}
}

/// Get the base fee recipient address
pub fn base_fee_recipient() -> Address {
Address::from_str(BASE_FEE_RECIPIENT).unwrap()
}

/// Get the L1 cost recipient address
pub fn l1_cost_recipient() -> Address {
Address::from_str(L1_FEE_RECIPIENT).unwrap()
}

#[cfg(test)]
mod test_l1_fee {
#[cfg(feature = "optimism")]
Expand Down

0 comments on commit 6b110d9

Please sign in to comment.