diff --git a/crates/blockchain/blockchain.rs b/crates/blockchain/blockchain.rs index 4ad3f2db64..0b1d9da824 100644 --- a/crates/blockchain/blockchain.rs +++ b/crates/blockchain/blockchain.rs @@ -602,12 +602,15 @@ impl Blockchain { let (storage_trie, storage_updates_map) = storage_updates_map .entry(hashed_address_h256) .or_insert_with(|| { - ( - storage.open_storage_trie( + let db = storage + .open_storage_trie( hashed_address_h256, - account_state.storage_root, + *EMPTY_TRIE_HASH, parent_header.state_root, - ), + ) + .map(|v| v.db); + ( + db.and_then(|db| Trie::open_noroot(db).map_err(StoreError::Trie)), Default::default(), ) }); diff --git a/crates/common/trie/trie.rs b/crates/common/trie/trie.rs index 1a62852c08..8a69264c98 100644 --- a/crates/common/trie/trie.rs +++ b/crates/common/trie/trie.rs @@ -52,7 +52,7 @@ pub type TrieNode = (Nibbles, NodeRLP); /// Ethereum-compatible Merkle Patricia Trie pub struct Trie { - db: Box, + pub db: Box, pub root: NodeRef, pending_removal: FxHashSet, dirty: FxHashSet, @@ -89,6 +89,16 @@ impl Trie { } } + pub fn open_noroot(db: Box) -> Result { + let mut trie = Trie::open(db, *EMPTY_TRIE_HASH); + if let Some(root) = NodeRef::from(NodeHash::from(*EMPTY_TRIE_HASH)) + .get_node(trie.db.as_ref(), Nibbles::default())? + { + trie.root = root.into(); + } + Ok(trie) + } + /// Return a reference to the internal database. /// /// Warning: All changes made to the db will bypass the trie and may cause the trie to suddenly diff --git a/tooling/Cargo.lock b/tooling/Cargo.lock index fceb0ba508..896f0a45d7 100644 --- a/tooling/Cargo.lock +++ b/tooling/Cargo.lock @@ -4309,6 +4309,7 @@ dependencies = [ name = "guest_program" version = "7.0.0" dependencies = [ + "bincode", "bytes", "ethrex-blockchain", "ethrex-common 7.0.0",