Skip to content

Commit ffeaa47

Browse files
chore(engine): Remove ConsistentDbView (#19188)
Co-authored-by: Alexey Shekhirin <[email protected]>
1 parent a264ccb commit ffeaa47

File tree

18 files changed

+385
-560
lines changed

18 files changed

+385
-560
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"] }
@@ -134,7 +133,6 @@ test-utils = [
134133
"reth-trie/test-utils",
135134
"reth-trie-sparse/test-utils",
136135
"reth-prune-types?/test-utils",
137-
"reth-trie-db/test-utils",
138136
"reth-trie-parallel/test-utils",
139137
"reth-ethereum-primitives/test-utils",
140138
"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/persistence.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ where
142142
&self,
143143
blocks: Vec<ExecutedBlock<N::Primitives>>,
144144
) -> Result<Option<BlockNumHash>, PersistenceError> {
145-
debug!(target: "engine::persistence", first=?blocks.first().map(|b| b.recovered_block.num_hash()), last=?blocks.last().map(|b| b.recovered_block.num_hash()), "Saving range of blocks");
145+
let first_block_hash = blocks.first().map(|b| b.recovered_block.num_hash());
146+
let last_block_hash = blocks.last().map(|b| b.recovered_block.num_hash());
147+
debug!(target: "engine::persistence", first=?first_block_hash, last=?last_block_hash, "Saving range of blocks");
148+
146149
let start_time = Instant::now();
147150
let last_block_hash_num = blocks.last().map(|block| BlockNumHash {
148151
hash: block.recovered_block().hash(),
@@ -155,6 +158,9 @@ where
155158
provider_rw.save_blocks(blocks)?;
156159
provider_rw.commit()?;
157160
}
161+
162+
debug!(target: "engine::persistence", first=?first_block_hash, last=?last_block_hash, "Saved range of blocks");
163+
158164
self.metrics.save_blocks_duration_seconds.record(start_time.elapsed());
159165
Ok(last_block_hash_num)
160166
}

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
@@ -26,12 +26,12 @@ use reth_evm::{
2626
ConfigureEvm, EvmEnvFor, OnStateHook, SpecFor, TxEnvFor,
2727
};
2828
use reth_primitives_traits::NodePrimitives;
29-
use reth_provider::{
30-
providers::ConsistentDbView, BlockReader, DatabaseProviderFactory, StateProviderFactory,
31-
StateReader,
32-
};
29+
use reth_provider::{BlockReader, DatabaseProviderROFactory, StateProviderFactory, StateReader};
3330
use reth_revm::{db::BundleState, state::EvmState};
34-
use reth_trie::TrieInput;
31+
use reth_trie::{
32+
hashed_cursor::HashedCursorFactory, prefix_set::TriePrefixSetsMut,
33+
trie_cursor::TrieCursorFactory,
34+
};
3535
use reth_trie_parallel::{
3636
proof_task::{ProofTaskCtx, ProofWorkerHandle},
3737
root::ParallelStateRootError,
@@ -121,8 +121,6 @@ where
121121
>,
122122
/// Whether to disable the parallel sparse trie.
123123
disable_parallel_sparse_trie: bool,
124-
/// A cleared trie input, kept around to be reused so allocations can be minimized.
125-
trie_input: Option<TrieInput>,
126124
/// Maximum concurrency for prewarm task.
127125
prewarm_max_concurrency: usize,
128126
}
@@ -149,7 +147,6 @@ where
149147
precompile_cache_disabled: config.precompile_cache_disabled(),
150148
precompile_cache_map,
151149
sparse_state_trie: Arc::default(),
152-
trie_input: None,
153150
disable_parallel_sparse_trie: config.disable_parallel_sparse_trie(),
154151
prewarm_max_concurrency: config.prewarm_max_concurrency(),
155152
}
@@ -200,50 +197,45 @@ where
200197
name = "payload processor",
201198
skip_all
202199
)]
203-
pub fn spawn<P, I: ExecutableTxIterator<Evm>>(
200+
pub fn spawn<P, F, I: ExecutableTxIterator<Evm>>(
204201
&mut self,
205202
env: ExecutionEnv<Evm>,
206203
transactions: I,
207204
provider_builder: StateProviderBuilder<N, P>,
208-
consistent_view: ConsistentDbView<P>,
209-
trie_input: TrieInput,
205+
multiproof_provider_factory: F,
210206
config: &TreeConfig,
211207
) -> Result<
212208
PayloadHandle<WithTxEnv<TxEnvFor<Evm>, I::Tx>, I::Error>,
213209
(ParallelStateRootError, I, ExecutionEnv<Evm>, StateProviderBuilder<N, P>),
214210
>
215211
where
216-
P: DatabaseProviderFactory<Provider: BlockReader>
217-
+ BlockReader
218-
+ StateProviderFactory
219-
+ StateReader
212+
P: BlockReader + StateProviderFactory + StateReader + Clone + 'static,
213+
F: DatabaseProviderROFactory<Provider: TrieCursorFactory + HashedCursorFactory>
220214
+ Clone
215+
+ Send
221216
+ 'static,
222217
{
223218
let span = tracing::Span::current();
224219
let (to_sparse_trie, sparse_trie_rx) = channel();
225-
// spawn multiproof task, save the trie input
226-
let (trie_input, state_root_config) = MultiProofConfig::from_input(trie_input);
227-
self.trie_input = Some(trie_input);
220+
221+
// We rely on the cursor factory to provide whatever DB overlay is necessary to see a
222+
// consistent view of the database, including the trie tables. Because of this there is no
223+
// need for an overarching prefix set to invalidate any section of the trie tables, and so
224+
// we use an empty prefix set.
225+
let prefix_sets = Arc::new(TriePrefixSetsMut::default());
228226

229227
// Create and spawn the storage proof task
230-
let task_ctx = ProofTaskCtx::new(
231-
state_root_config.nodes_sorted.clone(),
232-
state_root_config.state_sorted.clone(),
233-
state_root_config.prefix_sets.clone(),
234-
);
228+
let task_ctx = ProofTaskCtx::new(multiproof_provider_factory, prefix_sets);
235229
let storage_worker_count = config.storage_worker_count();
236230
let account_worker_count = config.account_worker_count();
237231
let proof_handle = ProofWorkerHandle::new(
238232
self.executor.handle().clone(),
239-
consistent_view,
240233
task_ctx,
241234
storage_worker_count,
242235
account_worker_count,
243236
);
244237

245238
let multi_proof_task = MultiProofTask::new(
246-
state_root_config,
247239
proof_handle.clone(),
248240
to_sparse_trie,
249241
config.multiproof_chunking_enabled().then_some(config.multiproof_chunk_size()),
@@ -393,11 +385,6 @@ where
393385
CacheTaskHandle { cache, to_prewarm_task: Some(to_prewarm_task), cache_metrics }
394386
}
395387

396-
/// Takes the trie input from the inner payload processor, if it exists.
397-
pub const fn take_trie_input(&mut self) -> Option<TrieInput> {
398-
self.trie_input.take()
399-
}
400-
401388
/// Returns the cache for the given parent hash.
402389
///
403390
/// If the given hash is different then what is recently cached, then this will create a new
@@ -718,12 +705,12 @@ mod tests {
718705
use reth_evm_ethereum::EthEvmConfig;
719706
use reth_primitives_traits::{Account, Recovered, StorageEntry};
720707
use reth_provider::{
721-
providers::{BlockchainProvider, ConsistentDbView},
708+
providers::{BlockchainProvider, OverlayStateProviderFactory},
722709
test_utils::create_test_provider_factory_with_chain_spec,
723710
ChainSpecProvider, HashingWriter,
724711
};
725712
use reth_testing_utils::generators;
726-
use reth_trie::{test_utils::state_root, HashedPostState, TrieInput};
713+
use reth_trie::{test_utils::state_root, HashedPostState};
727714
use revm_primitives::{Address, HashMap, B256, KECCAK_EMPTY, U256};
728715
use revm_state::{AccountInfo, AccountStatus, EvmState, EvmStorageSlot};
729716
use std::sync::Arc;
@@ -905,17 +892,18 @@ mod tests {
905892
&TreeConfig::default(),
906893
PrecompileCacheMap::default(),
907894
);
908-
let provider = BlockchainProvider::new(factory).unwrap();
895+
896+
let provider_factory = BlockchainProvider::new(factory).unwrap();
897+
909898
let mut handle =
910899
payload_processor
911900
.spawn(
912901
Default::default(),
913902
core::iter::empty::<
914903
Result<Recovered<TransactionSigned>, core::convert::Infallible>,
915904
>(),
916-
StateProviderBuilder::new(provider.clone(), genesis_hash, None),
917-
ConsistentDbView::new_with_latest_tip(provider).unwrap(),
918-
TrieInput::from_state(hashed_state),
905+
StateProviderBuilder::new(provider_factory.clone(), genesis_hash, None),
906+
OverlayStateProviderFactory::new(provider_factory),
919907
&TreeConfig::default(),
920908
)
921909
.map_err(|(err, ..)| err)

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

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ impl SparseTrieUpdate {
5757
}
5858

5959
/// Common configuration for multi proof tasks
60-
#[derive(Debug, Clone)]
61-
pub(super) struct MultiProofConfig {
60+
#[derive(Debug, Clone, Default)]
61+
pub(crate) struct MultiProofConfig {
6262
/// The sorted collection of cached in-memory intermediate trie nodes that
6363
/// can be reused for computation.
6464
pub nodes_sorted: Arc<TrieUpdatesSorted>,
@@ -75,7 +75,7 @@ impl MultiProofConfig {
7575
///
7676
/// This returns a cleared [`TrieInput`] so that we can reuse any allocated space in the
7777
/// [`TrieInput`].
78-
pub(super) fn from_input(mut input: TrieInput) -> (TrieInput, Self) {
78+
pub(crate) fn from_input(mut input: TrieInput) -> (TrieInput, Self) {
7979
let config = Self {
8080
nodes_sorted: Arc::new(input.nodes.drain_into_sorted()),
8181
state_sorted: Arc::new(input.state.drain_into_sorted()),
@@ -289,7 +289,6 @@ impl StorageMultiproofInput {
289289
/// Input parameters for dispatching a multiproof calculation.
290290
#[derive(Debug)]
291291
struct MultiproofInput {
292-
config: MultiProofConfig,
293292
source: Option<StateChangeSource>,
294293
hashed_state_update: HashedPostState,
295294
proof_targets: MultiProofTargets,
@@ -458,7 +457,6 @@ impl MultiproofManager {
458457
/// Dispatches a single multiproof calculation to worker pool.
459458
fn dispatch_multiproof(&mut self, multiproof_input: MultiproofInput) {
460459
let MultiproofInput {
461-
config,
462460
source,
463461
hashed_state_update,
464462
proof_targets,
@@ -485,7 +483,7 @@ impl MultiproofManager {
485483

486484
// Extend prefix sets with targets
487485
let frozen_prefix_sets =
488-
ParallelProof::extend_prefix_sets_with_targets(&config.prefix_sets, &proof_targets);
486+
ParallelProof::extend_prefix_sets_with_targets(&Default::default(), &proof_targets);
489487

490488
// Dispatch account multiproof to worker pool with result sender
491489
let input = AccountMultiproofInput {
@@ -671,8 +669,6 @@ pub(super) struct MultiProofTask {
671669
/// The size of proof targets chunk to spawn in one calculation.
672670
/// If None, chunking is disabled and all targets are processed in a single proof.
673671
chunk_size: Option<usize>,
674-
/// Task configuration.
675-
config: MultiProofConfig,
676672
/// Receiver for state root related messages (prefetch, state updates, finish signal).
677673
rx: CrossbeamReceiver<MultiProofMessage>,
678674
/// Sender for state root related messages.
@@ -696,7 +692,6 @@ pub(super) struct MultiProofTask {
696692
impl MultiProofTask {
697693
/// Creates a new multi proof task with the unified message channel
698694
pub(super) fn new(
699-
config: MultiProofConfig,
700695
proof_worker_handle: ProofWorkerHandle,
701696
to_sparse_trie: std::sync::mpsc::Sender<SparseTrieUpdate>,
702697
chunk_size: Option<usize>,
@@ -707,7 +702,6 @@ impl MultiProofTask {
707702

708703
Self {
709704
chunk_size,
710-
config,
711705
rx,
712706
tx,
713707
proof_result_rx,
@@ -761,7 +755,6 @@ impl MultiProofTask {
761755
let mut dispatch = |proof_targets| {
762756
self.multiproof_manager.dispatch(
763757
MultiproofInput {
764-
config: self.config.clone(),
765758
source: None,
766759
hashed_state_update: Default::default(),
767760
proof_targets,
@@ -909,7 +902,6 @@ impl MultiProofTask {
909902

910903
self.multiproof_manager.dispatch(
911904
MultiproofInput {
912-
config: self.config.clone(),
913905
source: Some(source),
914906
hashed_state_update,
915907
proof_targets,
@@ -1253,10 +1245,11 @@ mod tests {
12531245
use super::*;
12541246
use alloy_primitives::map::B256Set;
12551247
use reth_provider::{
1256-
providers::ConsistentDbView, test_utils::create_test_provider_factory, BlockReader,
1257-
DatabaseProviderFactory,
1248+
providers::OverlayStateProviderFactory, test_utils::create_test_provider_factory,
1249+
BlockReader, DatabaseProviderFactory, PruneCheckpointReader, StageCheckpointReader,
1250+
TrieReader,
12581251
};
1259-
use reth_trie::{MultiProof, TrieInput};
1252+
use reth_trie::MultiProof;
12601253
use reth_trie_parallel::proof_task::{ProofTaskCtx, ProofWorkerHandle};
12611254
use revm_primitives::{B256, U256};
12621255
use std::sync::OnceLock;
@@ -1275,20 +1268,19 @@ mod tests {
12751268

12761269
fn create_test_state_root_task<F>(factory: F) -> MultiProofTask
12771270
where
1278-
F: DatabaseProviderFactory<Provider: BlockReader> + Clone + 'static,
1271+
F: DatabaseProviderFactory<
1272+
Provider: BlockReader + TrieReader + StageCheckpointReader + PruneCheckpointReader,
1273+
> + Clone
1274+
+ Send
1275+
+ 'static,
12791276
{
12801277
let rt_handle = get_test_runtime_handle();
1281-
let (_trie_input, config) = MultiProofConfig::from_input(TrieInput::default());
1282-
let task_ctx = ProofTaskCtx::new(
1283-
config.nodes_sorted.clone(),
1284-
config.state_sorted.clone(),
1285-
config.prefix_sets.clone(),
1286-
);
1287-
let consistent_view = ConsistentDbView::new(factory, None);
1288-
let proof_handle = ProofWorkerHandle::new(rt_handle, consistent_view, task_ctx, 1, 1);
1278+
let overlay_factory = OverlayStateProviderFactory::new(factory);
1279+
let task_ctx = ProofTaskCtx::new(overlay_factory, Default::default());
1280+
let proof_handle = ProofWorkerHandle::new(rt_handle, task_ctx, 1, 1);
12891281
let (to_sparse_trie, _receiver) = std::sync::mpsc::channel();
12901282

1291-
MultiProofTask::new(config, proof_handle, to_sparse_trie, Some(1))
1283+
MultiProofTask::new(proof_handle, to_sparse_trie, Some(1))
12921284
}
12931285

12941286
#[test]

0 commit comments

Comments
 (0)