Skip to content

Commit 3598c68

Browse files
committed
refactor(tries): use SparseStateTrie::update_account_stateless from reth
1 parent 8f8c9dc commit 3598c68

1 file changed

Lines changed: 3 additions & 25 deletions

File tree

crates/tries/src/default.rs

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
use crate::{StatelessTrie, StatelessTrieError, WitnessDbError};
22
use alloc::{collections::VecDeque, format, vec::Vec};
33
use alloy_primitives::{Address, B256, U256, keccak256, map::B256IndexMap};
4-
use alloy_rlp::{Decodable, Encodable};
4+
use alloy_rlp::Decodable;
55
use alloy_rpc_types_debug::ExecutionWitness;
66
use alloy_trie::{EMPTY_ROOT_HASH, TrieAccount, nodes::TrieNode};
77
use itertools::Itertools;
88
use reth_trie_common::{
99
BranchNodeMasks, DecodedMultiProofV2, HashedPostState, Nibbles, ProofTrieNodeV2,
10-
TRIE_ACCOUNT_RLP_MAX_SIZE,
1110
};
1211
use reth_trie_sparse::{
13-
RevealableSparseTrie, SparseStateTrie, SparseTrie,
12+
RevealableSparseTrie, SparseStateTrie,
1413
errors::SparseStateTrieResult,
1514
provider::{DefaultTrieNodeProvider, DefaultTrieNodeProviderFactory},
1615
};
@@ -332,31 +331,10 @@ fn calculate_state_root(
332331
}
333332

334333
// 2. Apply account‑level updates and (re)encode the account nodes
335-
// Update accounts with new values
336-
let mut account_rlp_buf = Vec::with_capacity(TRIE_ACCOUNT_RLP_MAX_SIZE);
337-
338334
for (hashed_address, account) in
339335
state.accounts.into_iter().sorted_unstable_by_key(|(addr, _)| *addr)
340336
{
341-
let nibbles = Nibbles::unpack(hashed_address);
342-
343-
// Determine which storage root should be used for this account
344-
let storage_root = if let Some(storage_trie) = trie.storage_trie_mut(&hashed_address) {
345-
storage_trie.root()
346-
} else if let Some(value) = trie.get_account_value(&hashed_address) {
347-
TrieAccount::decode(&mut &value[..])?.storage_root
348-
} else {
349-
EMPTY_ROOT_HASH
350-
};
351-
352-
// Decide whether to remove or update the account leaf
353-
if let Some(account) = account {
354-
account_rlp_buf.clear();
355-
account.into_trie_account(storage_root).encode(&mut account_rlp_buf);
356-
trie.update_account_leaf(nibbles, account_rlp_buf.clone(), &provider_factory)?;
357-
} else {
358-
trie.remove_account_leaf(&nibbles, &provider_factory)?;
359-
}
337+
trie.update_account_stateless(hashed_address, account, &provider_factory)?;
360338
}
361339

362340
// Return new state root

0 commit comments

Comments
 (0)