Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Aug 15, 2024
1 parent 47472a1 commit 6e918e4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
18 changes: 8 additions & 10 deletions core/src/next_leader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,29 @@ use {
};

/// Returns a list of tpu vote sockets for the leaders of the next N fanout
/// slots. Leaders are deduped but the resulting list could have duplicate
/// sockets if two different leaders share the same tpu vote socket.
/// slots. Leaders and sockets are deduped.
pub(crate) fn upcoming_leader_tpu_vote_sockets(
cluster_info: &ClusterInfo,
poh_recorder: &RwLock<PohRecorder>,
fanout_slots: usize,
fanout_slots: u64,
) -> Vec<SocketAddr> {
let upcoming_leaders = {
let mut upcoming_leaders = Vec::with_capacity(fanout_slots);
let poh_recorder = poh_recorder.read().unwrap();
for n_slots in 1..=fanout_slots {
upcoming_leaders.push(poh_recorder.leader_after_n_slots(n_slots as u64));
}
upcoming_leaders
(1..=fanout_slots)
.filter_map(|n_slots| poh_recorder.leader_after_n_slots(n_slots))
.collect_vec()
};

upcoming_leaders
.into_iter()
.flatten()
.unique()
.dedup()
.filter_map(|leader_pubkey| {
cluster_info
.lookup_contact_info(&leader_pubkey, ContactInfo::tpu_vote)?
.ok()
})
// dedup again since leaders could potentially share the same tpu vote socket
.dedup()
.collect()
}

Expand Down
9 changes: 7 additions & 2 deletions core/src/voting_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use {
solana_gossip::cluster_info::ClusterInfo,
solana_measure::measure::Measure,
solana_poh::poh_recorder::PohRecorder,
solana_sdk::{clock::Slot, transaction::Transaction},
solana_sdk::{
clock::{Slot, FORWARD_TRANSACTIONS_TO_LEADER_AT_SLOT_OFFSET},
transaction::Transaction,
},
std::{
sync::{Arc, RwLock},
thread::{self, Builder, JoinHandle},
Expand Down Expand Up @@ -79,7 +82,9 @@ impl VotingService {
}

// Attempt to send our vote transaction to the leaders for the next few slots
const UPCOMING_LEADER_FANOUT_SLOTS: usize = 2;
const UPCOMING_LEADER_FANOUT_SLOTS: u64 = FORWARD_TRANSACTIONS_TO_LEADER_AT_SLOT_OFFSET;
#[cfg(test)]
static_assertions::const_assert_eq!(UPCOMING_LEADER_FANOUT_SLOTS, 2);
let upcoming_leader_sockets = upcoming_leader_tpu_vote_sockets(
cluster_info,
poh_recorder,
Expand Down

0 comments on commit 6e918e4

Please sign in to comment.