From f1d17a21ddb6a32936e8a37f1b333970d76eacab Mon Sep 17 00:00:00 2001 From: Ashwin Sekar Date: Wed, 29 Nov 2023 16:46:25 +0000 Subject: [PATCH 1/2] blockstore: use u32 for fec_set_index in erasure set index store key --- ledger/src/blockstore.rs | 14 ++++++++------ ledger/src/shred.rs | 8 ++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index 984932a0e08ab7..9728ba0d3b1540 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, fec_set_index as u64)) } 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, fec_set_index as u64), &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..38b8594e0df2d5 100644 --- a/ledger/src/shred.rs +++ b/ledger/src/shred.rs @@ -283,12 +283,8 @@ 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. + pub(crate) fn store_key(&self) -> (Slot, /*fec_set_index:*/ u32) { (self.0, self.1) } } From 2461df42a722c8799e393e42dffcdc8a74d3c45f Mon Sep 17 00:00:00 2001 From: Ashwin Sekar Date: Thu, 30 Nov 2023 21:57:30 +0000 Subject: [PATCH 2/2] pr feedback u64::from --- ledger/src/blockstore.rs | 4 ++-- ledger/src/shred.rs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index 9728ba0d3b1540..3e7c8b9286fea3 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -465,7 +465,7 @@ impl Blockstore { fn erasure_meta(&self, erasure_set: ErasureSetId) -> Result> { let (slot, fec_set_index) = erasure_set.store_key(); - self.erasure_meta_cf.get((slot, fec_set_index as u64)) + self.erasure_meta_cf.get((slot, u64::from(fec_set_index))) } fn merkle_root_meta(&self, erasure_set: ErasureSetId) -> Result> { @@ -1020,7 +1020,7 @@ impl Blockstore { for (erasure_set, erasure_meta) in erasure_metas { let (slot, fec_set_index) = erasure_set.store_key(); - write_batch.put::((slot, fec_set_index as u64), &erasure_meta)?; + write_batch.put::((slot, u64::from(fec_set_index)), &erasure_meta)?; } for (erasure_set, merkle_root_meta) in merkle_root_metas { diff --git a/ledger/src/shred.rs b/ledger/src/shred.rs index 38b8594e0df2d5..5b4d3f70392bfa 100644 --- a/ledger/src/shred.rs +++ b/ledger/src/shred.rs @@ -284,6 +284,7 @@ impl ErasureSetId { } // 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) }