[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() { 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; let offset = block_idx * BitmapBlock::NCHUNKS;
for (i, _) in block.inner.iter().enumerate().filter(|&(_, v)| v) { for (i, _) in block.inner.iter().enumerate().filter(|&(_, v)| v) {
chunks chunks
@ -412,7 +412,7 @@ impl Writeable for BitmapBlock {
// Write raw bytes // Write raw bytes
Writeable::write(&BitmapBlockSerialization::Raw, writer)?; Writeable::write(&BitmapBlockSerialization::Raw, writer)?;
let bytes = self.inner.to_bytes(); 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)?; writer.write_fixed_bytes(&bytes)?;
} }

View file

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

View file

@ -539,7 +539,7 @@ where
hash: Hash, hash: Hash,
id: SegmentIdentifier, id: SegmentIdentifier,
) -> Result<Segment<RangeProof>, chain::Error> { ) -> 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()); return Err(chain::ErrorKind::InvalidSegmentHeight.into());
} }
let segmenter = self.chain().segmenter()?; let segmenter = self.chain().segmenter()?;