feat(trie): include address on storage trie update error (#14075)

This commit is contained in:
Alexey Shekhirin
2025-01-29 18:37:56 +00:00
committed by GitHub
parent 376a5ddf55
commit 04ddcdfae5
2 changed files with 17 additions and 11 deletions

View File

@ -107,6 +107,9 @@ pub enum SparseStateTrieErrorKind {
/// Encoded first proof node. /// Encoded first proof node.
node: Bytes, node: Bytes,
}, },
/// Storage sparse trie error.
#[error("error in storage trie for address {0:?}: {1:?}")]
SparseStorageTrie(B256, SparseTrieErrorKind),
/// Sparse trie error. /// Sparse trie error.
#[error(transparent)] #[error(transparent)]
Sparse(#[from] SparseTrieErrorKind), Sparse(#[from] SparseTrieErrorKind),

View File

@ -12,8 +12,8 @@ use alloy_primitives::{
}; };
use itertools::Itertools; use itertools::Itertools;
use reth_execution_errors::{ use reth_execution_errors::{
SparseStateTrieError, SparseStateTrieErrorKind, SparseTrieError, SparseTrieErrorKind, SparseStateTrieErrorKind, SparseTrieError, SparseTrieErrorKind, StateProofError,
StateProofError, TrieWitnessError, TrieWitnessError,
}; };
use reth_trie_common::{MultiProofTargets, Nibbles}; use reth_trie_common::{MultiProofTargets, Nibbles};
use reth_trie_sparse::{ use reth_trie_sparse::{
@ -126,9 +126,12 @@ where
{ {
// Update storage trie first. // Update storage trie first.
let storage = state.storages.get(&hashed_address); let storage = state.storages.get(&hashed_address);
let storage_trie = sparse_trie let storage_trie = sparse_trie.storage_trie_mut(&hashed_address).ok_or(
.storage_trie_mut(&hashed_address) SparseStateTrieErrorKind::SparseStorageTrie(
.ok_or(SparseStateTrieErrorKind::Sparse(SparseTrieErrorKind::Blind))?; hashed_address,
SparseTrieErrorKind::Blind,
),
)?;
for hashed_slot in hashed_slots.into_iter().sorted_unstable() { for hashed_slot in hashed_slots.into_iter().sorted_unstable() {
let storage_nibbles = Nibbles::unpack(hashed_slot); let storage_nibbles = Nibbles::unpack(hashed_slot);
let maybe_leaf_value = storage let maybe_leaf_value = storage
@ -137,13 +140,13 @@ where
.map(|v| alloy_rlp::encode_fixed_size(v).to_vec()); .map(|v| alloy_rlp::encode_fixed_size(v).to_vec());
if let Some(value) = maybe_leaf_value { if let Some(value) = maybe_leaf_value {
storage_trie storage_trie.update_leaf(storage_nibbles, value).map_err(|err| {
.update_leaf(storage_nibbles, value) SparseStateTrieErrorKind::SparseStorageTrie(hashed_address, err.into_kind())
.map_err(SparseStateTrieError::from)?; })?;
} else { } else {
storage_trie storage_trie.remove_leaf(&storage_nibbles).map_err(|err| {
.remove_leaf(&storage_nibbles) SparseStateTrieErrorKind::SparseStorageTrie(hashed_address, err.into_kind())
.map_err(SparseStateTrieError::from)?; })?;
} }
} }