Skip to content

Commit

Permalink
Cleanup usage of legacy bitmaps. (#3455)
Browse files Browse the repository at this point in the history
The legacy bitmaps are no longer required and
have not been in use for a while.
  • Loading branch information
antiochp authored Oct 2, 2020
1 parent f25b7ae commit c3b1ccf
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions chain/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ pub const NRD_KERNEL_LIST_PREFIX: u8 = b'K';
/// Prefix for NRD kernel pos index entries.
pub const NRD_KERNEL_ENTRY_PREFIX: u8 = b'k';

const BLOCK_INPUT_BITMAP_PREFIX: u8 = b'B';
const BLOCK_SUMS_PREFIX: u8 = b'M';
const BLOCK_SPENT_PREFIX: u8 = b'S';

Expand Down Expand Up @@ -319,9 +318,6 @@ impl<'a> Batch<'a> {

/// Delete the block spent index.
fn delete_spent_index(&self, bh: &Hash) -> Result<(), Error> {
// Clean up the legacy input bitmap as well.
let _ = self.db.delete(&to_key(BLOCK_INPUT_BITMAP_PREFIX, bh));

self.db.delete(&to_key(BLOCK_SPENT_PREFIX, bh))
}

Expand All @@ -345,25 +341,12 @@ impl<'a> Batch<'a> {
/// Get the block input bitmap based on our spent index.
/// Fallback to legacy block input bitmap from the db.
pub fn get_block_input_bitmap(&self, bh: &Hash) -> Result<Bitmap, Error> {
if let Ok(spent) = self.get_spent_index(bh) {
let bitmap = spent
.into_iter()
.map(|x| x.pos.try_into().unwrap())
.collect();
Ok(bitmap)
} else {
self.get_legacy_input_bitmap(bh)
}
}

fn get_legacy_input_bitmap(&self, bh: &Hash) -> Result<Bitmap, Error> {
option_to_not_found(
self.db
.get_with(&to_key(BLOCK_INPUT_BITMAP_PREFIX, bh), |data| {
Ok(Bitmap::deserialize(data))
}),
|| "legacy block input bitmap".to_string(),
)
let bitmap = self
.get_spent_index(bh)?
.into_iter()
.map(|x| x.pos.try_into().unwrap())
.collect();
Ok(bitmap)
}

/// Get the "spent index" from the db for the specified block.
Expand Down

0 comments on commit c3b1ccf

Please sign in to comment.