Skip to content

Commit

Permalink
Use estimated current slot in tpu client (solana-labs#28997)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgarg66 authored Nov 30, 2022
1 parent 58e12cf commit 07d21d4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tpu-client/src/nonblocking/tpu_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,18 @@ impl LeaderTpuCache {
}

// Get the TPU sockets for the current leader and upcoming leaders according to fanout size
fn get_leader_sockets(&self, fanout_slots: u64) -> Vec<SocketAddr> {
fn get_leader_sockets(
&self,
estimated_current_slot: Slot,
fanout_slots: u64,
) -> Vec<SocketAddr> {
let mut leader_set = HashSet::new();
let mut leader_sockets = Vec::new();
for leader_slot in self.first_slot..self.first_slot + fanout_slots {
// `first_slot` might have been advanced since caller last read the `estimated_current_slot`
// value. Take the greater of the two values to ensure we are reading from the latest
// leader schedule.
let current_slot = std::cmp::max(estimated_current_slot, self.first_slot);
for leader_slot in current_slot..current_slot + fanout_slots {
if let Some(leader) = self.get_slot_leader(leader_slot) {
if let Some(tpu_socket) = self.leader_tpu_map.get(leader) {
if leader_set.insert(*leader) {
Expand Down Expand Up @@ -628,10 +636,11 @@ impl LeaderTpuService {
}

pub fn leader_tpu_sockets(&self, fanout_slots: u64) -> Vec<SocketAddr> {
let current_slot = self.recent_slots.estimated_current_slot();
self.leader_tpu_cache
.read()
.unwrap()
.get_leader_sockets(fanout_slots)
.get_leader_sockets(current_slot, fanout_slots)
}

async fn run(
Expand Down

0 comments on commit 07d21d4

Please sign in to comment.