Skip to content
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### 2025-10-28

- Use RocksDB-specific backend for the VM [#5073](https://github.com/lambdaclass/ethrex/pull/5073)
- Batch BlobsBundle::validate [#4993](https://github.com/lambdaclass/ethrex/pull/4993)

### 2025-10-27
Expand Down
76 changes: 54 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 16 additions & 5 deletions crates/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pub mod mempool;
pub mod payload;
mod smoke_test;
pub mod tracing;
pub mod vm;

use ::tracing::{debug, info};
use constants::{MAX_INITCODE_SIZE, MAX_TRANSACTION_DATA_SIZE, POST_OSAKA_GAS_LIMIT_CAP};
Expand All @@ -26,6 +25,7 @@ use ethrex_common::types::{Fork, MempoolTransaction};
use ethrex_common::{Address, H256, TrieLogger};
use ethrex_metrics::metrics;
use ethrex_rlp::encode::RLPEncode;
use ethrex_storage::trie_db::generic_vm::StoreVmDatabase;
use ethrex_storage::{
AccountUpdatesList, Store, UpdateBatch, error::StoreError, hash_address, hash_key,
};
Expand All @@ -40,8 +40,6 @@ use std::time::Instant;
use tokio::sync::Mutex as TokioMutex;
use tokio_util::sync::CancellationToken;

use vm::StoreVmDatabase;

#[cfg(feature = "metrics")]
use ethrex_metrics::metrics_blocks::METRICS_BLOCKS;

Expand Down Expand Up @@ -155,8 +153,7 @@ impl Blockchain {
// Validate the block pre-execution
validate_block(block, &parent_header, &chain_config, ELASTICITY_MULTIPLIER)?;

let vm_db = StoreVmDatabase::new(self.storage.clone(), block.header.parent_hash);
let mut vm = self.new_evm(vm_db)?;
let mut vm = self.new_evm_from_db(self.storage.vm_db(parent_header)?)?;

let execution_result = vm.execute_block(block)?;
let account_updates = vm.get_state_transitions()?;
Expand Down Expand Up @@ -1020,6 +1017,20 @@ impl Blockchain {
new_evm(&self.options.r#type, vm_db)
}

pub fn new_evm_from_db(&self, vm_db: DynVmDatabase) -> Result<Evm, EvmError> {
let evm = match &self.options.r#type {
BlockchainType::L1 => Evm::new_for_l1_boxed(vm_db),
BlockchainType::L2(l2_config) => {
let fee_config = *l2_config
.fee_config
.read()
.map_err(|_| EvmError::Custom("Fee config lock was poisoned".to_string()))?;
Evm::new_for_l2_boxed(vm_db, fee_config)?
}
};
Ok(evm)
}

/// Get the current fork of the chain, based on the latest block's timestamp
pub async fn current_fork(&self) -> Result<Fork, StoreError> {
let chain_config = self.storage.get_chain_config();
Expand Down
3 changes: 1 addition & 2 deletions crates/blockchain/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use ethrex_common::{
use ethrex_vm::{Evm, EvmError};

use ethrex_rlp::encode::RLPEncode;
use ethrex_storage::{Store, error::StoreError};
use ethrex_storage::{Store, error::StoreError, trie_db::generic_vm::StoreVmDatabase};

use sha3::{Digest, Keccak256};

Expand All @@ -39,7 +39,6 @@ use crate::{
error::{ChainError, InvalidBlockError},
mempool::PendingTxFilter,
new_evm,
vm::StoreVmDatabase,
};

use thiserror::Error;
Expand Down
4 changes: 2 additions & 2 deletions crates/blockchain/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use std::{
};

use ethrex_common::{H256, tracing::CallTrace, types::Block};
use ethrex_storage::Store;
use ethrex_storage::{Store, trie_db::generic_vm::StoreVmDatabase};
use ethrex_vm::{Evm, EvmError};

use crate::{Blockchain, error::ChainError, vm::StoreVmDatabase};
use crate::{Blockchain, error::ChainError};

impl Blockchain {
/// Outputs the call trace for the given transaction
Expand Down
3 changes: 2 additions & 1 deletion crates/l2/based/block_fetcher.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{cmp::min, collections::HashMap, sync::Arc, time::Duration};

use ethrex_blockchain::{Blockchain, fork_choice::apply_fork_choice, vm::StoreVmDatabase};
use ethrex_blockchain::{Blockchain, fork_choice::apply_fork_choice};
use ethrex_common::utils::keccak;
use ethrex_common::{
Address, H160, H256, U256,
Expand All @@ -17,6 +17,7 @@ use ethrex_l2_sdk::{get_last_committed_batch, get_last_fetched_l1_block};
use ethrex_rlp::decode::RLPDecode;
use ethrex_rpc::{EthClient, types::receipt::RpcLog};
use ethrex_storage::Store;
use ethrex_storage::trie_db::generic_vm::StoreVmDatabase;
use ethrex_storage_rollup::{RollupStoreError, StoreRollup};
use spawned_concurrency::{
error::GenServerError,
Expand Down
2 changes: 2 additions & 0 deletions crates/l2/prover/src/guest_program/src/risc0/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/l2/prover/src/guest_program/src/sp1/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/l2/sequencer/l1_committer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
};

use bytes::Bytes;
use ethrex_blockchain::{Blockchain, vm::StoreVmDatabase};
use ethrex_blockchain::Blockchain;
use ethrex_common::{
Address, H256, U256,
types::{
Expand Down Expand Up @@ -43,7 +43,7 @@ use ethrex_rpc::{
types::block_identifier::{BlockIdentifier, BlockTag},
};
use ethrex_storage::EngineType;
use ethrex_storage::Store;
use ethrex_storage::{Store, trie_db::generic_vm::StoreVmDatabase};
use ethrex_storage_rollup::StoreRollup;
use ethrex_vm::{BlockExecutionResult, Evm};
use rand::Rng;
Expand Down
7 changes: 4 additions & 3 deletions crates/networking/rpc/eth/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
},
utils::RpcErr,
};
use ethrex_blockchain::{Blockchain, vm::StoreVmDatabase};
use ethrex_blockchain::Blockchain;
use ethrex_common::{
H256, U256,
types::{AccessListEntry, BlockHash, BlockHeader, BlockNumber, GenericTransaction, TxKind},
Expand All @@ -23,6 +23,7 @@ use serde::Serialize;

use serde_json::Value;
use tracing::debug;
use ethrex_storage::trie_db::generic_vm::StoreVmDatabase;

pub const ESTIMATE_ERROR_RATIO: f64 = 0.015;
pub const CALL_STIPEND: u64 = 2_300; // Free gas given at beginning of call.
Expand Down Expand Up @@ -347,8 +348,8 @@ impl RpcHandler for CreateAccessListRequest {
_ => return Ok(Value::Null),
};

let vm_db = StoreVmDatabase::new(context.storage.clone(), header.hash());
let mut vm = context.blockchain.new_evm(vm_db)?;
let vm_db = context.storage.vm_db(header.clone())?;
let mut vm = context.blockchain.new_evm_from_db(vm_db)?;

// Run transaction and obtain access list
let (gas_used, access_list, error) = vm.create_access_list(&self.transaction, &header)?;
Expand Down
2 changes: 2 additions & 0 deletions crates/storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ documentation.workspace = true
ethrex-rlp.workspace = true
ethrex-common.workspace = true
ethrex-trie.workspace = true
ethrex-vm.workspace = true

async-trait.workspace = true
ethereum-types.workspace = true
Expand All @@ -26,6 +27,7 @@ rocksdb = { workspace = true, optional = true }
rustc-hash.workspace = true
tokio = { workspace = true, optional = true, features = ["rt"] }
bincode = "1.3.3"
rayon.workspace = true

[features]
default = []
Expand Down
5 changes: 5 additions & 0 deletions crates/storage/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use ethrex_common::types::{
Block, BlockBody, BlockHash, BlockHeader, BlockNumber, ChainConfig, Code, Index, Receipt,
Transaction,
};
use ethrex_vm::DynVmDatabase;
use std::path::Path;
use std::{fmt::Debug, panic::RefUnwindSafe};

Expand Down Expand Up @@ -380,4 +381,8 @@ pub trait StoreEngine: Debug + Send + Sync + RefUnwindSafe {
fn generate_flatkeyvalue(&self) -> Result<(), StoreError>;

async fn create_checkpoint(&self, path: &Path) -> Result<(), StoreError>;

fn vm_db(&self, _parent_header: BlockHeader) -> Option<Result<DynVmDatabase, StoreError>> {
None
}
}
2 changes: 1 addition & 1 deletion crates/storage/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod api;
mod rlp;
mod store;
pub mod store_db;
mod trie_db;
pub mod trie_db;
#[cfg(feature = "rocksdb")]
mod utils;

Expand Down
Loading
Loading