pub struct PMMR<'a, T, B>{
pub size: u64,
/* private fields */
}
Expand description
Prunable Merkle Mountain Range implementation. All positions within the tree start at 0 just like array indices.
Heavily relies on navigation operations within a binary tree. In particular, all the implementation needs to keep track of the MMR structure is how far we are in the sequence of nodes making up the MMR.
Fields§
§size: u64
Number of nodes in the PMMR
Implementations§
source§impl<'a, T, B> PMMR<'a, T, B>
impl<'a, T, B> PMMR<'a, T, B>
sourcepub fn new(backend: &'a mut B) -> PMMR<'_, T, B>
pub fn new(backend: &'a mut B) -> PMMR<'_, T, B>
Build a new prunable Merkle Mountain Range using the provided backend.
sourcepub fn at(backend: &'a mut B, size: u64) -> PMMR<'_, T, B>
pub fn at(backend: &'a mut B, size: u64) -> PMMR<'_, T, B>
Build a new prunable Merkle Mountain Range pre-initialized until size with the provided backend.
sourcepub fn readonly_pmmr(&self) -> ReadonlyPMMR<'_, T, B>
pub fn readonly_pmmr(&self) -> ReadonlyPMMR<'_, T, B>
Build a “readonly” view of this PMMR.
sourcepub fn push(&mut self, leaf: &T) -> Result<u64, String>
pub fn push(&mut self, leaf: &T) -> Result<u64, String>
Push a new element into the MMR. Computes new related peaks at the same time if applicable.
sourcepub fn push_pruned_subtree(
&mut self,
hash: Hash,
pos0: u64
) -> Result<(), String>
pub fn push_pruned_subtree( &mut self, hash: Hash, pos0: u64 ) -> Result<(), String>
Push a pruned subtree into the PMMR
sourcepub fn reset_prune_list(&mut self)
pub fn reset_prune_list(&mut self)
Reset prune list
sourcepub fn remove_from_leaf_set(&mut self, pos0: u64)
pub fn remove_from_leaf_set(&mut self, pos0: u64)
Remove the specified position from the leaf set
sourcepub fn snapshot(&mut self, header: &BlockHeader) -> Result<(), String>
pub fn snapshot(&mut self, header: &BlockHeader) -> Result<(), String>
Saves a snapshot of the MMR tagged with the block hash. Specifically - snapshots the utxo file as we need this rewound before sending the txhashset zip file to another node for fast-sync.
sourcepub fn rewind(
&mut self,
position: u64,
rewind_rm_pos: &Bitmap
) -> Result<(), String>
pub fn rewind( &mut self, position: u64, rewind_rm_pos: &Bitmap ) -> Result<(), String>
Rewind the PMMR to a previous position, as if all push operations after that had been canceled. Expects a position in the PMMR to rewind and bitmaps representing the positions added and removed that we want to “undo”.
sourcepub fn prune(&mut self, pos0: u64) -> Result<bool, String>
pub fn prune(&mut self, pos0: u64) -> Result<bool, String>
Prunes (removes) the leaf from the MMR at the specified position. Returns an error if prune is called on a non-leaf position. Returns false if the leaf node has already been pruned. Returns true if pruning is successful.
sourcepub fn validate(&self) -> Result<(), String>
pub fn validate(&self) -> Result<(), String>
Walks all unpruned nodes in the MMR and revalidate all parent hashes
sourcepub fn dump(&self, short: bool)
pub fn dump(&self, short: bool)
Debugging utility to print information about the MMRs. Short version only prints the last 8 nodes.
sourcepub fn dump_stats(&self)
pub fn dump_stats(&self)
Prints PMMR statistics to the logs, used for debugging.
sourcepub fn dump_from_file(&self, short: bool)
pub fn dump_from_file(&self, short: bool)
Debugging utility to print information about the MMRs. Short version only prints the last 8 nodes. Looks in the underlying hash file and so ignores the remove log.
Trait Implementations§
source§impl<'a, T, B> ReadablePMMR for PMMR<'a, T, B>
impl<'a, T, B> ReadablePMMR for PMMR<'a, T, B>
source§fn get_hash(&self, pos0: u64) -> Option<Hash>
fn get_hash(&self, pos0: u64) -> Option<Hash>
source§fn get_data(&self, pos0: u64) -> Option<Self::Item>
fn get_data(&self, pos0: u64) -> Option<Self::Item>
source§fn get_from_file(&self, pos0: u64) -> Option<Hash>
fn get_from_file(&self, pos0: u64) -> Option<Hash>
source§fn get_peak_from_file(&self, pos0: u64) -> Option<Hash>
fn get_peak_from_file(&self, pos0: u64) -> Option<Hash>
source§fn get_data_from_file(&self, pos0: u64) -> Option<Self::Item>
fn get_data_from_file(&self, pos0: u64) -> Option<Self::Item>
source§fn unpruned_size(&self) -> u64
fn unpruned_size(&self) -> u64
source§fn leaf_pos_iter(&self) -> Box<dyn Iterator<Item = u64> + '_>
fn leaf_pos_iter(&self) -> Box<dyn Iterator<Item = u64> + '_>
source§fn leaf_idx_iter(&self, from_idx: u64) -> Box<dyn Iterator<Item = u64> + '_>
fn leaf_idx_iter(&self, from_idx: u64) -> Box<dyn Iterator<Item = u64> + '_>
source§fn n_unpruned_leaves(&self) -> u64
fn n_unpruned_leaves(&self) -> u64
source§fn n_unpruned_leaves_to_index(&self, to_index: u64) -> u64
fn n_unpruned_leaves_to_index(&self, to_index: u64) -> u64
source§fn bag_the_rhs(&self, peak_pos0: u64) -> Option<Hash>
fn bag_the_rhs(&self, peak_pos0: u64) -> Option<Hash>
source§fn peak_path(&self, peak_pos0: u64) -> Vec<Hash>
fn peak_path(&self, peak_pos0: u64) -> Vec<Hash>
peak_pos
, where the rhs is bagged together