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

Commit

Permalink
Skip leader slots until a vote lands
Browse files Browse the repository at this point in the history
  • Loading branch information
sakridge committed Mar 1, 2021
1 parent 24af996 commit 8aa468f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions core/src/replay_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ impl ReplayStage {
let mut partition_exists = false;
let mut skipped_slots_info = SkippedSlotsInfo::default();
let mut replay_timing = ReplayTiming::default();
let mut has_voted = false;
let mut first_voted_slot = Slot::MAX;
loop {
let allocated = thread_mem_usage::Allocatedp::default();

Expand Down Expand Up @@ -375,6 +377,8 @@ impl ReplayStage {
&cluster_slots,
&bank_forks,
&mut heaviest_subtree_fork_choice,
&mut has_voted,
first_voted_slot,
);
compute_bank_stats_time.stop();

Expand Down Expand Up @@ -479,6 +483,7 @@ impl ReplayStage {
&mut heaviest_subtree_fork_choice,
&cache_block_time_sender,
&bank_notification_sender,
&mut first_voted_slot,
);
};
voting_time.stop();
Expand Down Expand Up @@ -570,6 +575,7 @@ impl ReplayStage {
&progress,
&retransmit_slots_sender,
&mut skipped_slots_info,
has_voted,
);

let poh_bank = poh_recorder.lock().unwrap().bank();
Expand Down Expand Up @@ -885,7 +891,12 @@ impl ReplayStage {
progress_map: &ProgressMap,
retransmit_slots_sender: &RetransmitSlotsSender,
skipped_slots_info: &mut SkippedSlotsInfo,
has_voted: bool,
) {
if !has_voted {
info!("Haven't landed a vote, so skipping my leader slot");
return;
}
// all the individual calls to poh_recorder.lock() are designed to
// increase granularity, decrease contention

Expand Down Expand Up @@ -1077,6 +1088,7 @@ impl ReplayStage {
heaviest_subtree_fork_choice: &mut HeaviestSubtreeForkChoice,
cache_block_time_sender: &Option<CacheBlockTimeSender>,
bank_notification_sender: &Option<BankNotificationSender>,
first_voted_slot: &mut Slot,
) {
if bank.is_empty() {
inc_new_counter_info!("replay_stage-voted_empty_bank", 1);
Expand Down Expand Up @@ -1158,6 +1170,7 @@ impl ReplayStage {
last_vote,
&tower_slots,
switch_fork_decision,
first_voted_slot,
);
}

Expand All @@ -1169,6 +1182,7 @@ impl ReplayStage {
vote: Vote,
tower: &[Slot],
switch_fork_decision: &SwitchForkDecision,
first_voted_slot: &mut Slot,
) {
if authorized_voter_keypairs.is_empty() {
return;
Expand Down Expand Up @@ -1238,6 +1252,9 @@ impl ReplayStage {

let mut vote_tx = Transaction::new_with_payer(&[vote_ix], Some(&node_keypair.pubkey()));

if *first_voted_slot != Slot::MAX {
*first_voted_slot = bank.slot();
}
let blockhash = bank.last_blockhash();
vote_tx.partial_sign(&[node_keypair.as_ref()], blockhash);
vote_tx.partial_sign(&[authorized_voter_keypair.as_ref()], blockhash);
Expand Down Expand Up @@ -1423,6 +1440,8 @@ impl ReplayStage {
cluster_slots: &ClusterSlots,
bank_forks: &RwLock<BankForks>,
heaviest_subtree_fork_choice: &mut dyn ForkChoice,
has_voted: &mut bool,
first_voted_slot: Slot,
) -> Vec<Slot> {
frozen_banks.sort_by_key(|bank| bank.slot());
let mut new_stats = vec![];
Expand Down Expand Up @@ -1499,6 +1518,9 @@ impl ReplayStage {
tower.check_vote_stake_threshold(bank_slot, &stats.voted_stakes, stats.total_stake);
stats.is_locked_out = tower.is_locked_out(bank_slot, &ancestors);
stats.has_voted = tower.has_voted(bank_slot);
if bank_slot > first_voted_slot && stats.has_voted {
*has_voted = true;
}
stats.is_recent = tower.is_recent(bank_slot);
}
new_stats
Expand Down

0 comments on commit 8aa468f

Please sign in to comment.