pub struct MerkleBridge<H> { /* private fields */ }
Expand description

The information required to “update” witnesses from one state of a Merkle tree to another.

The witness for a particular leaf of a Merkle tree consists of the siblings of that leaf, plus the siblings of the parents of that leaf in a path to the root of the tree. When considering a Merkle tree where leaves are appended to the tree in a linear fashion (rather than being inserted at arbitrary positions), we often wish to produce a witness for a leaf that was appended to the tree at some point in the past. A MerkleBridge from one position in the tree to another position in the tree contains the minimal amount of information necessary to produce a witness for the leaf at the former position, given that leaves have been subsequently appended to reach the current position.

MerkleBridge values have a semigroup, such that the sum (fused) value of two successive bridges, along with a NonEmptyFrontier with its tip at the prior position of the first bridge being fused, can be used to produce a witness for the leaf at the tip of the prior frontier.

Implementations§

source§

impl<H> MerkleBridge<H>

source

pub fn new(value: H) -> Self

Construct a new Merkle bridge containing only the specified leaf.

source

pub fn from_parts( prior_position: Option<Position>, tracking: BTreeSet<Address>, ommers: BTreeMap<Address, H>, frontier: NonEmptyFrontier<H> ) -> Self

Construct a new Merkle bridge from its constituent parts.

source

pub fn prior_position(&self) -> Option<Position>

Returns the position of the final leaf in the frontier of the bridge that this bridge is the successor of, or None if this is the first bridge in a tree.

source

pub fn position(&self) -> Position

Returns the position of the most recently appended leaf.

source

pub fn tracking(&self) -> &BTreeSet<Address>

Returns the set of internal node addresses that we’re searching for the ommers for.

source

pub fn ommers(&self) -> &BTreeMap<Address, H>

Returns the set of internal node addresses that we’re searching for the ommers for.

source

pub fn frontier(&self) -> &NonEmptyFrontier<H>

Returns the non-empty frontier of this Merkle bridge.

source

pub fn current_leaf(&self) -> &H

Returns the value of the most recently appended leaf.

source

pub fn check_continuity(&self, next: &Self) -> Result<(), ContinuityError>

Checks whether this bridge is a valid successor for the specified bridge.

source

pub fn position_range(&self) -> Range<Position>

Returns the range of positions observed by this bridge.

source§

impl<'a, H: Hashable + Clone + Ord + 'a> MerkleBridge<H>

source

pub fn successor(&self, track_current_leaf: bool) -> Self

Constructs a new bridge to follow this one. If mark_current_leaf is true, the successor will track the information necessary to create a witness for the leaf most recently appended to this bridge’s frontier.

source

pub fn append(&mut self, value: H)

Advances this bridge’s frontier by appending the specified node, and updates any auth path ommers being tracked if necessary.

Trait Implementations§

source§

impl<H: Clone> Clone for MerkleBridge<H>

source§

fn clone(&self) -> MerkleBridge<H>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<H: Debug> Debug for MerkleBridge<H>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<H: PartialEq> PartialEq<MerkleBridge<H>> for MerkleBridge<H>

source§

fn eq(&self, other: &MerkleBridge<H>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<H: Eq> Eq for MerkleBridge<H>

source§

impl<H> StructuralEq for MerkleBridge<H>

source§

impl<H> StructuralPartialEq for MerkleBridge<H>

Auto Trait Implementations§

§

impl<H> RefUnwindSafe for MerkleBridge<H>where H: RefUnwindSafe,

§

impl<H> Send for MerkleBridge<H>where H: Send,

§

impl<H> Sync for MerkleBridge<H>where H: Sync,

§

impl<H> Unpin for MerkleBridge<H>where H: Unpin,

§

impl<H> UnwindSafe for MerkleBridge<H>where H: UnwindSafe + RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.