pub struct MerkleMountainRange(/* private fields */);Expand description
Incrementally constructable Merkle mountain range.
Each entry in the list is a pair of (digest, max-depth), where max-depth tracks an upper bound on the size of the subtree for which the digest is the root. The largest subtree is at index 0, the smallest at index len - 1.
Note that the max size of the internal vec of digests (peaks) is equal to log_2 n where n is the number of leaves in the tree.
Implementations§
Source§impl MerkleMountainRange
impl MerkleMountainRange
Sourcepub fn new_finalized(root: Digest) -> Self
pub fn new_finalized(root: Digest) -> Self
Construct a new MerkleMountainRange in a finalized state, given a root.
Sourcepub fn push(&mut self, leaf: Digest) -> Result<(), Error>
pub fn push(&mut self, leaf: Digest) -> Result<(), Error>
Push a new leaf onto the Merkle mountain range.
Sourcepub fn finalize(&mut self) -> Result<(), Error>
pub fn finalize(&mut self) -> Result<(), Error>
Finalize the MerkleMountainRange, combining all peaks into one root. No new nodes can be added to a finalized commitment.
Sourcepub fn finalized_root(self) -> Option<Digest>
pub fn finalized_root(self) -> Option<Digest>
Finalizes the MerkleMountainRange and returns the root, or returns None is the
MerkleMountainRange is empty.
Sourcepub fn is_finalized(&self) -> bool
pub fn is_finalized(&self) -> bool
Returns true if the MerkleMountainRange is finalized. No new nodes can be added to a finalized MerkleMountainRange.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the MerkleMountainRange is empty.
Sourcepub fn encode(&self) -> Vec<u8> ⓘ
pub fn encode(&self) -> Vec<u8> ⓘ
A compact encoding for the MerkleMountainRange used in encoding the journal designed to be efficient for use in the EVM, and designed to ensure it is possible to construct the journal encoding of a finalized MerkleMountainRange given only the finalized root.
Sourcepub fn decode(bytes: impl AsRef<[u8]>) -> Result<Self, DecodingError>
pub fn decode(bytes: impl AsRef<[u8]>) -> Result<Self, DecodingError>
Decode the specialized journal encoding. See MerkleMountainRange::encode.
Trait Implementations§
Source§impl Clone for MerkleMountainRange
impl Clone for MerkleMountainRange
Source§fn clone(&self) -> MerkleMountainRange
fn clone(&self) -> MerkleMountainRange
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MerkleMountainRange
impl Debug for MerkleMountainRange
Source§impl<'de> Deserialize<'de> for MerkleMountainRange
impl<'de> Deserialize<'de> for MerkleMountainRange
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<D: Borrow<Digest>> Extend<D> for MerkleMountainRange
impl<D: Borrow<Digest>> Extend<D> for MerkleMountainRange
Source§fn extend<T: IntoIterator<Item = D>>(&mut self, leaves: T)
fn extend<T: IntoIterator<Item = D>>(&mut self, leaves: T)
Extend a MerkleMountainRange from an iterator of digest leaves.
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<D: Borrow<Digest>> FromIterator<D> for MerkleMountainRange
impl<D: Borrow<Digest>> FromIterator<D> for MerkleMountainRange
Source§fn from_iter<T: IntoIterator<Item = D>>(leaves: T) -> Self
fn from_iter<T: IntoIterator<Item = D>>(leaves: T) -> Self
Construct a MerkleMountainRange from an iterator of digest leaves.
Auto Trait Implementations§
impl Freeze for MerkleMountainRange
impl RefUnwindSafe for MerkleMountainRange
impl Send for MerkleMountainRange
impl Sync for MerkleMountainRange
impl Unpin for MerkleMountainRange
impl UnwindSafe for MerkleMountainRange
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more