Skip to content

Commit f9e88d2

Browse files
committed
update test
1 parent cd3f151 commit f9e88d2

File tree

2 files changed

+68
-10
lines changed

2 files changed

+68
-10
lines changed

core/src/replay_stage.rs

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4527,7 +4527,9 @@ pub(crate) mod tests {
45274527
replay_stage::ReplayStage,
45284528
vote_simulator::{self, VoteSimulator},
45294529
},
4530-
blockstore_processor::{fill_blockstore_slot_with_ticks, ProcessOptions},
4530+
blockstore_processor::{
4531+
confirm_full_slot, fill_blockstore_slot_with_ticks, process_bank_0, ProcessOptions,
4532+
},
45314533
crossbeam_channel::unbounded,
45324534
itertools::Itertools,
45334535
solana_entry::entry::{self, Entry},
@@ -9042,6 +9044,7 @@ pub(crate) mod tests {
90429044

90439045
#[test]
90449046
fn test_initialize_progress_and_fork_choice_with_duplicates() {
9047+
solana_logger::setup();
90459048
let GenesisConfigInfo {
90469049
mut genesis_config, ..
90479050
} = create_genesis_config(123);
@@ -9057,27 +9060,71 @@ pub(crate) mod tests {
90579060
slot 0
90589061
|
90599062
slot 1 -> Duplicate before restart
9063+
|
9064+
slot 2
9065+
|
9066+
slot 3 -> Duplicate before restart, artificially rooted
9067+
|
9068+
slot 4 -> Duplicate before restart, artificially rooted
9069+
|
9070+
slot 5 -> Duplicate before restart
9071+
|
9072+
slot 6
90609073
*/
90619074

90629075
let mut last_hash = blockhash;
9063-
for i in 0..1 {
9076+
for i in 0..6 {
90649077
last_hash =
90659078
fill_blockstore_slot_with_ticks(&blockstore, ticks_per_slot, i + 1, i, last_hash);
90669079
}
9067-
blockstore.set_roots([0, 1].iter()).unwrap();
9080+
// Artifically root
9081+
blockstore.set_roots([3, 4].iter()).unwrap();
90689082

90699083
// Set up bank0
90709084
let bank_forks = BankForks::new_rw_arc(Bank::new_for_tests(&genesis_config));
90719085
let bank0 = bank_forks.read().unwrap().get_with_scheduler(0).unwrap();
9086+
let recyclers = VerifyRecyclers::default();
9087+
let replay_tx_thread_pool = rayon::ThreadPoolBuilder::new()
9088+
.num_threads(1)
9089+
.thread_name(|i| format!("solReplayTx{i:02}"))
9090+
.build()
9091+
.expect("new rayon threadpool");
9092+
9093+
process_bank_0(
9094+
&bank0,
9095+
&blockstore,
9096+
&replay_tx_thread_pool,
9097+
&ProcessOptions::default(),
9098+
&recyclers,
9099+
None,
9100+
None,
9101+
);
90729102

9073-
// Mark block 1 as duplicate
9103+
// Mark block 1, 3 , 4, 5 as duplicate
90749104
blockstore.store_duplicate_slot(1, vec![], vec![]).unwrap();
9105+
blockstore.store_duplicate_slot(3, vec![], vec![]).unwrap();
9106+
blockstore.store_duplicate_slot(4, vec![], vec![]).unwrap();
9107+
blockstore.store_duplicate_slot(5, vec![], vec![]).unwrap();
90759108

90769109
let bank1 = bank_forks.write().unwrap().insert(Bank::new_from_parent(
90779110
bank0.clone_without_scheduler(),
90789111
&Pubkey::default(),
90799112
1,
90809113
));
9114+
confirm_full_slot(
9115+
&blockstore,
9116+
&bank1,
9117+
&replay_tx_thread_pool,
9118+
&ProcessOptions::default(),
9119+
&recyclers,
9120+
&mut ConfirmationProgress::new(bank0.last_blockhash()),
9121+
None,
9122+
None,
9123+
None,
9124+
&mut ExecuteTimings::default(),
9125+
)
9126+
.unwrap();
9127+
90819128
bank_forks
90829129
.write()
90839130
.unwrap()
@@ -9090,7 +9137,7 @@ pub(crate) mod tests {
90909137

90919138
let leader_schedule_cache = LeaderScheduleCache::new_from_bank(&bank1);
90929139

9093-
// process_blockstore_from_root() from slot 1 onwards, should remove the duplicate proof from before the restart
9140+
// process_blockstore_from_root() from slot 1 onwards
90949141
blockstore_processor::process_blockstore_from_root(
90959142
&blockstore,
90969143
&bank_forks,
@@ -9103,7 +9150,9 @@ pub(crate) mod tests {
91039150
)
91049151
.unwrap();
91059152

9106-
// Verify that the duplicate information has been cleared and that fork choice can be initialized
9153+
assert_eq!(bank_forks.read().unwrap().root(), 4);
9154+
9155+
// Verify that fork choice can be initialized and that the root is not marked duplicate
91079156
let (_progress, fork_choice) =
91089157
ReplayStage::initialize_progress_and_fork_choice_with_locked_bank_forks(
91099158
&bank_forks,
@@ -9112,7 +9161,16 @@ pub(crate) mod tests {
91129161
&blockstore,
91139162
);
91149163

9115-
assert_eq!(fork_choice.tree_root().0, 1);
9116-
assert_eq!(fork_choice.best_overall_slot().0, 1);
9164+
let bank_forks = bank_forks.read().unwrap();
9165+
// 4 (the artificial root) is the tree root and no longer duplicate
9166+
assert_eq!(fork_choice.tree_root().0, 4);
9167+
assert!(fork_choice
9168+
.is_candidate(&(4, bank_forks.bank_hash(4).unwrap()))
9169+
.unwrap());
9170+
9171+
// 5 is still duplicate,
9172+
assert!(!fork_choice
9173+
.is_candidate(&(5, bank_forks.bank_hash(5).unwrap()))
9174+
.unwrap());
91179175
}
91189176
}

ledger/src/blockstore_processor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ fn verify_ticks(
10781078
}
10791079

10801080
#[allow(clippy::too_many_arguments)]
1081-
fn confirm_full_slot(
1081+
pub fn confirm_full_slot(
10821082
blockstore: &Blockstore,
10831083
bank: &BankWithScheduler,
10841084
replay_tx_thread_pool: &ThreadPool,
@@ -1684,7 +1684,7 @@ fn confirm_slot_entries(
16841684
}
16851685

16861686
// Special handling required for processing the entries in slot 0
1687-
fn process_bank_0(
1687+
pub fn process_bank_0(
16881688
bank0: &BankWithScheduler,
16891689
blockstore: &Blockstore,
16901690
replay_tx_thread_pool: &ThreadPool,

0 commit comments

Comments
 (0)