[PIBD] PMMR Desegmenter Structure (Pt. 1) (#3667)
* initial commit of WIP pibd explorations * correct calling for obtaining and validating first segment * update test to properly iterate through each segment of the test pmmrs, validating each segment as it goes * updated test to fully segment and validate PMMRs from compacted and uncompacted sample data. Also contains method of running test againt live chain data * remove logger change * change test file name * change test file name * change directory reference in test for CI * add initial (experimental) structure for PIBD desegmenting * move bitmap desegmentation logic into desegmenter * added txhashset methods to apply pibd segments (note this only works for fully unpruned trees atm) * change last_pos to mmr_size * fix to pmmr::peaks call * don't verify POW when copying headers * prepare for commit of work thus far' * update test paths * few updates based on early review
This commit is contained in:
@@ -87,7 +87,8 @@ impl SegmentIdentifier {
|
||||
/// Returns number of segments required that would needed in order to read a
|
||||
/// pmmr of size `target_mmr_size` in segments of height `segment_height`
|
||||
pub fn count_segments_required(target_mmr_size: u64, segment_height: u8) -> usize {
|
||||
pmmr::n_leaves(target_mmr_size) as usize / (1 << segment_height as usize)
|
||||
let d = 1 << segment_height;
|
||||
((pmmr::n_leaves(target_mmr_size) + d - 1) / d) as usize
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,17 +127,17 @@ impl<T> Segment<T> {
|
||||
self.identifier.idx * self.segment_capacity()
|
||||
}
|
||||
|
||||
/// Number of leaves in this segment. Equal to capacity except for the final segment, which can be smaller
|
||||
fn segment_unpruned_size(&self, last_pos: u64) -> u64 {
|
||||
// Number of leaves in this segment. Equal to capacity except for the final segment, which can be smaller
|
||||
fn segment_unpruned_size(&self, mmr_size: u64) -> u64 {
|
||||
min(
|
||||
self.segment_capacity(),
|
||||
pmmr::n_leaves(last_pos).saturating_sub(self.leaf_offset()),
|
||||
pmmr::n_leaves(mmr_size).saturating_sub(self.leaf_offset()),
|
||||
)
|
||||
}
|
||||
|
||||
/// Whether the segment is full (segment size == capacity)
|
||||
fn full_segment(&self, last_pos: u64) -> bool {
|
||||
self.segment_unpruned_size(last_pos) == self.segment_capacity()
|
||||
fn full_segment(&self, mmr_size: u64) -> bool {
|
||||
self.segment_unpruned_size(mmr_size) == self.segment_capacity()
|
||||
}
|
||||
|
||||
/// Inclusive range of MMR positions for this segment
|
||||
|
||||
Reference in New Issue
Block a user