From c71ecafed27625d8540a5e1cf2a08e6cdea2c00d Mon Sep 17 00:00:00 2001 From: Alexey Shekhirin <5773434+shekhirin@users.noreply.github.com> Date: Thu, 30 Jan 2025 22:03:45 +0000 Subject: [PATCH] add docs to target struct --- crates/engine/tree/src/tree/root.rs | 4 ++-- crates/trie/common/src/proofs.rs | 25 ++++++++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/crates/engine/tree/src/tree/root.rs b/crates/engine/tree/src/tree/root.rs index 1b1022282189..51e56ced29fb 100644 --- a/crates/engine/tree/src/tree/root.rs +++ b/crates/engine/tree/src/tree/root.rs @@ -1000,7 +1000,7 @@ fn extend_multi_proof_targets(targets: &mut MultiProofTargets, other: MultiProof for (address, slots) in other { match targets.entry(address) { Entry::Occupied(mut entry) => { - entry.get_mut().into_only_storage().extend(slots); + entry.get_mut().into_only_storage_mut().extend(slots); } Entry::Vacant(entry) => { entry.insert(slots.into_with_account()); @@ -1013,7 +1013,7 @@ fn extend_multi_proof_targets_ref(targets: &mut MultiProofTargets, other: &Multi for (address, slots) in other { match targets.entry(*address) { Entry::Occupied(mut entry) => { - entry.get_mut().into_only_storage().extend(slots.clone()); + entry.get_mut().into_only_storage_mut().extend(slots.clone()); } Entry::Vacant(entry) => { entry.insert(slots.clone().into_with_account()); diff --git a/crates/trie/common/src/proofs.rs b/crates/trie/common/src/proofs.rs index ee3cca72512a..cb7d2cc678b1 100644 --- a/crates/trie/common/src/proofs.rs +++ b/crates/trie/common/src/proofs.rs @@ -20,9 +20,12 @@ use reth_primitives_traits::Account; /// Proof targets map. pub type MultiProofTargets = B256HashMap; +/// Proof target account. #[derive(Debug, Clone)] pub enum MultiProofAccountTarget { + /// Fetch both account proof and storage slot proofs. WithAccount(B256HashSet), + /// Fetch only storage slot proofs. OnlyStorage(B256HashSet), } @@ -38,32 +41,38 @@ impl IntoIterator for MultiProofAccountTarget { } impl MultiProofAccountTarget { + /// Returns `true` if the target is fetching both account and storage slot proofs. pub const fn is_with_account(&self) -> bool { matches!(self, Self::WithAccount(_)) } + /// Returns `true` if the target is fetching only storage slot proofs. pub const fn is_only_storage(&self) -> bool { matches!(self, Self::OnlyStorage(_)) } + /// Returns `true` if no storage slot proofs are fetched. pub fn is_empty(&self) -> bool { match self { Self::WithAccount(set) | Self::OnlyStorage(set) => set.is_empty(), } } + /// Returns the number of storage slot proofs. pub fn len(&self) -> usize { match self { Self::WithAccount(set) | Self::OnlyStorage(set) => set.len(), } } + /// Returns `true` if the storage slot is included. pub fn contains(&self, value: &B256) -> bool { match self { Self::WithAccount(set) | Self::OnlyStorage(set) => set.contains(value), } } + /// Extends the target with another target. pub fn extend(&mut self, other: Self) { match (self, other) { ( @@ -73,21 +82,23 @@ impl MultiProofAccountTarget { } } + /// Converts the target into [`Self::WithAccount`]. pub fn into_with_account(self) -> Self { match self { - Self::WithAccount(set) | Self::OnlyStorage(set) => Self::WithAccount(set), + Self::OnlyStorage(set) => Self::WithAccount(set), + Self::WithAccount(_) => self, } } - pub fn into_only_storage(&mut self) -> &mut Self { - *self = match self { - Self::OnlyStorage(set) | Self::WithAccount(set) => { - Self::OnlyStorage(std::mem::take(set)) - } - }; + /// Converts the target into a mutable reference to [`Self::OnlyStorage`]. + pub fn into_only_storage_mut(&mut self) -> &mut Self { + if let Self::OnlyStorage(set) = self { + *self = Self::OnlyStorage(std::mem::take(set)); + } self } + /// Converts the target into a [`B256HashSet`] set of storage slots. pub fn into_slots(self) -> B256HashSet { match self { Self::WithAccount(set) | Self::OnlyStorage(set) => set,