pub struct PartialMmr { /* private fields */ }
Expand description
Partially materialized Merkle Mountain Range (MMR), used to efficiently store and update the authentication paths for a subset of the elements in a full MMR.
This structure store only the authentication path for a value, the value itself is stored separately.
Implementations§
source§impl PartialMmr
impl PartialMmr
sourcepub fn from_peaks(peaks: MmrPeaks) -> Self
pub fn from_peaks(peaks: MmrPeaks) -> Self
Returns a new PartialMmr instantiated from the specified peaks.
sourcepub fn from_parts(
peaks: MmrPeaks,
nodes: BTreeMap<InOrderIndex, RpoDigest>,
track_latest: bool,
) -> Self
pub fn from_parts( peaks: MmrPeaks, nodes: BTreeMap<InOrderIndex, RpoDigest>, track_latest: bool, ) -> Self
Returns a new PartialMmr instantiated from the specified components.
This constructor does not check the consistency between peaks and nodes. If the specified peaks are nodes are inconsistent, the returned partial MMR may exhibit undefined behavior.
sourcepub fn forest(&self) -> usize
pub fn forest(&self) -> usize
Returns the current forest
of this PartialMmr.
This value corresponds to the version of the PartialMmr and the number of leaves in the underlying MMR.
sourcepub fn num_leaves(&self) -> usize
pub fn num_leaves(&self) -> usize
Returns the number of leaves in the underlying MMR for this PartialMmr.
sourcepub fn peaks(&self) -> MmrPeaks
pub fn peaks(&self) -> MmrPeaks
Returns the peaks of the MMR for this PartialMmr.
sourcepub fn is_tracked(&self, pos: usize) -> bool
pub fn is_tracked(&self, pos: usize) -> bool
Returns true if this partial MMR tracks an authentication path for the leaf at the specified position.
sourcepub fn open(&self, pos: usize) -> Result<Option<MmrProof>, MmrError>
pub fn open(&self, pos: usize) -> Result<Option<MmrProof>, MmrError>
Given a leaf position, returns the Merkle path to its corresponding peak, or None if this partial MMR does not track an authentication paths for the specified leaf.
Note: The leaf position is the 0-indexed number corresponding to the order the leaves were added, this corresponds to the MMR size prior to adding the element. So the 1st element has position 0, the second position 1, and so on.
§Errors
Returns an error if the specified position is greater-or-equal than the number of leaves in the underlying MMR.
sourcepub fn nodes(&self) -> impl Iterator<Item = (&InOrderIndex, &RpoDigest)>
pub fn nodes(&self) -> impl Iterator<Item = (&InOrderIndex, &RpoDigest)>
Returns an iterator nodes of all authentication paths of this PartialMmr.
sourcepub fn inner_nodes<'a, I: Iterator<Item = (usize, RpoDigest)> + 'a>(
&'a self,
leaves: I,
) -> impl Iterator<Item = InnerNodeInfo> + 'a
pub fn inner_nodes<'a, I: Iterator<Item = (usize, RpoDigest)> + 'a>( &'a self, leaves: I, ) -> impl Iterator<Item = InnerNodeInfo> + 'a
Returns an iterator over inner nodes of this PartialMmr for the specified leaves.
The order of iteration is not defined. If a leaf is not presented in this partial MMR it is silently ignored.
sourcepub fn add(
&mut self,
leaf: RpoDigest,
track: bool,
) -> Vec<(InOrderIndex, RpoDigest)>
pub fn add( &mut self, leaf: RpoDigest, track: bool, ) -> Vec<(InOrderIndex, RpoDigest)>
Adds a new peak and optionally track it. Returns a vector of the authentication nodes inserted into this PartialMmr as a result of this operation.
When track
is true
the new leaf is tracked.
sourcepub fn track(
&mut self,
leaf_pos: usize,
leaf: RpoDigest,
path: &MerklePath,
) -> Result<(), MmrError>
pub fn track( &mut self, leaf_pos: usize, leaf: RpoDigest, path: &MerklePath, ) -> Result<(), MmrError>
Adds the authentication path represented by MerklePath if it is valid.
The leaf_pos
refers to the global position of the leaf in the MMR, these are 0-indexed
values assigned in a strictly monotonic fashion as elements are inserted into the MMR,
this value corresponds to the values used in the MMR structure.
The leaf
corresponds to the value at leaf_pos
, and path
is the authentication path for
that element up to its corresponding Mmr peak. The leaf
is only used to compute the root
from the authentication path to valid the data, only the authentication data is saved in
the structure. If the value is required it should be stored out-of-band.
sourcepub fn untrack(&mut self, leaf_pos: usize)
pub fn untrack(&mut self, leaf_pos: usize)
Removes a leaf of the PartialMmr and the unused nodes from the authentication path.
Note: leaf_pos
corresponds to the position in the MMR and not on an individual tree.
sourcepub fn apply(
&mut self,
delta: MmrDelta,
) -> Result<Vec<(InOrderIndex, RpoDigest)>, MmrError>
pub fn apply( &mut self, delta: MmrDelta, ) -> Result<Vec<(InOrderIndex, RpoDigest)>, MmrError>
Applies updates to this PartialMmr and returns a vector of new authentication nodes inserted into the partial MMR.
Trait Implementations§
source§impl Clone for PartialMmr
impl Clone for PartialMmr
source§fn clone(&self) -> PartialMmr
fn clone(&self) -> PartialMmr
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for PartialMmr
impl Debug for PartialMmr
source§impl Deserializable for PartialMmr
impl Deserializable for PartialMmr
source§fn read_from<R: ByteReader>(
source: &mut R,
) -> Result<Self, DeserializationError>
fn read_from<R: ByteReader>( source: &mut R, ) -> Result<Self, DeserializationError>
source
, attempts to deserialize these bytes
into Self
, and returns the result. Read moresource§fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
source§impl From<&MmrPeaks> for PartialMmr
impl From<&MmrPeaks> for PartialMmr
source§impl From<&PartialMmr> for MmrPeaks
impl From<&PartialMmr> for MmrPeaks
source§fn from(partial_mmr: &PartialMmr) -> Self
fn from(partial_mmr: &PartialMmr) -> Self
source§impl From<MmrPeaks> for PartialMmr
impl From<MmrPeaks> for PartialMmr
source§impl From<PartialMmr> for MmrPeaks
impl From<PartialMmr> for MmrPeaks
source§fn from(partial_mmr: PartialMmr) -> Self
fn from(partial_mmr: PartialMmr) -> Self
source§impl PartialEq for PartialMmr
impl PartialEq for PartialMmr
source§impl Serializable for PartialMmr
impl Serializable for PartialMmr
source§fn write_into<W: ByteWriter>(&self, target: &mut W)
fn write_into<W: ByteWriter>(&self, target: &mut W)
self
into bytes and writes these bytes into the target
.source§fn get_size_hint(&self) -> usize
fn get_size_hint(&self) -> usize
impl Eq for PartialMmr
impl StructuralPartialEq for PartialMmr
Auto Trait Implementations§
impl Freeze for PartialMmr
impl RefUnwindSafe for PartialMmr
impl Send for PartialMmr
impl Sync for PartialMmr
impl Unpin for PartialMmr
impl UnwindSafe for PartialMmr
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)