[][src]Trait grin_core::core::pmmr::Backend

pub trait Backend<T: PMMRable> {
    fn append(&mut self, data: &T, hashes: Vec<Hash>) -> Result<(), String>;
fn rewind(
        &mut self,
        position: u64,
        rewind_rm_pos: &Bitmap
    ) -> Result<(), String>;
fn get_hash(&self, position: u64) -> Option<Hash>;
fn get_data(&self, position: u64) -> Option<T::E>;
fn get_from_file(&self, position: u64) -> Option<Hash>;
fn get_data_from_file(&self, position: u64) -> Option<T::E>;
fn leaf_pos_iter(&self) -> Box<dyn Iterator<Item = u64>>;
fn remove(&mut self, position: u64) -> Result<(), String>;
fn data_as_temp_file(&self) -> Result<File, String>;
fn release_files(&mut self);
fn snapshot(&self, header: &BlockHeader) -> Result<(), String>;
fn dump_stats(&self); }

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

fn append(&mut self, data: &T, hashes: Vec<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.

fn rewind(
    &mut self,
    position: 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.

fn get_hash(&self, position: u64) -> Option<Hash>

Get a Hash by insertion position.

fn get_data(&self, position: u64) -> Option<T::E>

Get underlying data by insertion position.

fn get_from_file(&self, position: u64) -> Option<Hash>

Get a Hash by original insertion position (ignoring the remove log).

fn get_data_from_file(&self, position: u64) -> Option<T::E>

Get a Data Element by original insertion position (ignoring the remove log).

fn leaf_pos_iter(&self) -> Box<dyn Iterator<Item = u64>>

Iterator over current (unpruned, unremoved) leaf positions.

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).

fn data_as_temp_file(&self) -> Result<File, String>

Creates a temp file containing the contents of the underlying data file from the backend storage. This allows a caller to see a consistent view of the data without needing to lock the backend storage.

fn release_files(&mut self)

Release underlying datafiles and locks

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.

fn dump_stats(&self)

For debugging purposes so we can see how compaction is doing.

Loading content...

Implementors

Loading content...