Skip to content

Commit

Permalink
[5.0.x] Fix PIBD segments (#3532)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspervdm committed Dec 23, 2020
1 parent 8302f23 commit 49f0f3b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions chain/src/txhashset/bitmap_accumulator.rs
Expand Up @@ -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
Expand Down Expand Up @@ -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)?;
}

Expand Down
7 changes: 5 additions & 2 deletions core/src/core/pmmr/segment.rs
Expand Up @@ -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> {
Expand All @@ -476,6 +477,7 @@ where
last,
segment_root,
segment_unpruned_pos,
hash_last_pos,
other_root,
other_is_left,
)
Expand Down Expand Up @@ -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> {
Expand All @@ -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(())
Expand Down
2 changes: 1 addition & 1 deletion servers/src/common/adapters.rs
Expand Up @@ -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()?;
Expand Down

0 comments on commit 49f0f3b

Please sign in to comment.