[][src]Struct grin_chain::txhashset::BitmapAccumulator

pub struct BitmapAccumulator { /* fields omitted */ }

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.

Methods

impl BitmapAccumulator[src]

pub fn new() -> BitmapAccumulator[src]

Crate a new empty bitmap accumulator.

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

Initialize a bitmap accumulator given the provided idx iterator.

pub fn chunk_start_idx(idx: u64) -> u64[src]

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.

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>, 
[src]

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.

pub fn append_chunk(&mut self, chunk: BitmapChunk) -> Result<u64, Error>[src]

Append a new chunk to the BitmapAccumulator. Append parent hashes (if any) as necessary to build associated peak.

pub fn root(&self) -> Hash[src]

The root hash of the bitmap accumulator MMR.

Trait Implementations

impl Clone for BitmapAccumulator[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

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

impl<T> Erased for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

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

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

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> UnsafeAny for T where
    T: Any

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,