[−][src]Struct tari_mmr::MutableMmr
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<D, B> MutableMmr<D, B> where
D: Digest,
B: ArrayLike<Value = Hash>,
[src]
D: Digest,
B: ArrayLike<Value = Hash>,
pub fn new(mmr_backend: B, deleted: Bitmap) -> MutableMmr<D, B>
[src]
Create a new mutable MMR using the backend provided
pub fn assign(
&mut self,
state: MutableMmrLeafNodes
) -> Result<(), MerkleMountainRangeError>
[src]
&mut self,
state: MutableMmrLeafNodes
) -> Result<(), MerkleMountainRangeError>
Clear the MutableMmr and assign the MMR state from the set of leaf_hashes and deleted nodes given in state
.
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, MerkleMountainRangeError>
[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_index: u32
) -> Result<Option<Hash>, MerkleMountainRangeError>
[src]
&self,
leaf_index: u32
) -> Result<Option<Hash>, MerkleMountainRangeError>
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_index: u32
) -> Result<(Option<Hash>, bool), MerkleMountainRangeError>
[src]
&self,
leaf_index: u32
) -> Result<(Option<Hash>, bool), MerkleMountainRangeError>
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<Hash, MerkleMountainRangeError>
[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<Hash, MerkleMountainRangeError>
[src]
Returns only the MMR merkle root without the compressed serialisation of the bitmap
pub fn find_node_index(
&self,
hash: &Hash
) -> Result<Option<usize>, MerkleMountainRangeError>
[src]
&self,
hash: &Hash
) -> Result<Option<usize>, MerkleMountainRangeError>
pub fn find_leaf_index(
&self,
hash: &Hash
) -> Result<Option<usize>, MerkleMountainRangeError>
[src]
&self,
hash: &Hash
) -> Result<Option<usize>, MerkleMountainRangeError>
pub fn push(&mut self, hash: &Hash) -> Result<usize, MerkleMountainRangeError>
[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_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 callget_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_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<(), MerkleMountainRangeError>
[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,
leaf_index: usize,
count: usize
) -> Result<MutableMmrLeafNodes, MerkleMountainRangeError>
[src]
&self,
leaf_index: usize,
count: usize
) -> Result<MutableMmrLeafNodes, MerkleMountainRangeError>
Returns the state of the MMR that consists of the leaf hashes and the deleted nodes.
pub fn mmr(&self) -> &MerkleMountainRange<D, B>
[src]
Expose the MerkleMountainRange for verifying proofs
pub fn deleted(&self) -> &Bitmap
[src]
Return a reference to the bitmap of deleted nodes
pub fn clear(&mut self) -> Result<(), MerkleMountainRangeError>
[src]
Trait Implementations
impl<D: Debug, B: Debug> Debug for MutableMmr<D, B> where
D: Digest,
B: ArrayLike<Value = Hash>,
[src]
D: Digest,
B: ArrayLike<Value = Hash>,
impl<D, B> From<MerkleMountainRange<D, B>> for MutableMmr<D, B> where
D: Digest,
B: ArrayLike<Value = Hash>,
[src]
D: Digest,
B: ArrayLike<Value = Hash>,
fn from(mmr: MerkleMountainRange<D, B>) -> Self
[src]
impl<D, B, B2> PartialEq<MutableMmr<D, B2>> for MutableMmr<D, B> where
D: Digest,
B: ArrayLike<Value = Hash>,
B2: ArrayLike<Value = Hash>,
[src]
D: Digest,
B: ArrayLike<Value = Hash>,
B2: ArrayLike<Value = Hash>,
Auto Trait Implementations
impl<D, B> RefUnwindSafe for MutableMmr<D, B> where
B: RefUnwindSafe,
D: RefUnwindSafe,
B: RefUnwindSafe,
D: RefUnwindSafe,
impl<D, B> Send for MutableMmr<D, B> where
B: Send,
D: Send,
B: Send,
D: Send,
impl<D, B> Sync for MutableMmr<D, B> where
B: Sync,
D: Sync,
B: Sync,
D: Sync,
impl<D, B> Unpin for MutableMmr<D, B> where
B: Unpin,
D: Unpin,
B: Unpin,
D: Unpin,
impl<D, B> UnwindSafe for MutableMmr<D, B> where
B: UnwindSafe,
D: UnwindSafe,
B: UnwindSafe,
D: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> SafeBorrow<T> for T where
T: ?Sized,
T: ?Sized,
fn borrow_replacement(ptr: &T) -> &T
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,