@@ -13,6 +13,7 @@ use alloy_rpc_types_engine::{
1313 CancunPayloadFields , ExecutionPayload , ForkchoiceState , PayloadStatus , PayloadStatusEnum ,
1414 PayloadValidationError ,
1515} ;
16+ use dashmap:: DashMap ;
1617use reth_beacon_consensus:: {
1718 BeaconConsensusEngineEvent , BeaconEngineMessage , ForkchoiceStateTracker , InvalidHeaderCache ,
1819 OnForkChoiceUpdated , MIN_BLOCKS_FOR_PIPELINE_RUN ,
@@ -43,7 +44,10 @@ use reth_provider::{
4344} ;
4445use reth_revm:: database:: StateProviderDatabase ;
4546use reth_stages_api:: ControlFlow ;
46- use reth_trie:: { updates:: TrieUpdates , HashedPostState , TrieInput } ;
47+ use reth_trie:: {
48+ updates:: { StorageTrieUpdates , TrieUpdates } ,
49+ HashedPostState , TrieInput ,
50+ } ;
4751use reth_trie_parallel:: parallel_root:: { ParallelStateRoot , ParallelStateRootError } ;
4852use reth_trie_prefetch:: TriePrefetch ;
4953use std:: {
@@ -2194,11 +2198,11 @@ where
21942198 }
21952199
21962200 trace ! ( target: "engine::tree" , block=?block. num_hash( ) , "Executing block" ) ;
2197- let ( prefetch_tx, interrupt_tx) =
2201+ let ( prefetch_tx, interrupt_tx, missing_leaves_cache ) =
21982202 if self . enable_prefetch && !self . skip_state_root_validation {
21992203 self . setup_prefetch ( )
22002204 } else {
2201- ( None , None )
2205+ ( None , None , Default :: default ( ) )
22022206 } ;
22032207
22042208 let executor = self
@@ -2256,7 +2260,7 @@ where
22562260 let persistence_in_progress = self . persistence_state . in_progress ( ) ;
22572261 if !persistence_in_progress {
22582262 state_root_result = match self
2259- . compute_state_root_parallel ( block. parent_hash , & hashed_state)
2263+ . compute_state_root_parallel ( block. parent_hash , & hashed_state, missing_leaves_cache )
22602264 {
22612265 Ok ( ( state_root, trie_output) ) => Some ( ( state_root, trie_output) ) ,
22622266 Err ( ParallelStateRootError :: Provider ( ProviderError :: ConsistentView ( error) ) ) => {
@@ -2342,6 +2346,7 @@ where
23422346 & self ,
23432347 parent_hash : B256 ,
23442348 hashed_state : & HashedPostState ,
2349+ missing_leaves_cache : Arc < DashMap < B256 , ( B256 , StorageTrieUpdates ) > > ,
23452350 ) -> Result < ( B256 , TrieUpdates ) , ParallelStateRootError > {
23462351 let consistent_view = ConsistentDbView :: new_with_latest_tip ( self . provider . clone ( ) ) ?;
23472352 let mut input = TrieInput :: default ( ) ;
@@ -2364,7 +2369,7 @@ where
23642369 // Extend with block we are validating root for.
23652370 input. append_ref ( hashed_state) ;
23662371
2367- ParallelStateRoot :: new ( consistent_view, input) . incremental_root_with_updates ( )
2372+ ParallelStateRoot :: new ( consistent_view, input) . incremental_root_with_updates_and_cache ( missing_leaves_cache )
23682373 }
23692374
23702375 /// Handles an error that occurred while inserting a block.
@@ -2608,20 +2613,30 @@ where
26082613 Ok ( ( ) )
26092614 }
26102615
2611- fn setup_prefetch ( & self ) -> ( Option < UnboundedSender < EvmState > > , Option < oneshot:: Sender < ( ) > > ) {
2616+ fn setup_prefetch (
2617+ & self ,
2618+ ) -> (
2619+ Option < UnboundedSender < EvmState > > ,
2620+ Option < oneshot:: Sender < ( ) > > ,
2621+ Arc < DashMap < B256 , ( B256 , StorageTrieUpdates ) > > ,
2622+ ) {
26122623 let ( prefetch_tx, prefetch_rx) = tokio:: sync:: mpsc:: unbounded_channel ( ) ;
26132624 let ( interrupt_tx, interrupt_rx) = oneshot:: channel ( ) ;
26142625
26152626 let mut trie_prefetch = TriePrefetch :: new ( ) ;
26162627 let provider_factory = self . provider . clone ( ) ;
2628+ let missing_leaves_cache = Arc :: new ( DashMap :: new ( ) ) ;
2629+ let missing_leaves_cache_clone = Arc :: clone ( & missing_leaves_cache) ;
26172630
26182631 tokio:: spawn ( {
26192632 async move {
2620- trie_prefetch. run ( provider_factory, prefetch_rx, interrupt_rx) . await ;
2633+ trie_prefetch
2634+ . run ( provider_factory, prefetch_rx, interrupt_rx, missing_leaves_cache_clone)
2635+ . await ;
26212636 }
26222637 } ) ;
26232638
2624- ( Some ( prefetch_tx) , Some ( interrupt_tx) )
2639+ ( Some ( prefetch_tx) , Some ( interrupt_tx) , missing_leaves_cache )
26252640 }
26262641}
26272642
0 commit comments