From d84dcd37bcb6afceb533a3883ec05e048a190903 Mon Sep 17 00:00:00 2001 From: Ashwin Sekar Date: Thu, 30 Nov 2023 19:17:49 -0500 Subject: [PATCH] blockstore: use u32 for fec_set_index in erasure set index store key (#34268) * blockstore: use u32 for fec_set_index in erasure set index store key * pr feedback u64::from --- ledger/src/blockstore.rs | 14 ++++++++------ ledger/src/shred.rs | 9 +++------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index 984932a0e08ab7..3e7c8b9286fea3 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -464,11 +464,12 @@ impl Blockstore { } fn erasure_meta(&self, erasure_set: ErasureSetId) -> Result> { - 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> { - 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 @@ -1018,11 +1019,12 @@ impl Blockstore { )?; for (erasure_set, erasure_meta) in erasure_metas { - write_batch.put::(erasure_set.store_key(), &erasure_meta)?; + let (slot, fec_set_index) = erasure_set.store_key(); + write_batch.put::((slot, u64::from(fec_set_index)), &erasure_meta)?; } for (erasure_set, merkle_root_meta) in merkle_root_metas { - write_batch.put::(erasure_set.key(), &merkle_root_meta)?; + write_batch.put::(erasure_set.store_key(), &merkle_root_meta)?; } for (&slot, index_working_set_entry) in index_working_set.iter() { @@ -6828,7 +6830,7 @@ pub mod tests { for (erasure_set, merkle_root_meta) in merkle_root_metas { write_batch - .put::(erasure_set.key(), &merkle_root_meta) + .put::(erasure_set.store_key(), &merkle_root_meta) .unwrap(); } blockstore.db.write(write_batch).unwrap(); @@ -7008,7 +7010,7 @@ pub mod tests { for (erasure_set, merkle_root_meta) in merkle_root_metas { write_batch - .put::(erasure_set.key(), &merkle_root_meta) + .put::(erasure_set.store_key(), &merkle_root_meta) .unwrap(); } blockstore.db.write(write_batch).unwrap(); diff --git a/ledger/src/shred.rs b/ledger/src/shred.rs index b3000d69b773c3..5b4d3f70392bfa 100644 --- a/ledger/src/shred.rs +++ b/ledger/src/shred.rs @@ -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) } }