|
3 | 3 | //! A [`Chain`] contains the state of accounts for the chain after execution of its constituent |
4 | 4 | //! blocks, as well as a list of the blocks the chain is composed of. |
5 | 5 |
|
6 | | -use super::externals::TreeExternals; |
7 | | -use crate::BundleStateDataRef; |
| 6 | +use std::{ |
| 7 | + collections::{BTreeMap, HashMap}, |
| 8 | + ops::{Deref, DerefMut}, |
| 9 | + time::Instant, |
| 10 | +}; |
| 11 | + |
8 | 12 | use reth_blockchain_tree_api::{ |
9 | | - error::{BlockchainTreeError, InsertBlockErrorKind}, |
10 | | - BlockAttachment, BlockValidationKind, |
| 13 | + BlockAttachment, |
| 14 | + BlockValidationKind, error::{BlockchainTreeError, InsertBlockErrorKind}, |
11 | 15 | }; |
12 | 16 | use reth_consensus::{Consensus, ConsensusError, PostExecutionInput}; |
13 | 17 | use reth_db_api::database::Database; |
14 | 18 | use reth_evm::execute::{BlockExecutorProvider, Executor}; |
15 | 19 | use reth_execution_errors::BlockExecutionError; |
16 | 20 | use reth_execution_types::{Chain, ExecutionOutcome}; |
17 | 21 | use reth_primitives::{ |
18 | | - BlockHash, BlockNumber, ForkBlock, GotExpected, Header, SealedBlockWithSenders, SealedHeader, |
19 | | - B256, U256, |
| 22 | + B256, BlockHash, BlockNumber, ForkBlock, GotExpected, Header, SealedBlockWithSenders, |
| 23 | + SealedHeader, U256, |
20 | 24 | }; |
21 | 25 | use reth_provider::{ |
22 | | - providers::{BundleStateProvider, ConsistentDbView}, |
23 | | - FullExecutionDataProvider, ProviderError, StateRootProvider, |
| 26 | + FullExecutionDataProvider, |
| 27 | + ProviderError, providers::{BundleStateProvider, ConsistentDbView}, StateRootProvider, |
24 | 28 | }; |
25 | 29 | use reth_revm::{database::StateProviderDatabase, primitives::EvmState}; |
26 | | -use reth_trie::{updates::TrieUpdates, HashedPostState}; |
| 30 | +use reth_trie::{HashedPostState, updates::TrieUpdates}; |
27 | 31 | use reth_trie_parallel::parallel_root::ParallelStateRoot; |
28 | 32 | use reth_trie_prefetch::TriePrefetch; |
29 | | -use std::{ |
30 | | - collections::{BTreeMap, HashMap}, |
31 | | - ops::{Deref, DerefMut}, |
32 | | - sync::Arc, |
33 | | - time::Instant, |
34 | | -}; |
| 33 | + |
| 34 | +use crate::BundleStateDataRef; |
| 35 | + |
| 36 | +use super::externals::TreeExternals; |
35 | 37 |
|
36 | 38 | /// A chain in the blockchain tree that has functionality to execute blocks and append them to |
37 | 39 | /// itself. |
@@ -227,22 +229,25 @@ impl AppendableChain { |
227 | 229 | let block_hash = block.hash(); |
228 | 230 | let block = block.unseal(); |
229 | 231 |
|
| 232 | + let execute_start = Instant::now(); |
230 | 233 | let state = executor.execute((&block, U256::MAX, ancestor_blocks).into())?; |
231 | 234 | externals.consensus.validate_block_post_execution( |
232 | 235 | &block, |
233 | 236 | PostExecutionInput::new(&state.receipts, &state.requests), |
234 | 237 | )?; |
235 | 238 |
|
236 | | - let initial_execution_outcome = ExecutionOutcome::from((state, block.number)); |
| 239 | + tracing::debug!( |
| 240 | + target: "blockchain_tree::chain", |
| 241 | + number = block.number, |
| 242 | + duration = ?execute_start.elapsed(), |
| 243 | + "executed and validated block" |
| 244 | + ); |
237 | 245 |
|
238 | | - // stop the prefetch task. |
239 | | - if let Some(interrupt_tx) = interrupt_tx { |
240 | | - let _ = interrupt_tx.send(()); |
241 | | - } |
| 246 | + let initial_execution_outcome = ExecutionOutcome::from((state, block.number)); |
242 | 247 |
|
243 | 248 | // check state root if the block extends the canonical chain __and__ if state root |
244 | 249 | // validation was requested. |
245 | | - if block_validation_kind.is_exhaustive() { |
| 250 | + let result = if block_validation_kind.is_exhaustive() { |
246 | 251 | // calculate and check state root |
247 | 252 | let start = Instant::now(); |
248 | 253 | let (state_root, trie_updates) = if block_attachment.is_canonical() { |
@@ -285,7 +290,14 @@ impl AppendableChain { |
285 | 290 | Ok((initial_execution_outcome, trie_updates)) |
286 | 291 | } else { |
287 | 292 | Ok((initial_execution_outcome, None)) |
288 | | - } |
| 293 | + }; |
| 294 | + |
| 295 | + // stop the prefetch task. |
| 296 | + if let Some(interrupt_tx) = interrupt_tx { |
| 297 | + let _ = interrupt_tx.send(()); |
| 298 | + }; |
| 299 | + |
| 300 | + result |
289 | 301 | } |
290 | 302 |
|
291 | 303 | /// Validate and execute the given block, and append it to this chain. |
@@ -358,18 +370,11 @@ impl AppendableChain { |
358 | 370 | let (interrupt_tx, interrupt_rx) = tokio::sync::oneshot::channel(); |
359 | 371 |
|
360 | 372 | let mut trie_prefetch = TriePrefetch::new(); |
361 | | - let consistent_view = if let Ok(view) = |
362 | | - ConsistentDbView::new_with_latest_tip(externals.provider_factory.clone()) |
363 | | - { |
364 | | - view |
365 | | - } else { |
366 | | - tracing::debug!("Failed to create consistent view for trie prefetch"); |
367 | | - return (None, None) |
368 | | - }; |
| 373 | + let provider_factory = externals.provider_factory.clone(); |
369 | 374 |
|
370 | 375 | tokio::spawn({ |
371 | 376 | async move { |
372 | | - trie_prefetch.run::<DB>(Arc::new(consistent_view), prefetch_rx, interrupt_rx).await; |
| 377 | + trie_prefetch.run::<DB>(provider_factory, prefetch_rx, interrupt_rx).await; |
373 | 378 | } |
374 | 379 | }); |
375 | 380 |
|
|
0 commit comments