Struct BitmapAccumulator

Source
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

Source

pub fn new() -> BitmapAccumulator

Crate a new empty bitmap accumulator.

Source

pub fn init<T: IntoIterator<Item = u64>>( &mut self, idx: T, size: u64, ) -> Result<(), Error>

Initialize a bitmap accumulator given the provided idx iterator.

Source

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.

Source

pub fn apply<T, U>( &mut self, invalidated_idx: T, idx: U, size: u64, ) -> Result<(), Error>
where T: IntoIterator<Item = u64>, U: IntoIterator<Item = u64>,

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

Source

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.

Source

pub fn root(&self) -> Hash

The root hash of the bitmap accumulator MMR.

Source

pub fn readonly_pmmr( &self, ) -> ReadonlyPMMR<'_, BitmapChunk, VecBackend<BitmapChunk>>

Readonly access to our internal data.

Source

pub fn as_bitmap(&self) -> Result<Bitmap, Error>

Return a raw in-memory bitmap of this accumulator

Trait Implementations§

Source§

impl Clone for BitmapAccumulator

Source§

fn clone(&self) -> BitmapAccumulator

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneAny for T
where T: Any + Clone,

Source§

fn clone_any(&self) -> Box<dyn CloneAny>

Source§

fn clone_any_send(&self) -> Box<dyn CloneAny + Send>
where T: Send,

Source§

fn clone_any_sync(&self) -> Box<dyn CloneAny + Sync>
where T: Sync,

Source§

fn clone_any_send_sync(&self) -> Box<dyn CloneAny + Sync + Send>
where T: Send + Sync,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<'a, T> DefaultFeatures<'a> for T
where T: 'a + Send + Sync + Clone,

Source§

fn clone_boxed(&self) -> Box<dyn DefaultFeatures<'a>>

Clone this value, and then immediately put it into a Box behind a trait object of this trait.
Source§

fn self_address_mut(&mut self) -> *mut ()

Returns the address of self. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<'a, T> NonSyncFeatures<'a> for T
where T: 'a + Clone,

Source§

fn clone_boxed(&self) -> Box<dyn NonSyncFeatures<'a>>

Clone this value, and then immediately put it into a Box behind a trait object of this trait.
Source§

fn self_address_mut(&mut self) -> *mut ()

Returns the address of self. Read more
Source§

impl<T> SafeBorrow<T> for T
where T: ?Sized,

Source§

fn borrow_replacement(ptr: &T) -> &T

Given ptr, which was obtained from a prior call to Self::borrow(), return a value with the same nominal lifetime which is guaranteed to survive mutations to Self. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnsafeAny for T
where T: Any,