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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Perf

### 2025-11-12

- Cache `BLOBBASEFEE` opcode value [#5288](https://github.com/lambdaclass/ethrex/pull/5288)

### 2025-11-11

- Insert instead of merge for bloom rebuilds [#5223](https://github.com/lambdaclass/ethrex/pull/5223)
Expand All @@ -17,6 +21,7 @@
- Reuse stack pool in LEVM [#5179](https://github.com/lambdaclass/ethrex/pull/5179)

### 2025-11-05

- Merkelization backpressure and batching [#5200](https://github.com/lambdaclass/ethrex/pull/5200)

### 2025-11-03
Expand Down
11 changes: 9 additions & 2 deletions crates/vm/levm/src/opcode_handlers/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,15 @@ impl<'a> VM<'a> {
self.current_call_frame
.increase_consumed_gas(gas_cost::BLOBBASEFEE)?;

let blob_base_fee =
get_base_fee_per_blob_gas(self.env.block_excess_blob_gas, &self.env.config)?;
let blob_base_fee = match self.blob_base_fee.get() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is this not a bit clearer if we use OnceCell::get_or_init?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not work because it can't handle errors. The get_or_try_init method is nightly-only.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not as much a nit, is needing the blob_base_fee uncommon enough to not just init it with the block, rather than using a OnceCell?
Besides, we already have a &mut self here, so we could just use an option in any case.

Some(value) => *value,
None => {
let value =
get_base_fee_per_blob_gas(self.env.block_excess_blob_gas, &self.env.config)?;
_ = self.blob_base_fee.set(value);
value
}
};

self.current_call_frame.stack.push1(blob_base_fee)?;

Expand Down
6 changes: 5 additions & 1 deletion crates/vm/levm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use ethrex_common::{
types::{AccessListEntry, Code, Fork, Log, Transaction, fee_config::FeeConfig},
};
use std::{
cell::RefCell,
cell::{OnceCell, RefCell},
collections::{BTreeMap, BTreeSet, HashMap, HashSet},
mem,
rc::Rc,
Expand Down Expand Up @@ -323,9 +323,12 @@ pub struct VM<'a> {
/// A pool of stacks to avoid reallocating too much when creating new call frames.
pub stack_pool: Vec<Stack>,
pub vm_type: VMType,

/// The opcode table mapping opcodes to opcode handlers for fast lookup.
/// Build dynamically according to the given fork config.
pub(crate) opcode_table: [OpCodeFn<'a>; 256],
/// Cached `BLOBBASEFEE` value.
pub(crate) blob_base_fee: OnceCell<U256>,
}

impl<'a> VM<'a> {
Expand Down Expand Up @@ -375,6 +378,7 @@ impl<'a> VM<'a> {
),
env,
opcode_table: VM::build_opcode_table(fork),
blob_base_fee: OnceCell::new(),
};

let call_type = if is_create {
Expand Down
Loading