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
1 change: 1 addition & 0 deletions 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/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2582,8 +2582,8 @@ pub enum BlockStatus {

/// How a payload was inserted if it was valid.
///
/// If the payload was valid, but has already been seen, [`InsertPayloadOk::AlreadySeen(_)`] is
/// returned, otherwise [`InsertPayloadOk::Inserted(_)`] is returned.
/// If the payload was valid, but has already been seen, [`InsertPayloadOk::AlreadySeen`] is
/// returned, otherwise [`InsertPayloadOk::Inserted`] is returned.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum InsertPayloadOk {
/// The payload was valid, but we have already seen it.
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/evm/src/either.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ where
state: F,
) -> Result<BlockExecutionOutput<<Self::Primitives as NodePrimitives>::Receipt>, Self::Error>
where
F: FnMut(&revm::database::State<DB>),
F: FnMut(&mut revm::database::State<DB>),
{
match self {
Self::Left(a) => a.execute_with_state_closure(block, state),
Expand Down
4 changes: 2 additions & 2 deletions crates/evm/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ pub trait Executor<DB: Database>: Sized {
mut f: F,
) -> Result<BlockExecutionOutput<<Self::Primitives as NodePrimitives>::Receipt>, Self::Error>
where
F: FnMut(&State<DB>),
F: FnMut(&mut State<DB>),
{
let result = self.execute_one(block)?;
let mut state = self.into_state();
f(&state);
f(&mut state);
Ok(BlockExecutionOutput { state: state.take_bundle(), result })
}

Expand Down
2 changes: 1 addition & 1 deletion crates/net/downloaders/src/bodies/bodies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ where
/// Max requests to handle at the same time
///
/// This depends on the number of active peers but will always be
/// [`min_concurrent_requests`..`max_concurrent_requests`]
/// `min_concurrent_requests..max_concurrent_requests`
#[inline]
fn concurrent_request_limit(&self) -> usize {
let num_peers = self.client.num_connected_peers();
Expand Down
2 changes: 1 addition & 1 deletion crates/net/downloaders/src/headers/reverse_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ where
/// Max requests to handle at the same time
///
/// This depends on the number of active peers but will always be
/// [`min_concurrent_requests`..`max_concurrent_requests`]
/// `min_concurrent_requests..max_concurrent_requests`
#[inline]
fn concurrent_request_limit(&self) -> usize {
let num_peers = self.client.num_connected_peers();
Expand Down
6 changes: 3 additions & 3 deletions crates/net/network/src/test_utils/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,9 +788,9 @@ impl NetworkEventStream {
peers
}

/// Ensures that the first two events are a [`NetworkEvent::Peer(PeerEvent::PeerAdded`] and
/// [`NetworkEvent::ActivePeerSession`], returning the [`PeerId`] of the established
/// session.
/// Ensures that the first two events are a [`NetworkEvent::Peer`] and
/// [`PeerEvent::PeerAdded`][`NetworkEvent::ActivePeerSession`], returning the [`PeerId`] of the
/// established session.
pub async fn peer_added_and_established(&mut self) -> Option<PeerId> {
let peer_id = match self.inner.next().await {
Some(NetworkEvent::Peer(PeerEvent::PeerAdded(peer_id))) => peer_id,
Expand Down
4 changes: 2 additions & 2 deletions crates/node/core/src/args/pruning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ pub struct PruningArgs {
pub receipts_before: Option<BlockNumber>,
// Receipts Log Filter
/// Configure receipts log filter. Format:
/// <`address`>:<`prune_mode`>[,<`address`>:<`prune_mode`>...] Where <`prune_mode`> can be
/// 'full', 'distance:<`blocks`>', or 'before:<`block_number`>'
/// <`address`>:<`prune_mode`>... where <`prune_mode`> can be 'full', 'distance:<`blocks`>', or
/// 'before:<`block_number`>'
#[arg(long = "prune.receiptslogfilter", value_name = "FILTER_CONFIG", conflicts_with_all = &["receipts_full", "receipts_pre_merge", "receipts_distance", "receipts_before"], value_parser = parse_receipts_log_filter)]
pub receipts_log_filter: Option<ReceiptsLogPruneConfig>,

Expand Down
6 changes: 3 additions & 3 deletions crates/prune/types/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ impl PruneModes {
/// left in database after the pruning.
///
/// 1. For [`PruneMode::Full`], it fails if `MIN_BLOCKS > 0`.
/// 2. For [`PruneMode::Distance(distance`)], it fails if `distance < MIN_BLOCKS + 1`. `+ 1` is
/// needed because `PruneMode::Distance(0)` means that we leave zero blocks from the latest,
/// meaning we have one block in the database.
/// 2. For [`PruneMode::Distance`], it fails if `distance < MIN_BLOCKS + 1`. `+ 1` is needed because
/// `PruneMode::Distance(0)` means that we leave zero blocks from the latest, meaning we have one
/// block in the database.
#[cfg(any(test, feature = "serde"))]
fn deserialize_opt_prune_mode_with_min_blocks<
'de,
Expand Down
2 changes: 1 addition & 1 deletion crates/ress/provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ where
// invalid blocks.
if let Err(error) = self.evm_config.batch_executor(&mut db).execute_with_state_closure(
&block,
|state: &State<_>| {
|state: &mut State<_>| {
record.record_executed_state(state);
},
) {
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-e2e-tests/src/rpc_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct RpcTestCase {
/// Action that runs RPC compatibility tests from execution-apis test data
#[derive(Debug)]
pub struct RunRpcCompatTests {
/// RPC methods to test (e.g., ["`eth_getLogs`"])
/// RPC methods to test (e.g. `eth_getLogs`)
pub methods: Vec<String>,
/// Path to the execution-apis tests directory
pub test_data_path: String,
Expand Down
4 changes: 4 additions & 0 deletions crates/rpc/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ alloy-serde.workspace = true
revm = { workspace = true, features = ["optional_block_gas_limit", "optional_eip3607", "optional_no_base_fee"] }
revm-primitives = { workspace = true, features = ["serde"] }

# scroll
reth-scroll-evm = { workspace = true, optional = true }

# rpc
jsonrpsee.workspace = true
http.workspace = true
Expand Down Expand Up @@ -104,3 +107,4 @@ jsonrpsee = { workspace = true, features = ["client"] }

[features]
js-tracer = ["revm-inspectors/js-tracer", "reth-rpc-eth-types/js-tracer"]
scroll = ["reth-scroll-evm"]
9 changes: 8 additions & 1 deletion crates/rpc/rpc/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,11 +640,18 @@ where

let mut witness_record = ExecutionWitnessRecord::default();

let mut withdraw_root_res: Result<_, reth_errors::ProviderError> = Ok(());
let _ = block_executor
.execute_with_state_closure(&(*block).clone(), |statedb: &State<_>| {
.execute_with_state_closure(&(*block).clone(), |statedb: &mut State<_>| {
#[cfg(feature = "scroll")]
{
use reth_scroll_evm::LoadWithdrawRoot;
withdraw_root_res = statedb.load_withdraw_root();
}
witness_record.record_executed_state(statedb);
})
.map_err(|err| EthApiError::Internal(err.into()))?;
withdraw_root_res?;

let ExecutionWitnessRecord { hashed_state, codes, keys, lowest_block_number } =
witness_record;
Expand Down
2 changes: 1 addition & 1 deletion crates/scroll/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ thiserror.workspace = true
tracing.workspace = true

[dev-dependencies]
alloy-primitives = { workspace = true, features = ["getrandom"] }
alloy-primitives = { workspace = true, features = ["getrandom", "rand"] }
eyre.workspace = true

[features]
Expand Down
3 changes: 3 additions & 0 deletions crates/scroll/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ pub use base_fee::{
mod receipt;
pub use receipt::ScrollRethReceiptBuilder;

mod withdraw_root;
pub use withdraw_root::LoadWithdrawRoot;

use crate::build::ScrollBlockAssembler;
use alloc::sync::Arc;

Expand Down
99 changes: 99 additions & 0 deletions crates/scroll/evm/src/withdraw_root.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
use alloy_primitives::{address, Address, U256};
use revm::{database::State, Database};

const L2_MESSAGE_QUEUE_ADDRESS: Address = address!("0x5300000000000000000000000000000000000000");
const WITHDRAW_TRIE_ROOT_SLOT: U256 = U256::ZERO;

/// Instance that implements the trait can load the `L2MessageQueue` withdraw root in state.
pub trait LoadWithdrawRoot<DB: Database> {
/// Load the withdrawal root.
fn load_withdraw_root(&mut self) -> Result<(), DB::Error>;
}

impl<DB: Database> LoadWithdrawRoot<DB> for State<DB> {
fn load_withdraw_root(&mut self) -> Result<(), DB::Error> {
// we load the account in cache and query the storage slot. The storage slot will only be
// loaded from database if it is not already know.
self.load_cache_account(L2_MESSAGE_QUEUE_ADDRESS)?;
let _ = revm::Database::storage(self, L2_MESSAGE_QUEUE_ADDRESS, WITHDRAW_TRIE_ROOT_SLOT);

Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;
use std::{collections::HashMap, convert::Infallible};

use alloy_primitives::B256;
use revm::{bytecode::Bytecode, state::AccountInfo};
use revm_primitives::{StorageKey, StorageValue};

#[derive(Default)]
struct InMemoryDb {
pub accounts: HashMap<Address, AccountInfo>,
pub storage: HashMap<(Address, U256), U256>,
}

impl Database for InMemoryDb {
type Error = Infallible;

fn basic(&mut self, address: Address) -> Result<Option<AccountInfo>, Self::Error> {
Ok(self.accounts.get(&address).cloned())
}

fn code_by_hash(&mut self, _code_hash: B256) -> Result<Bytecode, Self::Error> {
Ok(Default::default())
}

fn storage(
&mut self,
address: Address,
index: StorageKey,
) -> Result<StorageValue, Self::Error> {
Ok(self.storage.get(&(address, index)).copied().unwrap_or_default())
}

fn block_hash(&mut self, _number: u64) -> Result<B256, Self::Error> {
Ok(Default::default())
}
}

#[test]
fn test_should_load_withdraw_root() -> eyre::Result<()> {
// init db
let mut db = InMemoryDb::default();

// load L2 message queue contract
let withdraw_root = U256::random();
db.accounts.insert(L2_MESSAGE_QUEUE_ADDRESS, Default::default());
db.storage.insert((L2_MESSAGE_QUEUE_ADDRESS, U256::ZERO), withdraw_root);

let mut state =
State::builder().with_database(db).with_bundle_update().without_state_clear().build();

assert!(state
.cache
.accounts
.get(&L2_MESSAGE_QUEUE_ADDRESS)
.map(|acc| acc.storage_slot(WITHDRAW_TRIE_ROOT_SLOT))
.is_none());

// load root
state.load_withdraw_root()?;

assert_eq!(
state
.cache
.accounts
.get(&L2_MESSAGE_QUEUE_ADDRESS)
.unwrap()
.storage_slot(WITHDRAW_TRIE_ROOT_SLOT)
.unwrap(),
withdraw_root
);

Ok(())
}
}
2 changes: 1 addition & 1 deletion crates/scroll/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ reth-rpc-eth-api = { workspace = true, features = ["scroll"] }
reth-rpc-eth-types.workspace = true
reth-tasks = { workspace = true, features = ["rayon"] }
reth-transaction-pool.workspace = true
reth-rpc.workspace = true
reth-rpc = { workspace = true, features = ["scroll"] }
reth-rpc-convert = { workspace = true, features = ["scroll"] }
reth-node-api.workspace = true
reth-node-builder.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/storage/db/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! MDBX implementation for reth's database abstraction layer.
//!
//! This crate is an implementation of [`reth-db-api`] for MDBX, as well as a few other common
//! This crate is an implementation of `reth-db-api` for MDBX, as well as a few other common
//! database types.
//!
//! # Overview
Expand Down
2 changes: 1 addition & 1 deletion crates/trie/db/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! An integration of [`reth-trie`] with [`reth-db`].
//! An integration of `reth-trie` with `reth-db`.

#![cfg_attr(not(test), warn(unused_crate_dependencies))]

Expand Down
2 changes: 1 addition & 1 deletion docs/vocs/docs/pages/cli/reth/node.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ Pruning:
Prune receipts before the specified block number. The specified block number is not pruned

--prune.receiptslogfilter <FILTER_CONFIG>
Configure receipts log filter. Format: <`address`>:<`prune_mode`>[,<`address`>:<`prune_mode`>...] Where <`prune_mode`> can be 'full', 'distance:<`blocks`>', or 'before:<`block_number`>'
Configure receipts log filter. Format: <`address`>:<`prune_mode`>... where <`prune_mode`> can be 'full', 'distance:<`blocks`>', or 'before:<`block_number`>'

--prune.accounthistory.full
Prunes all account history
Expand Down
2 changes: 1 addition & 1 deletion testing/ef-tests/src/cases/blockchain_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ fn run_case(case: &BlockchainTest) -> Result<(), Error> {
let executor = executor_provider.batch_executor(state_db);

let output = executor
.execute_with_state_closure(&(*block).clone(), |statedb: &State<_>| {
.execute_with_state_closure(&(*block).clone(), |statedb: &mut State<_>| {
witness_record.record_executed_state(statedb);
})
.map_err(|err| Error::block_failed(block_number, err))?;
Expand Down