pub struct ArenaParallelSparseTrie { /* private fields */ }Expand description
An arena-based sparse trie whose subtries can be mutated in parallel.
§Structure
Uses arena allocation (NodeArena) for node storage with direct index-based child
pointers, avoiding the per-node hashing overhead of a HashMap-based trie. The trie is split
into two tiers:
- Upper trie (
upper_arena): Contains nodes whose path is shorter thanUPPER_TRIE_MAX_DEPTHnibbles. These are the root and its immediate children. - Lower subtries (
ArenaSparseSubtrie): Each child of an upper-trie branch at the depth boundary becomes the root of its own subtrie, stored as anArenaSparseNode::Subtriechild in the upper arena. Each subtrie owns its own arena, enabling lock-free parallel mutation.
Node placement is determined by path length (not counting a branch’s short key):
- Paths with <
UPPER_TRIE_MAX_DEPTHnibbles live inupper_arena. - Paths with ≥
UPPER_TRIE_MAX_DEPTHnibbles live in a subtrie.
§Node Revealing
Nodes are lazily revealed from proof data via SparseTrie::reveal_nodes. Each node is
placed into the upper arena or delegated to its subtrie based on path depth. Unrevealed
children are stored as blinded BranchChilds referencing their RLP encoding.
When multiple subtries have pending reveals, they are processed in parallel using rayon
(controlled by ArenaParallelismThresholds::min_revealed_nodes).
§Leaf Operations
Leaf updates and removals are applied via SparseTrie::update_leaves. The method walks
the upper trie to route each update to the correct subtrie, then processes subtries in
parallel when the update count exceeds ArenaParallelismThresholds::min_updates.
After updates, structural changes (branch collapse, subtrie unwrapping) are handled by propagating dirty state back up through the upper trie.
§Root Hash Calculation
Root hash computation follows a bottom-up approach:
SparseTrie::update_subtrie_hashes: Takes dirty subtries from the upper arena and hashes them in parallel (when dirty leaf count meetsArenaParallelismThresholds::min_dirty_leaves), then walks the upper trie to restore hashed subtries and inline-hash any remaining dirty nodes.SparseTrie::root: Callsupdate_subtrie_hashes, then RLP-encodes the full upper trie depth-first to produce the root hash.
Each node tracks its state via ArenaSparseNodeState (Revealed, Cached, or Dirty)
so only modified subtrees are recomputed.
§Pruning
SparseTrie::prune replaces nodes older than its epoch cutoff with
blinded BranchChild entries using their cached RLP, then compacts the
arenas. Subtries are pruned in parallel when their leaf count exceeds
ArenaParallelismThresholds::min_leaves_for_prune.
Implementations§
Source§impl ArenaParallelSparseTrie
impl ArenaParallelSparseTrie
Sourcepub const fn with_parallelism_thresholds(
self,
thresholds: ArenaParallelismThresholds,
) -> Self
pub const fn with_parallelism_thresholds( self, thresholds: ArenaParallelismThresholds, ) -> Self
Sets the thresholds that control when parallelism is used during operations.
Trait Implementations§
Source§impl Clone for ArenaParallelSparseTrie
impl Clone for ArenaParallelSparseTrie
Source§impl Debug for ArenaParallelSparseTrie
impl Debug for ArenaParallelSparseTrie
Source§impl Default for ArenaParallelSparseTrie
impl Default for ArenaParallelSparseTrie
Source§impl SparseTrie for ArenaParallelSparseTrie
impl SparseTrie for ArenaParallelSparseTrie
Source§fn set_root(
&mut self,
root: TrieNodeV2,
masks: Option<BranchNodeMasks>,
retain_updates: bool,
) -> SparseTrieResult<()>
fn set_root( &mut self, root: TrieNodeV2, masks: Option<BranchNodeMasks>, retain_updates: bool, ) -> SparseTrieResult<()>
Source§fn set_updates(&mut self, retain_updates: bool)
fn set_updates(&mut self, retain_updates: bool)
Source§fn reveal_nodes(
&mut self,
nodes: &mut [ProofTrieNodeV2],
) -> SparseTrieResult<()>
fn reveal_nodes( &mut self, nodes: &mut [ProofTrieNodeV2], ) -> SparseTrieResult<()>
Source§fn root(&mut self, new_epoch: TrieNodeEpoch) -> B256
fn root(&mut self, new_epoch: TrieNodeEpoch) -> B256
Source§fn is_root_cached(&self) -> bool
fn is_root_cached(&self) -> bool
Source§fn root_epoch(&self) -> Option<TrieNodeEpoch>
fn root_epoch(&self) -> Option<TrieNodeEpoch>
None when it is dirty.Source§fn update_subtrie_hashes(&mut self, new_epoch: TrieNodeEpoch)
fn update_subtrie_hashes(&mut self, new_epoch: TrieNodeEpoch)
Source§fn get_leaf_value(&self, full_path: &Nibbles) -> Option<&Vec<u8>>
fn get_leaf_value(&self, full_path: &Nibbles) -> Option<&Vec<u8>>
Source§fn find_leaf(
&self,
full_path: &Nibbles,
expected_value: Option<&Vec<u8>>,
) -> Result<LeafLookup, LeafLookupError>
fn find_leaf( &self, full_path: &Nibbles, expected_value: Option<&Vec<u8>>, ) -> Result<LeafLookup, LeafLookupError>
Source§fn updates_ref(&self) -> Cow<'_, SparseTrieUpdates>
fn updates_ref(&self) -> Cow<'_, SparseTrieUpdates>
Source§fn take_updates(&mut self) -> SparseTrieUpdates
fn take_updates(&mut self) -> SparseTrieUpdates
Source§fn clear(&mut self)
fn clear(&mut self)
Source§fn prune(&mut self, prune_before: TrieNodeEpoch) -> usize
fn prune(&mut self, prune_before: TrieNodeEpoch) -> usize
prune_before into hash stubs. Read moreSource§fn update_leaves(
&mut self,
updates: &mut B256Map<LeafUpdate>,
proof_required_fn: impl FnMut(B256, ProofV2TargetParent),
) -> SparseTrieResult<()>
fn update_leaves( &mut self, updates: &mut B256Map<LeafUpdate>, proof_required_fn: impl FnMut(B256, ProofV2TargetParent), ) -> SparseTrieResult<()>
Auto Trait Implementations§
impl Freeze for ArenaParallelSparseTrie
impl RefUnwindSafe for ArenaParallelSparseTrie
impl Send for ArenaParallelSparseTrie
impl Sync for ArenaParallelSparseTrie
impl Unpin for ArenaParallelSparseTrie
impl UnsafeUnpin for ArenaParallelSparseTrie
impl UnwindSafe for ArenaParallelSparseTrie
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<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: 336 bytes