Forwarder: separate get_leader_and_addr (#30922)

This commit is contained in:
Andrew Fitzgerald 2023-03-28 16:34:36 -07:00 committed by GitHub
parent 564f8c9b17
commit 8e910b494f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 14 deletions

View File

@ -17,7 +17,7 @@ use {
solana_streamer::sendmmsg::batch_send,
std::{
iter::repeat,
net::UdpSocket,
net::{SocketAddr, UdpSocket},
sync::{atomic::Ordering, Arc, RwLock},
},
};
@ -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();
@ -214,6 +203,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;