pub struct PositionalLineageHash(/* private fields */);Expand description
A 128-bit positional lineage hash encoding parental lineage for tree traversal.
Layout (using full 128 bits):
- Mode (2 bits): Determines position field size
- Position (8/16/24 bits): Block position in sequence
- Current Sequence Hash (64 bits): Full u64 sequence hash for this block
- Parent Fragment (variable bits): Truncated lower bits of the parent’s sequence hash
Modes (automatically selected based on position):
- Mode 00: 8-bit position (max 255) + 64-bit current + 54-bit parent fragment
- Mode 01: 16-bit position (max 65,535) + 64-bit current + 46-bit parent fragment
- Mode 10: 24-bit position (max 16,777,215) + 64-bit current + 38-bit parent fragment
Carrying the full 64-bit current sequence hash inline makes PLH self-contained for
chain extension: a child PLH can be derived from a parent PLH plus the child’s
BlockHash alone, with no out-of-band state. The parent fragment shrinks as
position grows, but radix backward-traversal always matches on
(position, parent_fragment), and the probability of a shared parent at high
positions decreases faster than the fragment-collision bound rises.
Implementations§
Source§impl PositionalLineageHash
impl PositionalLineageHash
Sourcepub fn new(
current_seq_hash: SequenceHash,
parent_seq_hash: Option<SequenceHash>,
position: u64,
) -> Self
pub fn new( current_seq_hash: SequenceHash, parent_seq_hash: Option<SequenceHash>, position: u64, ) -> Self
Creates a new PositionalLineageHash from components.
The mode is automatically selected based on the position value to use the minimal representation that can fit the position.
§Arguments
current_seq_hash- The full u64 sequence hash of the current blockparent_seq_hash- The full u64 sequence hash of the parent block (None for root). Will be truncated to this position’s parent-fragment width.position- The block position in the sequence
§Panics
Panics if position >= 2^24 (16,777,216).
Sourcepub fn root(block_hash: BlockHash) -> Self
pub fn root(block_hash: BlockHash) -> Self
Creates a root PositionalLineageHash (position 0).
At the root, the sequence hash equals the block hash and there is no parent.
Sourcepub fn extend(&self, child_block_hash: BlockHash) -> Self
pub fn extend(&self, child_block_hash: BlockHash) -> Self
Extends this lineage by one block, producing the child PLH.
The chain recurrence is compute_next_sequence_hash. Salt does not seed the
per-step xxh3: BlockHash is already xxh3(tokens, salt_hash), so salt is mixed
into seq_hash[0] and propagates through every parent. Re-feeding it at each step
would be redundant.
§Panics
Panics if self.position() + 1 >= 2^24.
Sourcepub fn current_sequence_hash(&self) -> SequenceHash
pub fn current_sequence_hash(&self) -> SequenceHash
Returns the full 64-bit sequence hash of the current block.
Unlike the legacy current_hash_fragment (now removed), this is the complete
SequenceHash and is what extend feeds into the chain.
Sourcepub fn parent_hash_fragment(&self) -> u64
pub fn parent_hash_fragment(&self) -> u64
Returns the parent sequence hash fragment as stored in this PLH.
Width depends on this PLH’s mode (54/46/38 bits). Backward radix lookup must
always combine (position, parent_fragment) — the fragment alone is not unique.
Sourcepub fn parent_fragment_for_child_position(&self, child_position: u64) -> u64
pub fn parent_fragment_for_child_position(&self, child_position: u64) -> u64
Truncates this PLH’s current_sequence_hash to the parent-fragment width that
a child at child_position would store.
Useful when an external builder wants to construct a child PLH or verify a
parent/child edge: child.parent_hash_fragment() == parent.parent_fragment_for_child_position(child.position()).
Trait Implementations§
Source§impl Clone for PositionalLineageHash
impl Clone for PositionalLineageHash
Source§fn clone(&self) -> PositionalLineageHash
fn clone(&self) -> PositionalLineageHash
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for PositionalLineageHash
Source§impl Debug for PositionalLineageHash
impl Debug for PositionalLineageHash
Source§impl Default for PositionalLineageHash
impl Default for PositionalLineageHash
Source§fn default() -> PositionalLineageHash
fn default() -> PositionalLineageHash
Source§impl<'de> Deserialize<'de> for PositionalLineageHash
impl<'de> Deserialize<'de> for PositionalLineageHash
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for PositionalLineageHash
impl Display for PositionalLineageHash
impl Eq for PositionalLineageHash
Source§impl Hash for PositionalLineageHash
impl Hash for PositionalLineageHash
Source§impl Ord for PositionalLineageHash
impl Ord for PositionalLineageHash
Source§fn cmp(&self, other: &Self) -> Ordering
fn cmp(&self, other: &Self) -> Ordering
Lexicographic order: Self::position, then Self::current_sequence_hash,
then the full packed Self::as_u128 so the order is total and consistent with Eq.