mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(trie): include address on storage trie update error (#14075)
This commit is contained in:
@ -107,6 +107,9 @@ pub enum SparseStateTrieErrorKind {
|
||||
/// Encoded first proof node.
|
||||
node: Bytes,
|
||||
},
|
||||
/// Storage sparse trie error.
|
||||
#[error("error in storage trie for address {0:?}: {1:?}")]
|
||||
SparseStorageTrie(B256, SparseTrieErrorKind),
|
||||
/// Sparse trie error.
|
||||
#[error(transparent)]
|
||||
Sparse(#[from] SparseTrieErrorKind),
|
||||
|
||||
@ -12,8 +12,8 @@ use alloy_primitives::{
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use reth_execution_errors::{
|
||||
SparseStateTrieError, SparseStateTrieErrorKind, SparseTrieError, SparseTrieErrorKind,
|
||||
StateProofError, TrieWitnessError,
|
||||
SparseStateTrieErrorKind, SparseTrieError, SparseTrieErrorKind, StateProofError,
|
||||
TrieWitnessError,
|
||||
};
|
||||
use reth_trie_common::{MultiProofTargets, Nibbles};
|
||||
use reth_trie_sparse::{
|
||||
@ -126,9 +126,12 @@ where
|
||||
{
|
||||
// Update storage trie first.
|
||||
let storage = state.storages.get(&hashed_address);
|
||||
let storage_trie = sparse_trie
|
||||
.storage_trie_mut(&hashed_address)
|
||||
.ok_or(SparseStateTrieErrorKind::Sparse(SparseTrieErrorKind::Blind))?;
|
||||
let storage_trie = sparse_trie.storage_trie_mut(&hashed_address).ok_or(
|
||||
SparseStateTrieErrorKind::SparseStorageTrie(
|
||||
hashed_address,
|
||||
SparseTrieErrorKind::Blind,
|
||||
),
|
||||
)?;
|
||||
for hashed_slot in hashed_slots.into_iter().sorted_unstable() {
|
||||
let storage_nibbles = Nibbles::unpack(hashed_slot);
|
||||
let maybe_leaf_value = storage
|
||||
@ -137,13 +140,13 @@ where
|
||||
.map(|v| alloy_rlp::encode_fixed_size(v).to_vec());
|
||||
|
||||
if let Some(value) = maybe_leaf_value {
|
||||
storage_trie
|
||||
.update_leaf(storage_nibbles, value)
|
||||
.map_err(SparseStateTrieError::from)?;
|
||||
storage_trie.update_leaf(storage_nibbles, value).map_err(|err| {
|
||||
SparseStateTrieErrorKind::SparseStorageTrie(hashed_address, err.into_kind())
|
||||
})?;
|
||||
} else {
|
||||
storage_trie
|
||||
.remove_leaf(&storage_nibbles)
|
||||
.map_err(SparseStateTrieError::from)?;
|
||||
storage_trie.remove_leaf(&storage_nibbles).map_err(|err| {
|
||||
SparseStateTrieErrorKind::SparseStorageTrie(hashed_address, err.into_kind())
|
||||
})?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user