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

Commit

Permalink
Forwarder: separate get_leader_and_addr
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Mar 28, 2023
1 parent 2dfc46c commit 51cef29
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions core/src/banking_stage/forwarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use {
solana_streamer::sendmmsg::batch_send,
std::{
iter::repeat,
net::UdpSocket,
net::{SocketAddr, UdpSocket},
sync::{atomic::Ordering, Arc, RwLock},
},
};
Expand Down Expand Up @@ -147,19 +147,8 @@ impl Forwarder {
usize,
Option<Pubkey>,
) {
let leader_and_addr = match forward_option {
ForwardOption::NotForward => return (Ok(()), 0, None),
ForwardOption::ForwardTransaction => {
next_leader_tpu_forwards(&self.cluster_info, &self.poh_recorder)
}

ForwardOption::ForwardTpuVote => {
next_leader_tpu_vote(&self.cluster_info, &self.poh_recorder)
}
};
let (leader_pubkey, addr) = match leader_and_addr {
Some(leader_and_addr) => leader_and_addr,
None => return (Ok(()), 0, None),
let Some((leader_pubkey, addr)) = self.get_leader_and_addr(forward_option) else {
return (Ok(()), 0, None);
};

self.update_data_budget();
Expand Down Expand Up @@ -218,6 +207,20 @@ impl Forwarder {
(Ok(()), packet_vec_len, Some(leader_pubkey))
}

/// Get the pubkey and socket address for the leader to forward to
fn get_leader_and_addr(&self, forward_option: &ForwardOption) -> Option<(Pubkey, SocketAddr)> {
match forward_option {
ForwardOption::NotForward => None,
ForwardOption::ForwardTransaction => {
next_leader_tpu_forwards(&self.cluster_info, &self.poh_recorder)
}

ForwardOption::ForwardTpuVote => {
next_leader_tpu_vote(&self.cluster_info, &self.poh_recorder)
}
}
}

/// Re-fill the data budget if enough time has passed
fn update_data_budget(&self) {
const INTERVAL_MS: u64 = 100;
Expand Down

0 comments on commit 51cef29

Please sign in to comment.