Skip to content

Commit 324b055

Browse files
authored
removes blockstore_meta::ErasureMetaStatus (#4310)
We only need a true/false boolean to tell us if we should try to recover the erasure batch or not. The blockstore_meta::ErasureMetaStatus enum is verbose and redundant.
1 parent 5bcdd49 commit 324b055

File tree

2 files changed

+24
-37
lines changed

2 files changed

+24
-37
lines changed

ledger/src/blockstore.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -958,19 +958,19 @@ impl Blockstore {
958958
let slot = erasure_set.slot();
959959
let index_meta_entry = index_working_set.get(&slot).expect("Index");
960960
let index = &index_meta_entry.index;
961-
match erasure_meta.status(index) {
962-
ErasureMetaStatus::CanRecover => self
963-
.recover_shreds(
961+
erasure_meta
962+
.should_recover_shreds(index)
963+
.then(|| {
964+
self.recover_shreds(
964965
index,
965966
erasure_meta,
966967
prev_inserted_shreds,
967968
leader_schedule_cache,
968969
reed_solomon_cache,
969970
)
970-
.ok(),
971-
ErasureMetaStatus::DataFull => None,
972-
ErasureMetaStatus::StillNeed(_) => None,
973-
}
971+
.ok()
972+
})
973+
.flatten()
974974
})
975975
.collect()
976976
}

ledger/src/blockstore_meta.rs

+17-30
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,6 @@ pub struct DuplicateSlotProof {
192192
pub shred2: Vec<u8>,
193193
}
194194

195-
#[derive(Debug, PartialEq, Eq)]
196-
pub enum ErasureMetaStatus {
197-
CanRecover,
198-
DataFull,
199-
StillNeed(usize),
200-
}
201-
202195
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq)]
203196
pub enum FrozenHashVersioned {
204197
Current(FrozenHashStatus),
@@ -439,24 +432,20 @@ impl ErasureMeta {
439432
self.fec_set_index.checked_add(num_data)
440433
}
441434

442-
pub(crate) fn status(&self, index: &Index) -> ErasureMetaStatus {
443-
use ErasureMetaStatus::*;
444-
445-
let num_coding = index.coding().range(self.coding_shreds_indices()).count();
435+
// Returns true if some data shreds are missing, but there are enough data
436+
// and coding shreds to recover the erasure batch.
437+
// TODO: In order to retransmit all shreds from the erasure batch, we need
438+
// to always recover the batch as soon as possible, even if no data shreds
439+
// are missing. But because we currently do not store recovered coding
440+
// shreds into the blockstore we cannot identify if the batch was already
441+
// recovered (and retransmitted) or not.
442+
pub(crate) fn should_recover_shreds(&self, index: &Index) -> bool {
446443
let num_data = index.data().range(self.data_shreds_indices()).count();
447-
448-
let (data_missing, num_needed) = (
449-
self.config.num_data.saturating_sub(num_data),
450-
self.config.num_data.saturating_sub(num_data + num_coding),
451-
);
452-
453-
if data_missing == 0 {
454-
DataFull
455-
} else if num_needed == 0 {
456-
CanRecover
457-
} else {
458-
StillNeed(num_needed)
444+
if num_data >= self.config.num_data {
445+
return false; // No data shreds is missing.
459446
}
447+
let num_coding = index.coding().range(self.coding_shreds_indices()).count();
448+
self.config.num_data <= num_data + num_coding
460449
}
461450

462451
#[cfg(test)]
@@ -600,9 +589,7 @@ mod test {
600589
}
601590

602591
#[test]
603-
fn test_erasure_meta_status() {
604-
use ErasureMetaStatus::*;
605-
592+
fn test_should_recover_shreds() {
606593
let fec_set_index = 0;
607594
let erasure_config = ErasureConfig {
608595
num_data: 8,
@@ -620,13 +607,13 @@ mod test {
620607
let data_indexes = 0..erasure_config.num_data as u64;
621608
let coding_indexes = 0..erasure_config.num_coding as u64;
622609

623-
assert_eq!(e_meta.status(&index), StillNeed(erasure_config.num_data));
610+
assert!(!e_meta.should_recover_shreds(&index));
624611

625612
for ix in data_indexes.clone() {
626613
index.data_mut().insert(ix);
627614
}
628615

629-
assert_eq!(e_meta.status(&index), DataFull);
616+
assert!(!e_meta.should_recover_shreds(&index));
630617

631618
for ix in coding_indexes.clone() {
632619
index.coding_mut().insert(ix);
@@ -639,7 +626,7 @@ mod test {
639626
{
640627
index.data_mut().index.remove(&idx);
641628

642-
assert_eq!(e_meta.status(&index), CanRecover);
629+
assert!(e_meta.should_recover_shreds(&index));
643630
}
644631

645632
for ix in data_indexes {
@@ -652,7 +639,7 @@ mod test {
652639
{
653640
index.coding_mut().index.remove(&idx);
654641

655-
assert_eq!(e_meta.status(&index), DataFull);
642+
assert!(!e_meta.should_recover_shreds(&index));
656643
}
657644
}
658645

0 commit comments

Comments
 (0)