mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
perf(tree): keep storage trie around for updates (#12971)
This commit is contained in:
@ -10,7 +10,7 @@ use reth_trie::{
|
||||
};
|
||||
use reth_trie_db::DatabaseProof;
|
||||
use reth_trie_parallel::root::ParallelStateRootError;
|
||||
use reth_trie_sparse::{SparseStateTrie, SparseStateTrieResult};
|
||||
use reth_trie_sparse::{SparseStateTrie, SparseStateTrieResult, SparseTrieError};
|
||||
use revm_primitives::{keccak256, EvmState, B256};
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
@ -489,25 +489,24 @@ fn update_sparse_trie(
|
||||
|
||||
// Update storage slots with new values and calculate storage roots.
|
||||
for (address, storage) in state.storages {
|
||||
let storage_trie = trie.storage_trie_mut(&address).ok_or(SparseTrieError::Blind)?;
|
||||
|
||||
if storage.wiped {
|
||||
trie.wipe_storage(address)?;
|
||||
storage_trie.wipe();
|
||||
}
|
||||
|
||||
for (slot, value) in storage.storage {
|
||||
let slot_nibbles = Nibbles::unpack(slot);
|
||||
if value.is_zero() {
|
||||
// TODO: handle blinded node error
|
||||
trie.remove_storage_leaf(address, &slot_nibbles)?;
|
||||
storage_trie.remove_leaf(&slot_nibbles)?;
|
||||
} else {
|
||||
trie.update_storage_leaf(
|
||||
address,
|
||||
slot_nibbles,
|
||||
alloy_rlp::encode_fixed_size(&value).to_vec(),
|
||||
)?;
|
||||
storage_trie
|
||||
.update_leaf(slot_nibbles, alloy_rlp::encode_fixed_size(&value).to_vec())?;
|
||||
}
|
||||
}
|
||||
|
||||
trie.storage_root(address).unwrap();
|
||||
storage_trie.root();
|
||||
}
|
||||
|
||||
// Update accounts with new values
|
||||
|
||||
@ -62,7 +62,7 @@ impl SparseStateTrie {
|
||||
self.revealed.get(account).is_some_and(|slots| slots.contains(slot))
|
||||
}
|
||||
|
||||
/// Returned mutable reference to storage sparse trie if it was revealed.
|
||||
/// Returns mutable reference to storage sparse trie if it was revealed.
|
||||
pub fn storage_trie_mut(&mut self, account: &B256) -> Option<&mut RevealedSparseTrie> {
|
||||
self.storages.get_mut(account).and_then(|e| e.as_revealed_mut())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user