[5.0.x] Fix PIBD segments (#3532) (#3583)

Co-authored-by: jaspervdm <j@sper.dev>
This commit is contained in:
Quentin Le Sceller 2021-03-03 14:36:47 -05:00 committed by GitHub
parent 98e183c8b8
commit 64b2fddbf1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 5 deletions

View file

@ -340,7 +340,7 @@ impl From<BitmapSegment> for Segment<BitmapChunk> {
}
for (block_idx, block) in blocks.into_iter().enumerate() {
assert_eq!(block.inner.len(), BitmapBlock::NBITS as usize);
assert!(block.inner.len() <= BitmapBlock::NBITS as usize);
let offset = block_idx * BitmapBlock::NCHUNKS;
for (i, _) in block.inner.iter().enumerate().filter(|&(_, v)| v) {
chunks
@ -412,7 +412,7 @@ impl Writeable for BitmapBlock {
// Write raw bytes
Writeable::write(&BitmapBlockSerialization::Raw, writer)?;
let bytes = self.inner.to_bytes();
assert_eq!(bytes.len(), Self::NBITS as usize / 8);
assert!(bytes.len() <= Self::NBITS as usize / 8);
writer.write_fixed_bytes(&bytes)?;
}

View file

@ -464,6 +464,7 @@ where
last_pos: u64,
bitmap: Option<&Bitmap>,
mmr_root: Hash,
hash_last_pos: u64,
other_root: Hash,
other_is_left: bool,
) -> Result<(), SegmentError> {
@ -476,6 +477,7 @@ where
last,
segment_root,
segment_unpruned_pos,
hash_last_pos,
other_root,
other_is_left,
)
@ -708,6 +710,7 @@ impl SegmentProof {
segment_last_pos: u64,
segment_root: Hash,
segment_unpruned_pos: u64,
hash_last_pos: u64,
other_root: Hash,
other_is_left: bool,
) -> Result<(), SegmentError> {
@ -719,9 +722,9 @@ impl SegmentProof {
segment_unpruned_pos,
)?;
let root = if other_is_left {
(other_root, root).hash_with_index(last_pos)
(other_root, root).hash_with_index(hash_last_pos)
} else {
(root, other_root).hash_with_index(last_pos)
(root, other_root).hash_with_index(hash_last_pos)
};
if root == mmr_root {
Ok(())

View file

@ -539,7 +539,7 @@ where
hash: Hash,
id: SegmentIdentifier,
) -> Result<Segment<RangeProof>, chain::Error> {
if RANGEPROOF_SEGMENT_HEIGHT_RANGE.contains(&id.height) {
if !RANGEPROOF_SEGMENT_HEIGHT_RANGE.contains(&id.height) {
return Err(chain::ErrorKind::InvalidSegmentHeight.into());
}
let segmenter = self.chain().segmenter()?;