@@ -192,13 +192,6 @@ pub struct DuplicateSlotProof {
192
192
pub shred2 : Vec < u8 > ,
193
193
}
194
194
195
- #[ derive( Debug , PartialEq , Eq ) ]
196
- pub enum ErasureMetaStatus {
197
- CanRecover ,
198
- DataFull ,
199
- StillNeed ( usize ) ,
200
- }
201
-
202
195
#[ derive( Deserialize , Serialize , Debug , PartialEq , Eq ) ]
203
196
pub enum FrozenHashVersioned {
204
197
Current ( FrozenHashStatus ) ,
@@ -439,24 +432,20 @@ impl ErasureMeta {
439
432
self . fec_set_index . checked_add ( num_data)
440
433
}
441
434
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 {
446
443
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.
459
446
}
447
+ let num_coding = index. coding ( ) . range ( self . coding_shreds_indices ( ) ) . count ( ) ;
448
+ self . config . num_data <= num_data + num_coding
460
449
}
461
450
462
451
#[ cfg( test) ]
@@ -600,9 +589,7 @@ mod test {
600
589
}
601
590
602
591
#[ test]
603
- fn test_erasure_meta_status ( ) {
604
- use ErasureMetaStatus :: * ;
605
-
592
+ fn test_should_recover_shreds ( ) {
606
593
let fec_set_index = 0 ;
607
594
let erasure_config = ErasureConfig {
608
595
num_data : 8 ,
@@ -620,13 +607,13 @@ mod test {
620
607
let data_indexes = 0 ..erasure_config. num_data as u64 ;
621
608
let coding_indexes = 0 ..erasure_config. num_coding as u64 ;
622
609
623
- assert_eq ! ( e_meta. status ( & index) , StillNeed ( erasure_config . num_data ) ) ;
610
+ assert ! ( ! e_meta. should_recover_shreds ( & index) ) ;
624
611
625
612
for ix in data_indexes. clone ( ) {
626
613
index. data_mut ( ) . insert ( ix) ;
627
614
}
628
615
629
- assert_eq ! ( e_meta. status ( & index) , DataFull ) ;
616
+ assert ! ( ! e_meta. should_recover_shreds ( & index) ) ;
630
617
631
618
for ix in coding_indexes. clone ( ) {
632
619
index. coding_mut ( ) . insert ( ix) ;
@@ -639,7 +626,7 @@ mod test {
639
626
{
640
627
index. data_mut ( ) . index . remove ( & idx) ;
641
628
642
- assert_eq ! ( e_meta. status ( & index) , CanRecover ) ;
629
+ assert ! ( e_meta. should_recover_shreds ( & index) ) ;
643
630
}
644
631
645
632
for ix in data_indexes {
@@ -652,7 +639,7 @@ mod test {
652
639
{
653
640
index. coding_mut ( ) . index . remove ( & idx) ;
654
641
655
- assert_eq ! ( e_meta. status ( & index) , DataFull ) ;
642
+ assert ! ( ! e_meta. should_recover_shreds ( & index) ) ;
656
643
}
657
644
}
658
645
0 commit comments