pub struct ProofCalculator<TC, HC, VE: LeafValueEncoder> { /* private fields */ }Expand description
A proof calculator that generates Merkle proofs from leaf data and cached branch hashes.
The hashed cursor supplies leaves, while the trie cursor supplies cached branch hashes to skip subtries. Subtries containing proof targets or keys in the configured prefix set are recalculated.
The calculator:
- Accepts proof targets in any order and sorts them in place by parent context, then key.
- Returns proof nodes in depth-first post-order (children before parents).
- Automatically resets after each calculation
- Re-uses cursors from one calculation to the next
Implementations§
Source§impl<TC, HC, VE: LeafValueEncoder> ProofCalculator<TC, HC, VE>
impl<TC, HC, VE: LeafValueEncoder> ProofCalculator<TC, HC, VE>
Sourcepub fn new(trie_cursor: TC, hashed_cursor: HC) -> Self
pub fn new(trie_cursor: TC, hashed_cursor: HC) -> Self
Create a new ProofCalculator instance for calculating account proofs.
Sourcepub fn with_prefix_set(self, prefix_set: PrefixSet) -> Self
pub fn with_prefix_set(self, prefix_set: PrefixSet) -> Self
Sets the prefix set and returns self.
When given, all cached hashes matching the PrefixSet will be invalidated and their
subtries recalculated.
Source§impl<TC, HC, VE> ProofCalculator<TC, HC, VE>
impl<TC, HC, VE> ProofCalculator<TC, HC, VE>
Sourcepub fn proof(
&mut self,
value_encoder: &mut VE,
targets: &mut [ProofV2Target],
) -> Result<Vec<ProofTrieNodeV2>, StateProofError>
pub fn proof( &mut self, value_encoder: &mut VE, targets: &mut [ProofV2Target], ) -> Result<Vec<ProofTrieNodeV2>, StateProofError>
Generate a proof for the given targets.
Given a set of ProofV2Targets, returns nodes whose paths are a prefix of any target. The
returned nodes are sorted in depth-first post-order (children before parents).
Targets may be supplied in any order. Calculation sorts the slice in place by known parent context, then by key within each group.
Sourcepub fn compute_root_hash(
&mut self,
proof_nodes: &[ProofTrieNodeV2],
) -> Result<Option<B256>, StateProofError>
pub fn compute_root_hash( &mut self, proof_nodes: &[ProofTrieNodeV2], ) -> Result<Option<B256>, StateProofError>
Computes the root hash from a set of proof nodes.
Returns None if there is no root node (partial proof), otherwise returns the hash of the
root node.
This method reuses the internal RLP encode buffer for efficiency.
Sourcepub fn root_node(
&mut self,
value_encoder: &mut VE,
) -> Result<ProofTrieNodeV2, StateProofError>
pub fn root_node( &mut self, value_encoder: &mut VE, ) -> Result<ProofTrieNodeV2, StateProofError>
Calculates the root node of the trie.
This method does not accept targets nor retain proofs. Returns the root node which can
be used to compute the root hash via Self::compute_root_hash.
Source§impl<TC, HC> ProofCalculator<TC, HC, StorageValueEncoder>where
TC: TrieStorageCursor,
HC: HashedStorageCursor<Value = U256>,
impl<TC, HC> ProofCalculator<TC, HC, StorageValueEncoder>where
TC: TrieStorageCursor,
HC: HashedStorageCursor<Value = U256>,
Sourcepub fn new_storage(trie_cursor: TC, hashed_cursor: HC) -> Self
pub fn new_storage(trie_cursor: TC, hashed_cursor: HC) -> Self
Create a new StorageProofCalculator instance.
Sourcepub fn storage_proof(
&mut self,
hashed_address: B256,
targets: &mut [ProofV2Target],
) -> Result<Vec<ProofTrieNodeV2>, StateProofError>
pub fn storage_proof( &mut self, hashed_address: B256, targets: &mut [ProofV2Target], ) -> Result<Vec<ProofTrieNodeV2>, StateProofError>
Generate a proof for a storage trie at the given hashed address.
Given a set of ProofV2Targets, returns nodes whose paths are a prefix of any target. The
returned nodes are sorted in depth-first post-order (children before parents).
Targets may be supplied in any order. Calculation sorts the slice in place by known parent context, then by key within each group.
Sourcepub fn storage_root_node(
&mut self,
hashed_address: B256,
) -> Result<ProofTrieNodeV2, StateProofError>
pub fn storage_root_node( &mut self, hashed_address: B256, ) -> Result<ProofTrieNodeV2, StateProofError>
Calculates the root node of a storage trie.
This method does not accept targets nor retain proofs. Returns the root node which can
be used to compute the root hash via Self::compute_root_hash.
Sourcepub fn storage_root(
&mut self,
hashed_address: B256,
) -> Result<B256, StateProofError>
pub fn storage_root( &mut self, hashed_address: B256, ) -> Result<B256, StateProofError>
Calculates the storage root hash of the account at hashed_address.
Trait Implementations§
Auto Trait Implementations§
impl<TC, HC, VE> Freeze for ProofCalculator<TC, HC, VE>where
TC: Freeze,
HC: Freeze,
Vec<ProofTrieBranchChild<<VE as LeafValueEncoder>::DeferredEncoder>>: Freeze,
impl<TC, HC, VE> RefUnwindSafe for ProofCalculator<TC, HC, VE>where
TC: RefUnwindSafe,
HC: RefUnwindSafe,
Vec<ProofTrieBranchChild<<VE as LeafValueEncoder>::DeferredEncoder>>: RefUnwindSafe,
impl<TC, HC, VE> Send for ProofCalculator<TC, HC, VE>where
TC: Send,
HC: Send,
Vec<ProofTrieBranchChild<<VE as LeafValueEncoder>::DeferredEncoder>>: Send,
impl<TC, HC, VE> Sync for ProofCalculator<TC, HC, VE>where
TC: Sync,
HC: Sync,
Vec<ProofTrieBranchChild<<VE as LeafValueEncoder>::DeferredEncoder>>: Sync,
impl<TC, HC, VE> Unpin for ProofCalculator<TC, HC, VE>where
TC: Unpin,
HC: Unpin,
Vec<ProofTrieBranchChild<<VE as LeafValueEncoder>::DeferredEncoder>>: Unpin,
impl<TC, HC, VE> UnsafeUnpin for ProofCalculator<TC, HC, VE>where
TC: UnsafeUnpin,
HC: UnsafeUnpin,
Vec<ProofTrieBranchChild<<VE as LeafValueEncoder>::DeferredEncoder>>: UnsafeUnpin,
impl<TC, HC, VE> UnwindSafe for ProofCalculator<TC, HC, VE>where
TC: UnwindSafe,
HC: UnwindSafe,
Vec<ProofTrieBranchChild<<VE as LeafValueEncoder>::DeferredEncoder>>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreimpl<T> MaybeDebug for Twhere
T: Debug,
§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
Source§fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.