|
1 | 1 | use crate::{StatelessTrie, StatelessTrieError, WitnessDbError}; |
2 | 2 | use alloc::{collections::VecDeque, format, vec::Vec}; |
3 | 3 | use alloy_primitives::{Address, B256, U256, keccak256, map::B256IndexMap}; |
4 | | -use alloy_rlp::{Decodable, Encodable}; |
| 4 | +use alloy_rlp::Decodable; |
5 | 5 | use alloy_rpc_types_debug::ExecutionWitness; |
6 | 6 | use alloy_trie::{EMPTY_ROOT_HASH, TrieAccount, nodes::TrieNode}; |
7 | 7 | use itertools::Itertools; |
8 | 8 | use reth_trie_common::{ |
9 | 9 | BranchNodeMasks, DecodedMultiProofV2, HashedPostState, Nibbles, ProofTrieNodeV2, |
10 | | - TRIE_ACCOUNT_RLP_MAX_SIZE, |
11 | 10 | }; |
12 | 11 | use reth_trie_sparse::{ |
13 | | - RevealableSparseTrie, SparseStateTrie, SparseTrie, |
| 12 | + RevealableSparseTrie, SparseStateTrie, |
14 | 13 | errors::SparseStateTrieResult, |
15 | 14 | provider::{DefaultTrieNodeProvider, DefaultTrieNodeProviderFactory}, |
16 | 15 | }; |
@@ -332,31 +331,10 @@ fn calculate_state_root( |
332 | 331 | } |
333 | 332 |
|
334 | 333 | // 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 | | - |
338 | 334 | for (hashed_address, account) in |
339 | 335 | state.accounts.into_iter().sorted_unstable_by_key(|(addr, _)| *addr) |
340 | 336 | { |
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)?; |
360 | 338 | } |
361 | 339 |
|
362 | 340 | // Return new state root |
|
0 commit comments