pub trait Backend<T: PMMRable> {
Show 19 methods
// Required methods
fn append(&mut self, data: &T, hashes: &[Hash]) -> Result<(), String>;
fn append_pruned_subtree(
&mut self,
hash: Hash,
pos0: u64
) -> Result<(), String>;
fn append_hash(&mut self, hash: Hash) -> Result<(), String>;
fn rewind(
&mut self,
pos1: u64,
rewind_rm_pos: &Bitmap
) -> Result<(), String>;
fn get_hash(&self, pos0: u64) -> Option<Hash>;
fn get_data(&self, pos0: u64) -> Option<T::E>;
fn get_from_file(&self, pos0: u64) -> Option<Hash>;
fn get_peak_from_file(&self, pos0: u64) -> Option<Hash>;
fn get_data_from_file(&self, pos0: u64) -> Option<T::E>;
fn leaf_pos_iter(&self) -> Box<dyn Iterator<Item = u64> + '_>;
fn n_unpruned_leaves(&self) -> u64;
fn n_unpruned_leaves_to_index(&self, to_index: u64) -> u64;
fn leaf_idx_iter(&self, from_idx: u64) -> Box<dyn Iterator<Item = u64> + '_>;
fn remove(&mut self, position: u64) -> Result<(), String>;
fn remove_from_leaf_set(&mut self, pos0: u64);
fn release_files(&mut self);
fn reset_prune_list(&mut self);
fn snapshot(&self, header: &BlockHeader) -> Result<(), String>;
fn dump_stats(&self);
}
Expand description
Storage backend for the MMR, just needs to be indexed by order of insertion. The PMMR itself does not need the Backend to be accurate on the existence of an element (i.e. remove could be a no-op) but layers above can depend on an accurate Backend to check existence.
Required Methods§
sourcefn append(&mut self, data: &T, hashes: &[Hash]) -> Result<(), String>
fn append(&mut self, data: &T, hashes: &[Hash]) -> Result<(), String>
Append the provided Hashes to the backend storage, and optionally an associated data element to flatfile storage (for leaf nodes only). The position of the first element of the Vec in the MMR is provided to help the implementation.
sourcefn append_pruned_subtree(&mut self, hash: Hash, pos0: u64) -> Result<(), String>
fn append_pruned_subtree(&mut self, hash: Hash, pos0: u64) -> Result<(), String>
Rebuilding a PMMR locally from PIBD segments requires pruned subtree support. This allows us to append an existing pruned subtree directly without the underlying leaf nodes.
sourcefn rewind(&mut self, pos1: u64, rewind_rm_pos: &Bitmap) -> Result<(), String>
fn rewind(&mut self, pos1: u64, rewind_rm_pos: &Bitmap) -> Result<(), String>
Rewind the backend state to a previous position, as if all append operations after that had been canceled. Expects a position in the PMMR to rewind to as well as bitmaps representing the positions added and removed since the rewind position. These are what we will “undo” during the rewind.
sourcefn get_from_file(&self, pos0: u64) -> Option<Hash>
fn get_from_file(&self, pos0: u64) -> Option<Hash>
Get a Hash by original insertion position (ignoring the remove log).
sourcefn get_peak_from_file(&self, pos0: u64) -> Option<Hash>
fn get_peak_from_file(&self, pos0: u64) -> Option<Hash>
Get hash for peak pos. Optimized for reading peak hashes rather than arbitrary pos hashes. Peaks can be assumed to not be compacted.
sourcefn get_data_from_file(&self, pos0: u64) -> Option<T::E>
fn get_data_from_file(&self, pos0: u64) -> Option<T::E>
Get a Data Element by original insertion position (ignoring the remove log).
sourcefn leaf_pos_iter(&self) -> Box<dyn Iterator<Item = u64> + '_>
fn leaf_pos_iter(&self) -> Box<dyn Iterator<Item = u64> + '_>
Iterator over current (unpruned, unremoved) leaf positions.
sourcefn n_unpruned_leaves(&self) -> u64
fn n_unpruned_leaves(&self) -> u64
Number of leaves
sourcefn n_unpruned_leaves_to_index(&self, to_index: u64) -> u64
fn n_unpruned_leaves_to_index(&self, to_index: u64) -> u64
Number of leaves up to the given leaf index
sourcefn 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> + '_>
Iterator over current (unpruned, unremoved) leaf insertion index. Note: This differs from underlying MMR pos - [0, 1, 2, 3, 4] vs. [1, 2, 4, 5, 8].
sourcefn remove(&mut self, position: u64) -> Result<(), String>
fn remove(&mut self, position: u64) -> Result<(), String>
Remove Hash by insertion position. An index is also provided so the underlying backend can implement some rollback of positions up to a given index (practically the index is the height of a block that triggered removal).
sourcefn remove_from_leaf_set(&mut self, pos0: u64)
fn remove_from_leaf_set(&mut self, pos0: u64)
Remove a leaf from the leaf set
sourcefn release_files(&mut self)
fn release_files(&mut self)
Release underlying datafiles and locks
sourcefn reset_prune_list(&mut self)
fn reset_prune_list(&mut self)
Reset prune list, used when PIBD is reset
sourcefn snapshot(&self, header: &BlockHeader) -> Result<(), String>
fn snapshot(&self, header: &BlockHeader) -> Result<(), String>
Saves a snapshot of the rewound utxo file with the block hash as filename suffix. We need this when sending a txhashset zip file to a node for fast sync.
sourcefn dump_stats(&self)
fn dump_stats(&self)
For debugging purposes so we can see how compaction is doing.