mimblewimble / grin

Minimal implementation of the Mimblewimble protocol.
https://grin.mw/
Apache License 2.0
5.04k stars 990 forks source link

Prune list iterators #3574

Closed antiochp closed 3 years ago

antiochp commented 3 years ago

~We want to merge #3576 and #3575 before we merge this.~ ~Likely to be some conflicts as I pulled those changes out as separate PRs.~


Lets us do the following -

  let bitmap: Bitmap = prune_list
    .unpruned_leaf_iter(cutoff_pos)
    .collect();

Which is a really convenient way of producing a bitmap representing unpruned leaf positions based on a prune_list. This in effect "inverts" the prune_list giving the leaves that remain after pruning.

We can take advantage of this for more efficient pruning/compaction.

It is possible to efficiently compute the difference between what was pruned last time and what needs to be pruned this time -

20210224 09:17:13.613 DEBUG grin_store::pmmr - ***** prev_leaf_bitmap: 209732
20210224 09:17:13.616 DEBUG grin_store::pmmr - ***** next_leaf_bitmap: 196498
20210224 09:17:13.616 DEBUG grin_store::pmmr - ***** diff between bitmaps: 15467