pub enum RevealableSparseTrie<T = ArenaParallelSparseTrie> {
Blind(Option<Box<T>>),
Revealed(Box<T>),
}Expand description
A sparse trie that is either in a “blind” state (no nodes are revealed, root node hash is unknown) or in a “revealed” state (root node has been revealed and the trie can be updated).
In blind mode the trie does not contain any decoded node data, which saves memory but prevents direct access to node contents. The revealed mode stores decoded nodes along with additional information such as values, allowing direct manipulation.
The sparse trie design is optimised for:
- Memory efficiency - only revealed nodes are loaded into memory
- Update tracking - changes to the trie structure can be tracked and selectively persisted
- Incremental operations - nodes can be revealed as needed without loading the entire trie. This is what gives rise to the notion of a “sparse” trie.
Variants§
Blind(Option<Box<T>>)
The trie is blind – no nodes have been revealed
This is the default state. In this state, the trie cannot be directly queried or modified until nodes are revealed.
In this state the RevealableSparseTrie can optionally carry with it a cleared
sparse trie. This allows for reusing the trie’s allocations between payload executions.
Revealed(Box<T>)
Some nodes in the Trie have been revealed.
In this state, the trie can be queried and modified for the parts that have been revealed. Other parts remain blind and require revealing before they can be accessed.
Implementations§
Source§impl<T: SparseTrieTrait + Default> RevealableSparseTrie<T>
impl<T: SparseTrieTrait + Default> RevealableSparseTrie<T>
Sourcepub fn revealed_empty() -> Self
pub fn revealed_empty() -> Self
Creates a new revealed but empty sparse trie.
Sourcepub fn reveal_root(
&mut self,
root: TrieNodeV2,
masks: Option<BranchNodeMasks>,
retain_updates: bool,
) -> SparseTrieResult<&mut T>
pub fn reveal_root( &mut self, root: TrieNodeV2, masks: Option<BranchNodeMasks>, retain_updates: bool, ) -> SparseTrieResult<&mut T>
Reveals the root node, converting a blind trie into a revealed one.
If the trie is blinded, its root node is replaced with root.
The masks are used to determine how the node’s children are stored.
The retention flag controls whether trie updates should be tracked.
§Returns
A mutable reference to the underlying RevealableSparseTrie.
Sourcepub fn reveal_v2_proof_nodes(
&mut self,
nodes: &mut [ProofTrieNodeV2],
retain_updates: bool,
) -> SparseTrieResult<()>
pub fn reveal_v2_proof_nodes( &mut self, nodes: &mut [ProofTrieNodeV2], retain_updates: bool, ) -> SparseTrieResult<()>
Reveals a batch of V2 proof nodes into this trie.
If nodes contains a node at the empty path it is used to reveal the root (transitioning
the trie from blind to revealed). Otherwise the trie must already be revealed.
Source§impl<T: SparseTrieTrait> RevealableSparseTrie<T>
impl<T: SparseTrieTrait> RevealableSparseTrie<T>
Sourcepub const fn blind() -> Self
pub const fn blind() -> Self
Creates a new blind sparse trie.
§Examples
use reth_trie_sparse::RevealableSparseTrie;
let trie = <RevealableSparseTrie>::blind();
assert!(trie.is_blind());
let trie = <RevealableSparseTrie>::default();
assert!(trie.is_blind());Sourcepub fn blind_from(trie: T) -> Self
pub fn blind_from(trie: T) -> Self
Creates a new blind sparse trie, clearing and later reusing the given
RevealableSparseTrie.
Sourcepub const fn is_revealed(&self) -> bool
pub const fn is_revealed(&self) -> bool
Returns true if the sparse trie is revealed.
Sourcepub const fn as_revealed_ref(&self) -> Option<&T>
pub const fn as_revealed_ref(&self) -> Option<&T>
Returns an immutable reference to the underlying revealed sparse trie.
Returns None if the trie is blinded.
Sourcepub fn as_revealed_mut(&mut self) -> Option<&mut T>
pub fn as_revealed_mut(&mut self) -> Option<&mut T>
Returns a mutable reference to the underlying revealed sparse trie.
Returns None if the trie is blinded.
Sourcepub fn root(&mut self, new_epoch: TrieNodeEpoch) -> Option<B256>
pub fn root(&mut self, new_epoch: TrieNodeEpoch) -> Option<B256>
Calculates the root hash of the trie.
This will update any remaining dirty nodes before computing the root hash. “dirty” nodes are nodes that need their hashes to be recomputed because one or more of their children’s hashes have changed.
§Returns
Some(B256)with the calculated root hash if the trie is revealed.Noneif the trie is still blind.
Sourcepub fn is_root_cached(&self) -> bool
pub fn is_root_cached(&self) -> bool
Returns true if the root node is cached and does not need any recomputation.
Sourcepub fn root_with_updates(
&mut self,
new_epoch: TrieNodeEpoch,
) -> Option<(B256, SparseTrieUpdates)>
pub fn root_with_updates( &mut self, new_epoch: TrieNodeEpoch, ) -> Option<(B256, SparseTrieUpdates)>
Returns the root hash along with any accumulated update information.
This is useful for when you need both the root hash and information about what nodes were modified, which can be used to efficiently update an external database.
§Returns
An Option tuple consisting of:
- The trie root hash (
B256). - A
SparseTrieUpdatesstructure containing information about updated nodes. Noneif the trie is still blind.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears this trie, setting it to a blind state.
If this instance was revealed, or was itself a Blind with a pre-allocated
RevealableSparseTrie, this will set to Blind carrying a cleared
pre-allocated RevealableSparseTrie.
Source§impl<T: SparseTrieTrait + Default> RevealableSparseTrie<T>
impl<T: SparseTrieTrait + Default> RevealableSparseTrie<T>
Sourcepub fn update_leaves(
&mut self,
updates: &mut B256Map<LeafUpdate>,
proof_required_fn: impl FnMut(B256, ProofV2TargetParent),
) -> SparseTrieResult<()>
pub fn update_leaves( &mut self, updates: &mut B256Map<LeafUpdate>, proof_required_fn: impl FnMut(B256, ProofV2TargetParent), ) -> SparseTrieResult<()>
Applies batch leaf updates to the sparse trie.
For blind tries, all updates are kept in the map and proof targets are emitted for every key (with no known parent since nothing is revealed).
For revealed tries, delegates to the inner implementation which will:
- Apply updates where possible
- Keep blocked updates in the map
- Emit proof targets for blinded paths
Trait Implementations§
Source§impl<T: Clone> Clone for RevealableSparseTrie<T>
impl<T: Clone> Clone for RevealableSparseTrie<T>
Source§impl<T: Debug> Debug for RevealableSparseTrie<T>
impl<T: Debug> Debug for RevealableSparseTrie<T>
Source§impl<T: Default> Default for RevealableSparseTrie<T>
impl<T: Default> Default for RevealableSparseTrie<T>
impl<T: Eq> Eq for RevealableSparseTrie<T>
Source§impl<T: PartialEq> PartialEq for RevealableSparseTrie<T>
impl<T: PartialEq> PartialEq for RevealableSparseTrie<T>
impl<T: PartialEq> StructuralPartialEq for RevealableSparseTrie<T>
Auto Trait Implementations§
impl<T> Freeze for RevealableSparseTrie<T>
impl<T> RefUnwindSafe for RevealableSparseTrie<T>
impl<T> Send for RevealableSparseTrie<T>
impl<T> Sync for RevealableSparseTrie<T>
impl<T> Unpin for RevealableSparseTrie<T>
impl<T> UnsafeUnpin for RevealableSparseTrie<T>
impl<T> UnwindSafe for RevealableSparseTrie<T>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§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> 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> ⓘ
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 16 bytes
Size for each variant:
Blind: 8 bytesRevealed: 8 bytes