[][src]Struct geen::MutableMmr

pub struct MutableMmr<B> where
    B: Storage<Value = H256>, 
{ /* fields omitted */ }

Unlike a pure MMR, which is append-only, in MutableMmr, leaf nodes can be marked as deleted.

In MutableMmr a roaring bitmap tracks which data have been marked as deleted, and the merklish root is modified to include the hash of the roaring bitmap.

The MutableMmr API maps nearly 1:1 to that of MerkleMountainRange so that you should be able to use it as a drop-in replacement for the latter in most cases.

Methods

impl<B> MutableMmr<B> where
    B: Storage<Value = H256>, 
[src]

pub fn new(mmr_backend: B) -> MutableMmr<B>[src]

Create a new mutable MMR using the backend provided

pub fn restore(&mut self, state: MutableMmrLeafNodes) -> Result<(), GeneError>[src]

Reset the MutableMmr and restore the MMR state from the set of leaf_hashes and deleted nodes.

pub fn len(&self) -> u32[src]

Return the number of leaf nodes in the MutableMmr that have not been marked as deleted.

NB: This is semantically different to MerkleMountainRange::len(). The latter returns the total number of nodes in the MMR, while this function returns the number of leaf nodes minus the number of nodes marked for deletion.

pub fn is_empty(&self) -> Result<bool, GeneError>[src]

Returns true if the the MMR contains no nodes, OR all nodes have been marked for deletion

pub fn get_leaf_hash(
    &self,
    leaf_node_index: u32
) -> Result<Option<H256>, GeneError>
[src]

This function returns the hash of the leaf index provided, indexed from 0. If the hash does not exist, or if it has been marked for deletion, None is returned.

pub fn get_leaf_status(
    &self,
    leaf_node_index: u32
) -> Result<(Option<H256>, bool), GeneError>
[src]

Returns the hash of the leaf index provided, as well as its deletion status. The node has been marked for deletion if the boolean value is true.

pub fn get_leaf_count(&self) -> usize[src]

Returns the number of leave nodes in the MMR.

pub fn get_merkle_root(&self) -> Result<H256, GeneError>[src]

Returns a merkle(ish) root for this merkle set.

The root is calculated by concatenating the MMR merkle root with the compressed serialisation of the bitmap and then hashing the result.

pub fn get_mmr_only_root(&self) -> Result<H256, GeneError>[src]

Returns only the MMR merkle root without the compressed serialisation of the bitmap

pub fn find_leaf_node(&self, hash: &H256) -> Result<Option<usize>, GeneError>[src]

See [MerkleMountainRange::find_merkle_root]

pub fn push(&mut self, hash: &H256) -> Result<usize, GeneError>[src]

Push a new element into the MMR. Computes new related peaks at the same time if applicable. Returns the new number of leaf nodes (regardless of deleted state) in the mutable MMR

pub fn delete_and_compress(
    &mut self,
    leaf_node_index: u32,
    compress: bool
) -> bool
[src]

Mark a node for deletion and optionally compress the deletion bitmap. Don't call this function unless you're in a tight loop and want to eke out some extra performance by delaying the bitmap compression until after the batch deletion.

Note that this function doesn't actually delete anything (the underlying MMR structure is immutable), but marks the leaf node as deleted. Once a leaf node has been marked for deletion:

  • get_leaf_hash(n) will return None,
  • len() will not count this node anymore

Parameters

  • leaf_node_index: The index of the leaf node to mark for deletion, zero-based.
  • compress: Indicates whether the roaring bitmap should be compressed after marking the node for deletion. NB: You should set this to true unless you are in a loop and deleting multiple nodes, and you must set this to true if you are about to call get_merkle_root(). If you don't, the merkle root will be incorrect.

Return

The function returns true if a node was actually marked for deletion. If the index is out of bounds, or was already deleted, the function returns false.

pub fn delete(&mut self, leaf_node_index: u32) -> bool[src]

Mark a node for completion, and compress the roaring bitmap. See [delete_and_compress] for details.

pub fn compress(&mut self) -> bool[src]

Compress the roaring bitmap mapping deleted nodes. You never have to call this method unless you have been calling [delete_and_compress] with compress set to false ahead of a call to [get_merkle_root].

pub fn validate(&self) -> Result<(), GeneError>[src]

Walks the nodes in the MMR and validates all parent hashes

This just calls through to the underlying MMR's validate method. There's nothing we can do to check whether the roaring bitmap represents all the leaf nodes that we want to delete. Note: A struct that uses MutableMmr and links it to actual data should be able to do this though.

pub fn to_leaf_nodes(
    &self,
    index: usize,
    count: usize
) -> Result<MutableMmrLeafNodes, GeneError>
[src]

Returns the state of the MMR that consists of the leaf hashes and the deleted nodes.

pub fn mmr(&self) -> &MerkleMountainRange<B>[src]

Expose the MerkleMountainRange for verifying proofs

Trait Implementations

impl<B> From<MerkleMountainRange<B>> for MutableMmr<B> where
    B: Storage<Value = H256>, 
[src]

impl<B, B2> PartialEq<MutableMmr<B2>> for MutableMmr<B> where
    B: Storage<Value = H256>,
    B2: Storage<Value = H256>, 
[src]

impl<B: Debug> Debug for MutableMmr<B> where
    B: Storage<Value = H256>, 
[src]

Auto Trait Implementations

impl<B> Send for MutableMmr<B> where
    B: Send

impl<B> Sync for MutableMmr<B> where
    B: Sync

impl<B> Unpin for MutableMmr<B> where
    B: Unpin

impl<B> UnwindSafe for MutableMmr<B> where
    B: UnwindSafe

impl<B> RefUnwindSafe for MutableMmr<B> where
    B: RefUnwindSafe

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> FromCast<T> for T

impl<T, U> Cast<U> for T where
    U: FromCast<T>, 

impl<T> FromBits<T> for T

impl<T, U> IntoBits<U> for T where
    U: FromBits<T>, 

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,