Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/paradigmxyz/reth into krane…
Browse files Browse the repository at this point in the history
…/remove-op-feature
  • Loading branch information
0xkrane committed Sep 23, 2024
2 parents 1c5b321 + 89b6ad2 commit f4d751f
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 398 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

7 changes: 4 additions & 3 deletions bin/reth-bench/src/bench/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ impl BenchContext {
let mut benchmark_mode = BenchMode::new(bench_args.from, bench_args.to)?;

// construct the authenticated provider
let auth_jwt = bench_args.auth_jwtsecret.clone().ok_or_else(|| {
eyre::eyre!("--auth-jwtsecret must be provided for authenticated RPC")
})?;
let auth_jwt = bench_args
.auth_jwtsecret
.clone()
.ok_or_else(|| eyre::eyre!("--jwtsecret must be provided for authenticated RPC"))?;

// fetch jwt from file
//
Expand Down
12 changes: 12 additions & 0 deletions crates/engine/invalid-block-hooks/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use reth_revm::{
database::StateProviderDatabase,
db::states::bundle_state::BundleRetention,
primitives::{BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg},
state_change::post_block_balance_increments,
DatabaseCommit, StateBuilder,
};
use reth_rpc_api::DebugApiClient;
Expand Down Expand Up @@ -114,6 +115,17 @@ where

drop(evm);

// use U256::MAX here for difficulty, because fetching it is annoying
// NOTE: This is not mut because we are not doing the DAO irregular state change here
let balance_increments = post_block_balance_increments(
self.provider.chain_spec().as_ref(),
&block.block.clone().unseal(),
U256::MAX,
);

// increment balances
db.increment_balances(balance_increments)?;

// Merge all state transitions
db.merge_transitions(BundleRetention::Reverts);

Expand Down
4 changes: 0 additions & 4 deletions crates/node/builder/src/builder/add_ons.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Node add-ons. Depend on core [`NodeComponents`](crate::NodeComponents).

use std::marker::PhantomData;

use reth_node_api::{EthApiTypes, FullNodeComponents, NodeAddOns};

use crate::{exex::BoxedLaunchExEx, hooks::NodeHooks, rpc::RpcHooks};
Expand All @@ -22,8 +20,6 @@ pub struct AddOns<Node: FullNodeComponents, AddOns: NodeAddOns<Node>> {
/// required for launching the node, such as RPC.
#[derive(Default)]
pub struct RpcAddOns<Node: FullNodeComponents, EthApi: EthApiTypes> {
/// Core `eth` API type to install on the RPC server, configured w.r.t. network.
pub _eth_api: PhantomData<EthApi>,
/// Additional RPC hooks.
pub hooks: RpcHooks<Node, EthApi>,
}
6 changes: 3 additions & 3 deletions crates/node/builder/src/builder/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! The node builder process is essentially a state machine that transitions through various states
//! before the node can be launched.

use std::{fmt, future::Future, marker::PhantomData};
use std::{fmt, future::Future};

use reth_exex::ExExContext;
use reth_node_api::{
Expand Down Expand Up @@ -56,7 +56,7 @@ impl<T: FullNodeTypes> NodeBuilderWithTypes<T> {
components_builder,
add_ons: AddOns {
hooks: NodeHooks::default(),
rpc: RpcAddOns { _eth_api: PhantomData::<()>, hooks: RpcHooks::default() },
rpc: RpcAddOns { hooks: RpcHooks::default() },
exexs: Vec::new(),
},
}
Expand Down Expand Up @@ -180,7 +180,7 @@ where
components_builder,
add_ons: AddOns {
hooks: NodeHooks::default(),
rpc: RpcAddOns { _eth_api: PhantomData::<AO::EthApi>, hooks: RpcHooks::default() },
rpc: RpcAddOns { hooks: RpcHooks::default() },
exexs: Vec::new(),
},
}
Expand Down
3 changes: 1 addition & 2 deletions crates/trie/parallel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ thiserror.workspace = true
derive_more.workspace = true

# `async` feature
reth-tasks = { workspace = true, optional = true }
tokio = { workspace = true, optional = true, default-features = false }
itertools = { workspace = true, optional = true }

Expand Down Expand Up @@ -61,7 +60,7 @@ proptest-arbitrary-interop.workspace = true
[features]
default = ["metrics", "async", "parallel"]
metrics = ["reth-metrics", "dep:metrics", "reth-trie/metrics"]
async = ["reth-tasks/rayon", "tokio/sync", "itertools"]
async = ["tokio/sync", "itertools"]
parallel = ["rayon"]

[[bench]]
Expand Down
11 changes: 1 addition & 10 deletions crates/trie/parallel/benches/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ use alloy_primitives::{B256, U256};
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use proptest::{prelude::*, strategy::ValueTree, test_runner::TestRunner};
use proptest_arbitrary_interop::arb;
use rayon::ThreadPoolBuilder;
use reth_primitives::Account;
use reth_provider::{
providers::ConsistentDbView, test_utils::create_test_provider_factory, StateChangeWriter,
TrieWriter,
};
use reth_tasks::pool::BlockingTaskPool;
use reth_trie::{
hashed_cursor::HashedPostStateCursorFactory, HashedPostState, HashedStorage, StateRoot,
TrieInput,
Expand All @@ -23,7 +21,6 @@ pub fn calculate_state_root(c: &mut Criterion) {
group.sample_size(20);

let runtime = tokio::runtime::Runtime::new().unwrap();
let blocking_pool = BlockingTaskPool::new(ThreadPoolBuilder::default().build().unwrap());

for size in [1_000, 3_000, 5_000, 10_000] {
let (db_state, updated_state) = generate_test_data(size);
Expand Down Expand Up @@ -77,13 +74,7 @@ pub fn calculate_state_root(c: &mut Criterion) {
// async root
group.bench_function(BenchmarkId::new("async root", size), |b| {
b.to_async(&runtime).iter_with_setup(
|| {
AsyncStateRoot::new(
view.clone(),
blocking_pool.clone(),
TrieInput::from_state(updated_state.clone()),
)
},
|| AsyncStateRoot::new(view.clone(), TrieInput::from_state(updated_state.clone())),
|calculator| calculator.incremental_root(),
);
});
Expand Down
51 changes: 19 additions & 32 deletions crates/trie/parallel/src/async_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use reth_execution_errors::StorageRootError;
use reth_provider::{
providers::ConsistentDbView, BlockReader, DBProvider, DatabaseProviderFactory, ProviderError,
};
use reth_tasks::pool::BlockingTaskPool;
use reth_trie::{
hashed_cursor::{HashedCursorFactory, HashedPostStateCursorFactory},
node_iter::{TrieElement, TrieNodeIter},
Expand All @@ -20,6 +19,7 @@ use reth_trie::{
use reth_trie_db::{DatabaseHashedCursorFactory, DatabaseTrieCursorFactory};
use std::{collections::HashMap, sync::Arc};
use thiserror::Error;
use tokio::sync::oneshot;
use tracing::*;

/// Async state root calculator.
Expand All @@ -39,8 +39,6 @@ use tracing::*;
pub struct AsyncStateRoot<Factory> {
/// Consistent view of the database.
view: ConsistentDbView<Factory>,
/// Blocking task pool.
blocking_pool: BlockingTaskPool,
/// Trie input.
input: TrieInput,
/// Parallel state root metrics.
Expand All @@ -50,14 +48,9 @@ pub struct AsyncStateRoot<Factory> {

impl<Factory> AsyncStateRoot<Factory> {
/// Create new async state root calculator.
pub fn new(
view: ConsistentDbView<Factory>,
blocking_pool: BlockingTaskPool,
input: TrieInput,
) -> Self {
pub fn new(view: ConsistentDbView<Factory>, input: TrieInput) -> Self {
Self {
view,
blocking_pool,
input,
#[cfg(feature = "metrics")]
metrics: ParallelStateRootMetrics::default(),
Expand Down Expand Up @@ -106,8 +99,11 @@ where
let trie_nodes_sorted = trie_nodes_sorted.clone();
#[cfg(feature = "metrics")]
let metrics = self.metrics.storage_trie.clone();
let handle =
self.blocking_pool.spawn_fifo(move || -> Result<_, AsyncStateRootError> {

let (tx, rx) = oneshot::channel();

rayon::spawn_fifo(move || {
let result = (|| -> Result<_, AsyncStateRootError> {
let provider_ro = view.provider_ro()?;
let trie_cursor_factory = InMemoryTrieCursorFactory::new(
DatabaseTrieCursorFactory::new(provider_ro.tx_ref()),
Expand All @@ -126,8 +122,10 @@ where
)
.with_prefix_set(prefix_set)
.calculate(retain_updates)?)
});
storage_roots.insert(hashed_address, handle);
})();
let _ = tx.send(result);
});
storage_roots.insert(hashed_address, rx);
}

trace!(target: "trie::async_state_root", "calculating state root");
Expand Down Expand Up @@ -242,15 +240,12 @@ mod tests {
use super::*;
use alloy_primitives::{keccak256, Address, U256};
use rand::Rng;
use rayon::ThreadPoolBuilder;
use reth_primitives::{Account, StorageEntry};
use reth_provider::{test_utils::create_test_provider_factory, HashingWriter};
use reth_trie::{test_utils, HashedPostState, HashedStorage};

#[tokio::test]
async fn random_async_root() {
let blocking_pool = BlockingTaskPool::new(ThreadPoolBuilder::default().build().unwrap());

let factory = create_test_provider_factory();
let consistent_view = ConsistentDbView::new(factory.clone(), None);

Expand Down Expand Up @@ -295,14 +290,10 @@ mod tests {
}

assert_eq!(
AsyncStateRoot::new(
consistent_view.clone(),
blocking_pool.clone(),
Default::default(),
)
.incremental_root()
.await
.unwrap(),
AsyncStateRoot::new(consistent_view.clone(), Default::default(),)
.incremental_root()
.await
.unwrap(),
test_utils::state_root(state.clone())
);

Expand Down Expand Up @@ -332,14 +323,10 @@ mod tests {
}

assert_eq!(
AsyncStateRoot::new(
consistent_view.clone(),
blocking_pool.clone(),
TrieInput::from_state(hashed_state)
)
.incremental_root()
.await
.unwrap(),
AsyncStateRoot::new(consistent_view.clone(), TrieInput::from_state(hashed_state))
.incremental_root()
.await
.unwrap(),
test_utils::state_root(state)
);
}
Expand Down
Loading

0 comments on commit f4d751f

Please sign in to comment.