Skip to content

Commit

Permalink
blockstore: use u32 for fec_set_index in erasure set index store key (#…
Browse files Browse the repository at this point in the history
…34268)

* blockstore: use u32 for fec_set_index in erasure set index store key

* pr feedback u64::from
  • Loading branch information
AshwinSekar authored Dec 1, 2023
1 parent 18309ba commit d84dcd3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
14 changes: 8 additions & 6 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,11 +464,12 @@ impl Blockstore {
}

fn erasure_meta(&self, erasure_set: ErasureSetId) -> Result<Option<ErasureMeta>> {
self.erasure_meta_cf.get(erasure_set.store_key())
let (slot, fec_set_index) = erasure_set.store_key();
self.erasure_meta_cf.get((slot, u64::from(fec_set_index)))
}

fn merkle_root_meta(&self, erasure_set: ErasureSetId) -> Result<Option<MerkleRootMeta>> {
self.merkle_root_meta_cf.get(erasure_set.key())
self.merkle_root_meta_cf.get(erasure_set.store_key())
}

/// Check whether the specified slot is an orphan slot which does not
Expand Down Expand Up @@ -1018,11 +1019,12 @@ impl Blockstore {
)?;

for (erasure_set, erasure_meta) in erasure_metas {
write_batch.put::<cf::ErasureMeta>(erasure_set.store_key(), &erasure_meta)?;
let (slot, fec_set_index) = erasure_set.store_key();
write_batch.put::<cf::ErasureMeta>((slot, u64::from(fec_set_index)), &erasure_meta)?;
}

for (erasure_set, merkle_root_meta) in merkle_root_metas {
write_batch.put::<cf::MerkleRootMeta>(erasure_set.key(), &merkle_root_meta)?;
write_batch.put::<cf::MerkleRootMeta>(erasure_set.store_key(), &merkle_root_meta)?;
}

for (&slot, index_working_set_entry) in index_working_set.iter() {
Expand Down Expand Up @@ -6828,7 +6830,7 @@ pub mod tests {

for (erasure_set, merkle_root_meta) in merkle_root_metas {
write_batch
.put::<cf::MerkleRootMeta>(erasure_set.key(), &merkle_root_meta)
.put::<cf::MerkleRootMeta>(erasure_set.store_key(), &merkle_root_meta)
.unwrap();
}
blockstore.db.write(write_batch).unwrap();
Expand Down Expand Up @@ -7008,7 +7010,7 @@ pub mod tests {

for (erasure_set, merkle_root_meta) in merkle_root_metas {
write_batch
.put::<cf::MerkleRootMeta>(erasure_set.key(), &merkle_root_meta)
.put::<cf::MerkleRootMeta>(erasure_set.store_key(), &merkle_root_meta)
.unwrap();
}
blockstore.db.write(write_batch).unwrap();
Expand Down
9 changes: 3 additions & 6 deletions ledger/src/shred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,9 @@ impl ErasureSetId {
self.0
}

// Storage key for ErasureMeta in blockstore db.
pub(crate) fn store_key(&self) -> (Slot, /*fec_set_index:*/ u64) {
(self.0, u64::from(self.1))
}

pub(crate) fn key(&self) -> (Slot, /*fec_set_index:*/ u32) {
// Storage key for ErasureMeta and MerkleRootMeta in blockstore db.
// Note: ErasureMeta column uses u64 so this will need to be typecast
pub(crate) fn store_key(&self) -> (Slot, /*fec_set_index:*/ u32) {
(self.0, self.1)
}
}
Expand Down

0 comments on commit d84dcd3

Please sign in to comment.