Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 273726a

Browse files
committed
Fix duplicate confirmed
1 parent 06dc52b commit 273726a

File tree

2 files changed

+59
-19
lines changed

2 files changed

+59
-19
lines changed

local-cluster/tests/common/mod.rs

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -390,18 +390,32 @@ pub fn run_cluster_partition<C>(
390390
on_partition_resolved(&mut cluster, &mut context);
391391
}
392392

393+
pub struct ValidatorTestConfig {
394+
pub validator_keypair: Arc<Keypair>,
395+
pub validator_config: ValidatorConfig,
396+
pub in_genesis: bool,
397+
}
398+
393399
pub fn test_faulty_node(
394400
faulty_node_type: BroadcastStageType,
395401
node_stakes: Vec<u64>,
396-
validator_keys: Option<Vec<(Arc<Keypair>, bool)>>,
402+
validator_test_configs: Option<Vec<ValidatorTestConfig>>,
397403
custom_leader_schedule: Option<FixedSchedule>,
398404
) -> (LocalCluster, Vec<Arc<Keypair>>) {
399405
let num_nodes = node_stakes.len();
400-
let validator_keys = validator_keys.unwrap_or_else(|| {
401-
let mut validator_keys = Vec::with_capacity(num_nodes);
402-
validator_keys.resize_with(num_nodes, || (Arc::new(Keypair::new()), true));
403-
validator_keys
404-
});
406+
let validator_keys = validator_test_configs
407+
.as_ref()
408+
.map(|configs| {
409+
configs
410+
.iter()
411+
.map(|config| (config.validator_keypair.clone(), config.in_genesis))
412+
.collect()
413+
})
414+
.unwrap_or_else(|| {
415+
let mut validator_keys = Vec::with_capacity(num_nodes);
416+
validator_keys.resize_with(num_nodes, || (Arc::new(Keypair::new()), true));
417+
validator_keys
418+
});
405419

406420
assert_eq!(node_stakes.len(), num_nodes);
407421
assert_eq!(validator_keys.len(), num_nodes);
@@ -418,19 +432,24 @@ pub fn test_faulty_node(
418432
}
419433
});
420434

421-
let error_validator_config = ValidatorConfig {
422-
broadcast_stage_type: faulty_node_type,
423-
fixed_leader_schedule: Some(fixed_leader_schedule.clone()),
424-
..ValidatorConfig::default_for_test()
425-
};
426-
let mut validator_configs = Vec::with_capacity(num_nodes);
435+
let mut validator_configs = validator_test_configs
436+
.map(|configs| {
437+
configs
438+
.into_iter()
439+
.map(|config| config.validator_config)
440+
.collect()
441+
})
442+
.unwrap_or_else(|| {
443+
let mut configs = Vec::with_capacity(num_nodes);
444+
configs.resize_with(num_nodes, ValidatorConfig::default_for_test);
445+
configs
446+
});
427447

428448
// First validator is the bootstrap leader with the malicious broadcast logic.
429-
validator_configs.push(error_validator_config);
430-
validator_configs.resize_with(num_nodes, || ValidatorConfig {
431-
fixed_leader_schedule: Some(fixed_leader_schedule.clone()),
432-
..ValidatorConfig::default_for_test()
433-
});
449+
validator_configs[0].broadcast_stage_type = faulty_node_type;
450+
for config in &mut validator_configs {
451+
config.fixed_leader_schedule = Some(fixed_leader_schedule.clone());
452+
}
434453

435454
let mut cluster_config = ClusterConfig {
436455
cluster_lamports: 10_000,

local-cluster/tests/local_cluster.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5082,6 +5082,7 @@ fn test_duplicate_shreds_switch_failure() {
50825082
dup_shred2: &Shred,
50835083
) {
50845084
let disable_turbine = Arc::new(AtomicBool::new(true));
5085+
duplicate_fork_validator_info.config.voting_disabled = false;
50855086
duplicate_fork_validator_info.config.turbine_disabled = disable_turbine.clone();
50865087
info!("Restarting node: {}", pubkey);
50875088
cluster.restart_node(
@@ -5151,6 +5152,7 @@ fn test_duplicate_shreds_switch_failure() {
51515152
.iter()
51525153
.map(|s| (Arc::new(Keypair::from_base58_string(s)), true))
51535154
.collect::<Vec<_>>();
5155+
51545156
let validators = validator_keypairs
51555157
.iter()
51565158
.map(|(kp, _)| kp.pubkey())
@@ -5239,6 +5241,23 @@ fn test_duplicate_shreds_switch_failure() {
52395241

52405242
// 1) Set up the cluster
52415243
let (duplicate_slot_sender, duplicate_slot_receiver) = unbounded();
5244+
let validator_configs = validator_keypairs
5245+
.into_iter()
5246+
.map(|(validator_keypair, in_genesis)| {
5247+
let pubkey = validator_keypair.pubkey();
5248+
// Only allow the leader to vote so that no version gets duplicate confirmed.
5249+
// This is to avoid the leader dumping his own block.
5250+
let voting_disabled = { pubkey != duplicate_leader_validator_pubkey };
5251+
ValidatorTestConfig {
5252+
validator_keypair,
5253+
validator_config: ValidatorConfig {
5254+
voting_disabled,
5255+
..ValidatorConfig::default()
5256+
},
5257+
in_genesis,
5258+
}
5259+
})
5260+
.collect();
52425261
let (mut cluster, _validator_keypairs) = test_faulty_node(
52435262
BroadcastStageType::BroadcastDuplicates(BroadcastDuplicatesConfig {
52445263
partition: ClusterPartition::Pubkey(vec![
@@ -5252,7 +5271,7 @@ fn test_duplicate_shreds_switch_failure() {
52525271
duplicate_slot_sender: Some(duplicate_slot_sender),
52535272
}),
52545273
node_stakes,
5255-
Some(validator_keypairs),
5274+
Some(validator_configs),
52565275
Some(FixedSchedule {
52575276
leader_schedule: Arc::new(leader_schedule),
52585277
}),
@@ -5265,7 +5284,8 @@ fn test_duplicate_shreds_switch_failure() {
52655284
let duplicate_fork_validator2_info = cluster.exit_node(&duplicate_fork_validator2_pubkey);
52665285
let target_switch_fork_validator_ledger_path =
52675286
cluster.ledger_path(&target_switch_fork_validator_pubkey);
5268-
let target_switch_fork_validator_info = cluster.exit_node(&target_switch_fork_validator_pubkey);
5287+
let mut target_switch_fork_validator_info =
5288+
cluster.exit_node(&target_switch_fork_validator_pubkey);
52695289

52705290
// 2) Wait for a duplicate slot to land on both validators and for the target switch
52715291
// fork validator to get another version of the slot. Also ensure all versions of
@@ -5386,6 +5406,7 @@ fn test_duplicate_shreds_switch_failure() {
53865406
// 4) Restart `target_switch_fork_validator_pubkey`, and ensure they vote on their own leader slot
53875407
// that's not descended from the duplicate slot
53885408
info!("Restarting switch fork node");
5409+
target_switch_fork_validator_info.config.voting_disabled = false;
53895410
cluster.restart_node(
53905411
&target_switch_fork_validator_pubkey,
53915412
target_switch_fork_validator_info,

0 commit comments

Comments
 (0)