diff --git a/crates/chain-state/src/in_memory.rs b/crates/chain-state/src/in_memory.rs index 311830dbc6..bd88f8eb75 100644 --- a/crates/chain-state/src/in_memory.rs +++ b/crates/chain-state/src/in_memory.rs @@ -17,7 +17,10 @@ use reth_primitives_traits::{ SignedTransaction, }; use reth_storage_api::StateProviderBox; -use reth_trie::{updates::TrieUpdatesSorted, HashedPostStateSorted, LazyTrieData, TrieInputSorted}; +use reth_trie::{ + updates::TrieUpdatesSorted, HashedPostStateSorted, LazyTrieData, SortedTrieData, + TrieInputSorted, +}; use std::{collections::BTreeMap, sync::Arc, time::Instant}; use tokio::sync::{broadcast, watch}; @@ -948,22 +951,36 @@ impl> NewCanonicalChain { match blocks { [] => Chain::default(), [first, rest @ ..] => { + let trie_data_handle = first.trie_data_handle(); let mut chain = Chain::from_block( first.recovered_block().clone(), ExecutionOutcome::from(( first.execution_outcome().clone(), first.block_number(), )), - LazyTrieData::ready(first.hashed_state(), first.trie_updates()), + LazyTrieData::deferred(move || { + let trie_data = trie_data_handle.wait_cloned(); + SortedTrieData { + hashed_state: trie_data.hashed_state, + trie_updates: trie_data.trie_updates, + } + }), ); for exec in rest { + let trie_data_handle = exec.trie_data_handle(); chain.append_block( exec.recovered_block().clone(), ExecutionOutcome::from(( exec.execution_outcome().clone(), exec.block_number(), )), - LazyTrieData::ready(exec.hashed_state(), exec.trie_updates()), + LazyTrieData::deferred(move || { + let trie_data = trie_data_handle.wait_cloned(); + SortedTrieData { + hashed_state: trie_data.hashed_state, + trie_updates: trie_data.trie_updates, + } + }), ); } chain