@@ -104,6 +104,7 @@ pub(crate) fn aggregate_restart_last_voted_fork_slots(
104
104
cluster_info : Arc < ClusterInfo > ,
105
105
last_voted_fork_slots : & Vec < Slot > ,
106
106
bank_forks : Arc < RwLock < BankForks > > ,
107
+ blockstore : Arc < Blockstore > ,
107
108
wen_restart_repair_slots : Arc < RwLock < Vec < Slot > > > ,
108
109
exit : Arc < AtomicBool > ,
109
110
progress : & mut WenRestartProgress ,
@@ -160,20 +161,18 @@ pub(crate) fn aggregate_restart_last_voted_fork_slots(
160
161
let active_percent = last_voted_fork_slots_aggregate. active_percent ( ) ;
161
162
let mut filtered_slots: Vec < Slot > ;
162
163
{
163
- let my_bank_forks = bank_forks. read ( ) . unwrap ( ) ;
164
164
filtered_slots = last_voted_fork_slots_aggregate
165
165
. slots_to_repair_iter ( )
166
166
. filter ( |slot| {
167
167
if * slot <= & root_slot || is_full_slots. contains ( * slot) {
168
168
return false ;
169
169
}
170
- let is_full = my_bank_forks
171
- . get ( * * slot)
172
- . map_or ( false , |bank| bank. is_frozen ( ) ) ;
173
- if is_full {
170
+ if blockstore. is_full ( * * slot) {
174
171
is_full_slots. insert ( * * slot) ;
172
+ false
173
+ } else {
174
+ true
175
175
}
176
- !is_full
177
176
} )
178
177
. cloned ( )
179
178
. collect ( ) ;
@@ -234,6 +233,7 @@ pub fn wait_for_wen_restart(
234
233
cluster_info. clone ( ) ,
235
234
last_voted_fork_slots,
236
235
bank_forks. clone ( ) ,
236
+ blockstore. clone ( ) ,
237
237
wen_restart_repair_slots. clone ( ) . unwrap ( ) ,
238
238
exit. clone ( ) ,
239
239
& mut progress,
@@ -382,7 +382,6 @@ mod tests {
382
382
use {
383
383
crate :: wen_restart:: * ,
384
384
assert_matches:: assert_matches,
385
- solana_entry:: entry,
386
385
solana_gossip:: {
387
386
cluster_info:: ClusterInfo ,
388
387
contact_info:: ContactInfo ,
@@ -391,7 +390,10 @@ mod tests {
391
390
legacy_contact_info:: LegacyContactInfo ,
392
391
restart_crds_values:: RestartLastVotedForkSlots ,
393
392
} ,
394
- solana_ledger:: { blockstore, get_tmp_ledger_path_auto_delete} ,
393
+ solana_ledger:: {
394
+ blockstore:: { make_chaining_slot_entries, Blockstore } ,
395
+ get_tmp_ledger_path_auto_delete,
396
+ } ,
395
397
solana_program:: {
396
398
hash:: Hash ,
397
399
vote:: state:: { Vote , VoteStateUpdate } ,
@@ -403,7 +405,6 @@ mod tests {
403
405
} ,
404
406
} ,
405
407
solana_sdk:: {
406
- pubkey:: Pubkey ,
407
408
signature:: { Keypair , Signer } ,
408
409
timing:: timestamp,
409
410
} ,
@@ -454,6 +455,16 @@ mod tests {
454
455
pub wen_restart_proto_path : PathBuf ,
455
456
}
456
457
458
+ fn insert_slots_into_blockstore (
459
+ blockstore : Arc < Blockstore > ,
460
+ first_parent : Slot ,
461
+ slots_to_insert : & [ Slot ] ,
462
+ ) {
463
+ for ( shreds, _) in make_chaining_slot_entries ( slots_to_insert, 2 , first_parent) {
464
+ blockstore. insert_shreds ( shreds, None , false ) . unwrap ( ) ;
465
+ }
466
+ }
467
+
457
468
fn wen_restart_test_init ( ledger_path : & TempDir ) -> WenRestartTestInitResult {
458
469
let validator_voting_keypairs: Vec < _ > =
459
470
( 0 ..10 ) . map ( |_| ValidatorVoteKeypairs :: new_rand ( ) ) . collect ( ) ;
@@ -468,7 +479,7 @@ mod tests {
468
479
node_keypair. clone ( ) ,
469
480
SocketAddrSpace :: Unspecified ,
470
481
) ) ;
471
- let blockstore = Arc :: new ( blockstore :: Blockstore :: open ( ledger_path. path ( ) ) . unwrap ( ) ) ;
482
+ let blockstore = Arc :: new ( Blockstore :: open ( ledger_path. path ( ) ) . unwrap ( ) ) ;
472
483
let GenesisConfigInfo { genesis_config, .. } = create_genesis_config_with_vote_accounts (
473
484
10_000 ,
474
485
& validator_voting_keypairs,
@@ -479,42 +490,16 @@ mod tests {
479
490
. try_into ( )
480
491
. unwrap ( ) ;
481
492
let mut last_voted_fork_slots = Vec :: new ( ) ;
493
+ last_voted_fork_slots. extend ( [ 1 , last_parent] ) ;
482
494
for i in 0 ..EXPECTED_SLOTS {
483
- let entries = entry:: create_ticks ( 1 , 0 , Hash :: default ( ) ) ;
484
- let parent_slot = if i > 0 {
485
- ( RestartLastVotedForkSlots :: MAX_SLOTS . saturating_add ( i) )
486
- . try_into ( )
487
- . unwrap ( )
488
- } else {
489
- last_parent
490
- } ;
491
- let slot = ( RestartLastVotedForkSlots :: MAX_SLOTS
492
- . saturating_add ( i)
493
- . saturating_add ( 1 ) ) as Slot ;
494
- let shreds = blockstore:: entries_to_test_shreds (
495
- & entries,
496
- slot,
497
- parent_slot,
498
- false ,
499
- 0 ,
500
- true , // merkle_variant
495
+ last_voted_fork_slots. push (
496
+ ( RestartLastVotedForkSlots :: MAX_SLOTS
497
+ . saturating_add ( i)
498
+ . saturating_add ( 1 ) ) as Slot ,
501
499
) ;
502
- blockstore. insert_shreds ( shreds, None , false ) . unwrap ( ) ;
503
- last_voted_fork_slots. push ( slot) ;
504
500
}
505
- // link directly to slot 1 whose distance to last_vote > RestartLastVotedForkSlots::MAX_SLOTS so it will not be included.
506
- let entries = entry:: create_ticks ( 1 , 0 , Hash :: default ( ) ) ;
507
- let shreds = blockstore:: entries_to_test_shreds (
508
- & entries,
509
- last_parent,
510
- 1 ,
511
- false ,
512
- 0 ,
513
- true , // merkle_variant
514
- ) ;
515
- last_voted_fork_slots. extend ( [ last_parent, 1 ] ) ;
516
- blockstore. insert_shreds ( shreds, None , false ) . unwrap ( ) ;
517
- last_voted_fork_slots. sort ( ) ;
501
+ insert_slots_into_blockstore ( blockstore. clone ( ) , 0 , & last_voted_fork_slots) ;
502
+ last_voted_fork_slots. insert ( 0 , 0 ) ;
518
503
last_voted_fork_slots. reverse ( ) ;
519
504
let mut wen_restart_proto_path = ledger_path. path ( ) . to_path_buf ( ) ;
520
505
wen_restart_proto_path. push ( "wen_restart_status.proto" ) ;
@@ -599,23 +584,6 @@ mod tests {
599
584
let _ = remove_file ( & test_state. wen_restart_proto_path ) ;
600
585
}
601
586
602
- fn insert_and_freeze_slots (
603
- bank_forks : Arc < RwLock < BankForks > > ,
604
- expected_slots_to_repair : Vec < Slot > ,
605
- ) {
606
- let mut parent_bank = bank_forks. read ( ) . unwrap ( ) . root_bank ( ) ;
607
- for slot in expected_slots_to_repair {
608
- let mut bank_forks_rw = bank_forks. write ( ) . unwrap ( ) ;
609
- bank_forks_rw. insert ( Bank :: new_from_parent (
610
- parent_bank. clone ( ) ,
611
- & Pubkey :: default ( ) ,
612
- slot,
613
- ) ) ;
614
- parent_bank = bank_forks_rw. get ( slot) . unwrap ( ) ;
615
- parent_bank. freeze ( ) ;
616
- }
617
- }
618
-
619
587
#[ test]
620
588
fn test_wen_restart_normal_flow ( ) {
621
589
let ledger_path = get_tmp_ledger_path_auto_delete ! ( ) ;
@@ -673,7 +641,11 @@ mod tests {
673
641
}
674
642
675
643
// Simulating successful repair of missing blocks.
676
- insert_and_freeze_slots ( test_state. bank_forks . clone ( ) , expected_slots_to_repair) ;
644
+ insert_slots_into_blockstore (
645
+ test_state. blockstore . clone ( ) ,
646
+ last_vote_slot,
647
+ & expected_slots_to_repair,
648
+ ) ;
677
649
678
650
let _ = wen_restart_thread_handle. join ( ) ;
679
651
let progress = read_wen_restart_records ( & test_state. wen_restart_proto_path ) . unwrap ( ) ;
@@ -934,6 +906,7 @@ mod tests {
934
906
let wen_restart_proto_path_clone = test_state. wen_restart_proto_path . clone ( ) ;
935
907
let cluster_info_clone = test_state. cluster_info . clone ( ) ;
936
908
let bank_forks_clone = test_state. bank_forks . clone ( ) ;
909
+ let blockstore_clone = test_state. blockstore . clone ( ) ;
937
910
let exit = Arc :: new ( AtomicBool :: new ( false ) ) ;
938
911
let exit_clone = exit. clone ( ) ;
939
912
let mut progress_clone = progress. clone ( ) ;
@@ -947,6 +920,7 @@ mod tests {
947
920
cluster_info_clone,
948
921
& last_voted_fork_slots,
949
922
bank_forks_clone,
923
+ blockstore_clone,
950
924
Arc :: new ( RwLock :: new ( Vec :: new ( ) ) ) ,
951
925
exit_clone,
952
926
& mut progress_clone,
@@ -995,7 +969,11 @@ mod tests {
995
969
}
996
970
997
971
// Simulating successful repair of missing blocks.
998
- insert_and_freeze_slots ( test_state. bank_forks . clone ( ) , expected_slots_to_repair) ;
972
+ insert_slots_into_blockstore (
973
+ test_state. blockstore . clone ( ) ,
974
+ last_vote_slot,
975
+ & expected_slots_to_repair,
976
+ ) ;
999
977
1000
978
let last_voted_fork_slots = test_state. last_voted_fork_slots . clone ( ) ;
1001
979
wen_restart_test_succeed_after_failure (
0 commit comments