Skip to content

Commit 50c3d20

Browse files
chore(engine): Remove ConsistentDbView
1 parent 01820fd commit 50c3d20

File tree

16 files changed

+342
-469
lines changed

16 files changed

+342
-469
lines changed

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/engine/tree/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ reth-prune.workspace = true
3030
reth-revm.workspace = true
3131
reth-stages-api.workspace = true
3232
reth-tasks.workspace = true
33-
reth-trie-db.workspace = true
3433
reth-trie-parallel.workspace = true
3534
reth-trie-sparse = { workspace = true, features = ["std", "metrics"] }
3635
reth-trie-sparse-parallel = { workspace = true, features = ["std"] }
@@ -133,7 +132,6 @@ test-utils = [
133132
"reth-trie/test-utils",
134133
"reth-trie-sparse/test-utils",
135134
"reth-prune-types?/test-utils",
136-
"reth-trie-db/test-utils",
137135
"reth-trie-parallel/test-utils",
138136
"reth-ethereum-primitives/test-utils",
139137
"reth-node-ethereum/test-utils",

crates/engine/tree/benches/state_root_task.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ use reth_evm::OnStateHook;
2020
use reth_evm_ethereum::EthEvmConfig;
2121
use reth_primitives_traits::{Account as RethAccount, Recovered, StorageEntry};
2222
use reth_provider::{
23-
providers::{BlockchainProvider, ConsistentDbView},
23+
providers::{BlockchainProvider, OverlayStateProviderFactory},
2424
test_utils::{create_test_provider_factory_with_chain_spec, MockNodeTypesWithDB},
2525
AccountReader, ChainSpecProvider, HashingWriter, ProviderFactory,
2626
};
27-
use reth_trie::TrieInput;
2827
use revm_primitives::{HashMap, U256};
2928
use revm_state::{Account as RevmAccount, AccountInfo, AccountStatus, EvmState, EvmStorageSlot};
3029
use std::{hint::black_box, sync::Arc};
@@ -238,8 +237,7 @@ fn bench_state_root(c: &mut Criterion) {
238237
>,
239238
>(),
240239
StateProviderBuilder::new(provider.clone(), genesis_hash, None),
241-
ConsistentDbView::new_with_latest_tip(provider).unwrap(),
242-
TrieInput::default(),
240+
OverlayStateProviderFactory::new(provider),
243241
&TreeConfig::default(),
244242
)
245243
.map_err(|(err, ..)| err)

crates/engine/tree/src/tree/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ use reth_payload_primitives::{
2929
};
3030
use reth_primitives_traits::{NodePrimitives, RecoveredBlock, SealedBlock, SealedHeader};
3131
use reth_provider::{
32-
providers::ConsistentDbView, BlockReader, DatabaseProviderFactory, HashedPostStateProvider,
33-
ProviderError, StateProviderBox, StateProviderFactory, StateReader, TransactionVariant,
34-
TrieReader,
32+
BlockReader, DatabaseProviderFactory, HashedPostStateProvider, ProviderError, StateProviderBox,
33+
StateProviderFactory, StateReader, TransactionVariant, TrieReader,
3534
};
3635
use reth_revm::database::StateProviderDatabase;
3736
use reth_stages_api::ControlFlow;

crates/engine/tree/src/tree/payload_processor/mod.rs

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ use reth_evm::{
2525
ConfigureEvm, EvmEnvFor, OnStateHook, SpecFor, TxEnvFor,
2626
};
2727
use reth_primitives_traits::NodePrimitives;
28-
use reth_provider::{
29-
providers::ConsistentDbView, BlockReader, DatabaseProviderFactory, StateProviderFactory,
30-
StateReader,
31-
};
28+
use reth_provider::{BlockReader, DatabaseProviderROFactory, StateProviderFactory, StateReader};
3229
use reth_revm::{db::BundleState, state::EvmState};
33-
use reth_trie::TrieInput;
30+
use reth_trie::{
31+
hashed_cursor::HashedCursorFactory, prefix_set::TriePrefixSetsMut,
32+
trie_cursor::TrieCursorFactory,
33+
};
3434
use reth_trie_parallel::{
3535
proof_task::{ProofTaskCtx, ProofWorkerHandle},
3636
root::ParallelStateRootError,
@@ -94,8 +94,6 @@ where
9494
>,
9595
/// Whether to disable the parallel sparse trie.
9696
disable_parallel_sparse_trie: bool,
97-
/// A cleared trie input, kept around to be reused so allocations can be minimized.
98-
trie_input: Option<TrieInput>,
9997
/// Maximum concurrency for prewarm task.
10098
prewarm_max_concurrency: usize,
10199
}
@@ -122,7 +120,6 @@ where
122120
precompile_cache_disabled: config.precompile_cache_disabled(),
123121
precompile_cache_map,
124122
sparse_state_trie: Arc::default(),
125-
trie_input: None,
126123
disable_parallel_sparse_trie: config.disable_parallel_sparse_trie(),
127124
prewarm_max_concurrency: config.prewarm_max_concurrency(),
128125
}
@@ -167,43 +164,39 @@ where
167164
/// This returns a handle to await the final state root and to interact with the tasks (e.g.
168165
/// canceling)
169166
#[allow(clippy::type_complexity)]
170-
pub fn spawn<P, I: ExecutableTxIterator<Evm>>(
167+
pub fn spawn<P, F, I: ExecutableTxIterator<Evm>>(
171168
&mut self,
172169
env: ExecutionEnv<Evm>,
173170
transactions: I,
174171
provider_builder: StateProviderBuilder<N, P>,
175-
consistent_view: ConsistentDbView<P>,
176-
trie_input: TrieInput,
172+
multiproof_provider_factory: F,
177173
config: &TreeConfig,
178174
) -> Result<
179175
PayloadHandle<WithTxEnv<TxEnvFor<Evm>, I::Tx>, I::Error>,
180176
(ParallelStateRootError, I, ExecutionEnv<Evm>, StateProviderBuilder<N, P>),
181177
>
182178
where
183-
P: DatabaseProviderFactory<Provider: BlockReader>
184-
+ BlockReader
185-
+ StateProviderFactory
186-
+ StateReader
179+
P: BlockReader + StateProviderFactory + StateReader + Clone + 'static,
180+
F: DatabaseProviderROFactory<Provider: TrieCursorFactory + HashedCursorFactory>
187181
+ Clone
182+
+ Send
188183
+ 'static,
189184
{
190185
let (to_sparse_trie, sparse_trie_rx) = channel();
191-
// spawn multiproof task, save the trie input
192-
let (trie_input, state_root_config) = MultiProofConfig::from_input(trie_input);
193-
self.trie_input = Some(trie_input);
186+
187+
// We rely on the cursor factory to provide whatever DB overlay is necessary to see a
188+
// consistent view of the database, including the trie tables. Because of this there is no
189+
// need for an overarching prefix set to invalidate any section of the trie tables, and so
190+
// we use an empty prefix set.
191+
let prefix_sets = Arc::new(TriePrefixSetsMut::default());
194192

195193
// Create and spawn the storage proof task
196-
let task_ctx = ProofTaskCtx::new(
197-
state_root_config.nodes_sorted.clone(),
198-
state_root_config.state_sorted.clone(),
199-
state_root_config.prefix_sets.clone(),
200-
);
194+
let task_ctx = ProofTaskCtx::new(multiproof_provider_factory, prefix_sets);
201195
let storage_worker_count = config.storage_worker_count();
202196
let account_worker_count = config.account_worker_count();
203197
let max_proof_task_concurrency = config.max_proof_task_concurrency() as usize;
204198
let proof_handle = ProofWorkerHandle::new(
205199
self.executor.handle().clone(),
206-
consistent_view,
207200
task_ctx,
208201
storage_worker_count,
209202
account_worker_count,
@@ -213,7 +206,6 @@ where
213206
// spawn one Tokio task for the account proof, and one Tokio task for the storage proof.
214207
let max_multi_proof_task_concurrency = max_proof_task_concurrency / 2;
215208
let multi_proof_task = MultiProofTask::new(
216-
state_root_config,
217209
self.executor.clone(),
218210
proof_handle.clone(),
219211
to_sparse_trie,
@@ -361,11 +353,6 @@ where
361353
CacheTaskHandle { cache, to_prewarm_task: Some(to_prewarm_task), cache_metrics }
362354
}
363355

364-
/// Takes the trie input from the inner payload processor, if it exists.
365-
pub const fn take_trie_input(&mut self) -> Option<TrieInput> {
366-
self.trie_input.take()
367-
}
368-
369356
/// Returns the cache for the given parent hash.
370357
///
371358
/// If the given hash is different then what is recently cached, then this will create a new
@@ -663,12 +650,12 @@ mod tests {
663650
use reth_evm_ethereum::EthEvmConfig;
664651
use reth_primitives_traits::{Account, Recovered, StorageEntry};
665652
use reth_provider::{
666-
providers::{BlockchainProvider, ConsistentDbView},
653+
providers::{BlockchainProvider, OverlayStateProviderFactory},
667654
test_utils::create_test_provider_factory_with_chain_spec,
668655
ChainSpecProvider, HashingWriter,
669656
};
670657
use reth_testing_utils::generators;
671-
use reth_trie::{test_utils::state_root, HashedPostState, TrieInput};
658+
use reth_trie::{test_utils::state_root, HashedPostState};
672659
use revm_primitives::{Address, HashMap, B256, KECCAK_EMPTY, U256};
673660
use revm_state::{AccountInfo, AccountStatus, EvmState, EvmStorageSlot};
674661
use std::sync::Arc;
@@ -850,17 +837,18 @@ mod tests {
850837
&TreeConfig::default(),
851838
PrecompileCacheMap::default(),
852839
);
853-
let provider = BlockchainProvider::new(factory).unwrap();
840+
841+
let provider_factory = BlockchainProvider::new(factory).unwrap();
842+
854843
let mut handle =
855844
payload_processor
856845
.spawn(
857846
Default::default(),
858847
core::iter::empty::<
859848
Result<Recovered<TransactionSigned>, core::convert::Infallible>,
860849
>(),
861-
StateProviderBuilder::new(provider.clone(), genesis_hash, None),
862-
ConsistentDbView::new_with_latest_tip(provider).unwrap(),
863-
TrieInput::from_state(hashed_state),
850+
StateProviderBuilder::new(provider_factory.clone(), genesis_hash, None),
851+
OverlayStateProviderFactory::new(provider_factory),
864852
&TreeConfig::default(),
865853
)
866854
.map_err(|(err, ..)| err)

crates/engine/tree/src/tree/payload_processor/multiproof.rs

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ impl SparseTrieUpdate {
6464
}
6565

6666
/// Common configuration for multi proof tasks
67-
#[derive(Debug, Clone)]
68-
pub(super) struct MultiProofConfig {
67+
#[derive(Debug, Clone, Default)]
68+
pub(crate) struct MultiProofConfig {
6969
/// The sorted collection of cached in-memory intermediate trie nodes that
7070
/// can be reused for computation.
7171
pub nodes_sorted: Arc<TrieUpdatesSorted>,
@@ -82,7 +82,7 @@ impl MultiProofConfig {
8282
///
8383
/// This returns a cleared [`TrieInput`] so that we can reuse any allocated space in the
8484
/// [`TrieInput`].
85-
pub(super) fn from_input(mut input: TrieInput) -> (TrieInput, Self) {
85+
pub(crate) fn from_input(mut input: TrieInput) -> (TrieInput, Self) {
8686
let config = Self {
8787
nodes_sorted: Arc::new(input.nodes.drain_into_sorted()),
8888
state_sorted: Arc::new(input.state.drain_into_sorted()),
@@ -290,7 +290,6 @@ impl From<MultiproofInput> for PendingMultiproofTask {
290290
/// Input parameters for spawning a dedicated storage multiproof calculation.
291291
#[derive(Debug)]
292292
struct StorageMultiproofInput {
293-
config: MultiProofConfig,
294293
source: Option<StateChangeSource>,
295294
hashed_state_update: HashedPostState,
296295
hashed_address: B256,
@@ -313,7 +312,6 @@ impl StorageMultiproofInput {
313312
/// Input parameters for spawning a multiproof calculation.
314313
#[derive(Debug)]
315314
struct MultiproofInput {
316-
config: MultiProofConfig,
317315
source: Option<StateChangeSource>,
318316
hashed_state_update: HashedPostState,
319317
proof_targets: MultiProofTargets,
@@ -437,7 +435,6 @@ impl MultiproofManager {
437435
/// Spawns a single storage proof calculation task.
438436
fn spawn_storage_proof(&mut self, storage_multiproof_input: StorageMultiproofInput) {
439437
let StorageMultiproofInput {
440-
config,
441438
source,
442439
hashed_state_update,
443440
hashed_address,
@@ -462,9 +459,7 @@ impl MultiproofManager {
462459
);
463460
let start = Instant::now();
464461
let proof_result = ParallelProof::new(
465-
config.nodes_sorted,
466-
config.state_sorted,
467-
config.prefix_sets,
462+
Default::default(), // prefix sets
468463
missed_leaves_storage_roots,
469464
storage_proof_worker_handle,
470465
)
@@ -511,7 +506,6 @@ impl MultiproofManager {
511506
/// Spawns a single multiproof calculation task.
512507
fn spawn_multiproof(&mut self, multiproof_input: MultiproofInput) {
513508
let MultiproofInput {
514-
config,
515509
source,
516510
hashed_state_update,
517511
proof_targets,
@@ -540,7 +534,7 @@ impl MultiproofManager {
540534

541535
// Extend prefix sets with targets
542536
let frozen_prefix_sets =
543-
ParallelProof::extend_prefix_sets_with_targets(&config.prefix_sets, &proof_targets);
537+
ParallelProof::extend_prefix_sets_with_targets(&Default::default(), &proof_targets);
544538

545539
// Queue account multiproof to worker pool
546540
let input = AccountMultiproofInput {
@@ -658,8 +652,6 @@ pub(super) struct MultiProofTask {
658652
///
659653
/// If [`None`], then chunking is disabled.
660654
chunk_size: Option<usize>,
661-
/// Task configuration.
662-
config: MultiProofConfig,
663655
/// Receiver for state root related messages.
664656
rx: Receiver<MultiProofMessage>,
665657
/// Sender for state root related messages.
@@ -681,7 +673,6 @@ pub(super) struct MultiProofTask {
681673
impl MultiProofTask {
682674
/// Creates a new multi proof task with the unified message channel
683675
pub(super) fn new(
684-
config: MultiProofConfig,
685676
executor: WorkloadExecutor,
686677
proof_worker_handle: ProofWorkerHandle,
687678
to_sparse_trie: Sender<SparseTrieUpdate>,
@@ -693,7 +684,6 @@ impl MultiProofTask {
693684

694685
Self {
695686
chunk_size,
696-
config,
697687
rx,
698688
tx,
699689
to_sparse_trie,
@@ -742,7 +732,6 @@ impl MultiProofTask {
742732
let mut spawn = |proof_targets| {
743733
self.multiproof_manager.spawn_or_queue(
744734
MultiproofInput {
745-
config: self.config.clone(),
746735
source: None,
747736
hashed_state_update: Default::default(),
748737
proof_targets,
@@ -885,7 +874,6 @@ impl MultiProofTask {
885874

886875
self.multiproof_manager.spawn_or_queue(
887876
MultiproofInput {
888-
config: self.config.clone(),
889877
source: Some(source),
890878
hashed_state_update,
891879
proof_targets,
@@ -1208,30 +1196,27 @@ mod tests {
12081196
use super::*;
12091197
use alloy_primitives::map::B256Set;
12101198
use reth_provider::{
1211-
providers::ConsistentDbView, test_utils::create_test_provider_factory, BlockReader,
1212-
DatabaseProviderFactory,
1199+
providers::OverlayStateProviderFactory, test_utils::create_test_provider_factory,
1200+
BlockReader, DatabaseProviderFactory, StageCheckpointReader, TrieReader,
12131201
};
1214-
use reth_trie::{MultiProof, TrieInput};
1202+
use reth_trie::MultiProof;
12151203
use reth_trie_parallel::proof_task::{ProofTaskCtx, ProofWorkerHandle};
12161204
use revm_primitives::{B256, U256};
12171205

12181206
fn create_test_state_root_task<F>(factory: F) -> MultiProofTask
12191207
where
1220-
F: DatabaseProviderFactory<Provider: BlockReader> + Clone + 'static,
1208+
F: DatabaseProviderFactory<Provider: BlockReader + TrieReader + StageCheckpointReader>
1209+
+ Clone
1210+
+ Send
1211+
+ 'static,
12211212
{
12221213
let executor = WorkloadExecutor::default();
1223-
let (_trie_input, config) = MultiProofConfig::from_input(TrieInput::default());
1224-
let task_ctx = ProofTaskCtx::new(
1225-
config.nodes_sorted.clone(),
1226-
config.state_sorted.clone(),
1227-
config.prefix_sets.clone(),
1228-
);
1229-
let consistent_view = ConsistentDbView::new(factory, None);
1230-
let proof_handle =
1231-
ProofWorkerHandle::new(executor.handle().clone(), consistent_view, task_ctx, 1, 1);
1214+
let overlay_factory = OverlayStateProviderFactory::new(factory);
1215+
let task_ctx = ProofTaskCtx::new(overlay_factory, Default::default());
1216+
let proof_handle = ProofWorkerHandle::new(executor.handle().clone(), task_ctx, 1, 1);
12321217
let channel = channel();
12331218

1234-
MultiProofTask::new(config, executor, proof_handle, channel.0, 1, None)
1219+
MultiProofTask::new(executor, proof_handle, channel.0, 1, None)
12351220
}
12361221

12371222
#[test]

0 commit comments

Comments
 (0)