pub struct BitmapAccumulator { /* private fields */ }Expand description
The “bitmap accumulator” allows us to commit to a specific bitmap by splitting it into fragments and inserting these fragments into an MMR to produce an overall root hash. Leaves in the MMR are fragments of the bitmap consisting of 1024 contiguous bits from the overall bitmap. The first (leftmost) leaf in the MMR represents the first 1024 bits of the bitmap, the next leaf is the next 1024 bits of the bitmap etc.
Flipping a single bit does not require the full bitmap to be rehashed, only the path from the relevant leaf up to its associated peak.
Flipping multiple bits within a single chunk is no more expensive than flipping a single bit as a leaf node in the MMR represents a sequence of 1024 bits. Flipping multiple bits located close together is a relatively cheap operation with minimal rehashing required to update the relevant peaks and the overall MMR root.
It is also possible to generate Merkle proofs for these 1024 bit fragments, proving both inclusion and location in the overall “accumulator” MMR. We plan to take advantage of this during fast sync, allowing for validation of partial data.
Implementations§
Source§impl BitmapAccumulator
impl BitmapAccumulator
Sourcepub fn new() -> BitmapAccumulator
pub fn new() -> BitmapAccumulator
Crate a new empty bitmap accumulator.
Sourcepub fn init<T: IntoIterator<Item = u64>>(
&mut self,
idx: T,
size: u64,
) -> Result<(), Error>
pub fn init<T: IntoIterator<Item = u64>>( &mut self, idx: T, size: u64, ) -> Result<(), Error>
Initialize a bitmap accumulator given the provided idx iterator.
Sourcepub fn chunk_start_idx(idx: u64) -> u64
pub fn chunk_start_idx(idx: u64) -> u64
Find the start of the first “chunk” of 1024 bits from the provided idx. Zero the last 10 bits to round down to multiple of 1024.
Sourcepub fn apply<T, U>(
&mut self,
invalidated_idx: T,
idx: U,
size: u64,
) -> Result<(), Error>
pub fn apply<T, U>( &mut self, invalidated_idx: T, idx: U, size: u64, ) -> Result<(), Error>
Apply updates to the bitmap accumulator given an iterator of invalidated idx and an iterator of idx to be set to true. We determine the existing chunks to be rebuilt given the invalidated idx. We then rebuild given idx, extending the accumulator with new chunk(s) as necessary. Resulting bitmap accumulator will contain sufficient bitmap chunks to cover size. If size is 1 then we will have a single chunk. If size is 1023 then we will have a single chunk (bits 0 to 1023 inclusive). If the size is 1024 then we will have two chunks. TODO: first argument is an iterator for no good reason; might as well pass from_idx as first argument
Sourcepub fn append_chunk(&mut self, chunk: BitmapChunk) -> Result<u64, Error>
pub fn append_chunk(&mut self, chunk: BitmapChunk) -> Result<u64, Error>
Append a new chunk to the BitmapAccumulator. Append parent hashes (if any) as necessary to build associated peak.
Sourcepub fn readonly_pmmr(
&self,
) -> ReadonlyPMMR<'_, BitmapChunk, VecBackend<BitmapChunk>>
pub fn readonly_pmmr( &self, ) -> ReadonlyPMMR<'_, BitmapChunk, VecBackend<BitmapChunk>>
Readonly access to our internal data.
Trait Implementations§
Source§impl Clone for BitmapAccumulator
impl Clone for BitmapAccumulator
Source§fn clone(&self) -> BitmapAccumulator
fn clone(&self) -> BitmapAccumulator
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for BitmapAccumulator
impl RefUnwindSafe for BitmapAccumulator
impl Send for BitmapAccumulator
impl Sync for BitmapAccumulator
impl Unpin for BitmapAccumulator
impl UnwindSafe for BitmapAccumulator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<'a, T> DefaultFeatures<'a> for T
impl<'a, T> DefaultFeatures<'a> for T
Source§fn clone_boxed(&self) -> Box<dyn DefaultFeatures<'a>>
fn clone_boxed(&self) -> Box<dyn DefaultFeatures<'a>>
Box
behind a trait object of this trait.Source§impl<'a, T> NonSyncFeatures<'a> for Twhere
T: 'a + Clone,
impl<'a, T> NonSyncFeatures<'a> for Twhere
T: 'a + Clone,
Source§fn clone_boxed(&self) -> Box<dyn NonSyncFeatures<'a>>
fn clone_boxed(&self) -> Box<dyn NonSyncFeatures<'a>>
Box
behind a trait object of this trait.