Struct grin_store::pmmr::PMMRBackend
source · pub struct PMMRBackend<T: PMMRable> { /* private fields */ }
Expand description
PMMR persistent backend implementation. Relies on multiple facilities to handle writing, reading and pruning.
- A main storage file appends Hash instances as they come. This AppendOnlyFile is also backed by a mmap for reads.
- An in-memory backend buffers the latest batch of writes to ensure the PMMR can always read recent values even if they haven’t been flushed to disk yet.
- A leaf_set tracks unpruned (unremoved) leaf positions in the MMR..
- A prune_list tracks the positions of pruned (and compacted) roots in the MMR.
Implementations§
source§impl<T: PMMRable> PMMRBackend<T>
impl<T: PMMRable> PMMRBackend<T>
sourcepub fn new<P: AsRef<Path>>(
data_dir: P,
prunable: bool,
version: ProtocolVersion,
header: Option<&BlockHeader>
) -> Result<PMMRBackend<T>>
pub fn new<P: AsRef<Path>>( data_dir: P, prunable: bool, version: ProtocolVersion, header: Option<&BlockHeader> ) -> Result<PMMRBackend<T>>
Instantiates a new PMMR backend. If optional size is provided then treat as “fixed” size otherwise “variable” size backend. Use the provided dir to store its files.
sourcepub fn unpruned_size(&self) -> u64
pub fn unpruned_size(&self) -> u64
Number of hashes in the PMMR stored by this backend. Only produces the fully sync’d size.
sourcepub fn data_size(&self) -> u64
pub fn data_size(&self) -> u64
Number of elements in the underlying stored data. Extremely dependent on pruning and compaction.
sourcepub fn hash_size(&self) -> u64
pub fn hash_size(&self) -> u64
Size of the underlying hashed data. Extremely dependent on pruning and compaction.
sourcepub fn sync(&mut self) -> Result<()>
pub fn sync(&mut self) -> Result<()>
Syncs all files to disk. A call to sync is required to ensure all the data has been successfully written to disk.
sourcepub fn check_compact(
&mut self,
cutoff_pos: u64,
rewind_rm_pos: &Bitmap
) -> Result<bool>
pub fn check_compact( &mut self, cutoff_pos: u64, rewind_rm_pos: &Bitmap ) -> Result<bool>
Takes the leaf_set at a given cutoff_pos and generates an updated prune_list. Saves the updated prune_list to disk, compacts the hash and data files based on the prune_list and saves both to disk.
A cutoff position limits compaction on recent data. This will be the last position of a particular block to keep things aligned. The block_marker in the db/index for the particular block will have a suitable output_pos. This is used to enforce a horizon after which the local node should have all the data to allow rewinding.
Trait Implementations§
source§impl<T: PMMRable> Backend<T> for PMMRBackend<T>
impl<T: PMMRable> Backend<T> for PMMRBackend<T>
source§fn append(&mut self, data: &T, hashes: &[Hash]) -> Result<(), String>
fn append(&mut self, data: &T, hashes: &[Hash]) -> Result<(), String>
Append the provided data and hashes to the backend storage. Add the new leaf pos to our leaf_set if this is a prunable MMR.
source§fn get_hash(&self, pos0: u64) -> Option<Hash>
fn get_hash(&self, pos0: u64) -> Option<Hash>
Get the hash at pos. Return None if pos is a leaf and it has been removed (or pruned or compacted).
source§fn get_data(&self, pos0: u64) -> Option<T::E>
fn get_data(&self, pos0: u64) -> Option<T::E>
Get the data at pos. Return None if it has been removed or if pos is not a leaf node.
source§fn remove_from_leaf_set(&mut self, pos0: u64)
fn remove_from_leaf_set(&mut self, pos0: u64)
Remove leaf from leaf set
source§fn leaf_pos_iter(&self) -> Box<dyn Iterator<Item = u64> + '_>
fn leaf_pos_iter(&self) -> Box<dyn Iterator<Item = u64> + '_>
Returns an iterator over all the leaf positions. for a prunable PMMR this is an iterator over the leaf_set bitmap. For a non-prunable PMMR this is all leaves (this is not yet implemented).
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> + '_>
Returns an iterator over all the leaf insertion indices (0-indexed). If our pos are [1,2,4,5,8] (first 5 leaf pos) then our insertion indices are [0,1,2,3,4]
source§fn rewind(
&mut self,
position: u64,
rewind_rm_pos: &Bitmap
) -> Result<(), String>
fn rewind( &mut self, position: u64, rewind_rm_pos: &Bitmap ) -> Result<(), String>
Rewind the PMMR backend to the given position.
source§fn release_files(&mut self)
fn release_files(&mut self)
Release underlying data files