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

Forwarder: separate get_leader_and_addr #30922

Merged
merged 1 commit into from
Mar 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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