Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ChannelSend trait to prep for lossy sender #4797

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
26 changes: 13 additions & 13 deletions gossip/src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use {
},
weighted_shuffle::WeightedShuffle,
},
crossbeam_channel::{Receiver, RecvTimeoutError, Sender},
crossbeam_channel::{Receiver, RecvTimeoutError},
itertools::Itertools,
rand::{seq::SliceRandom, CryptoRng, Rng},
rayon::{prelude::*, ThreadPool, ThreadPoolBuilder},
Expand Down Expand Up @@ -75,7 +75,7 @@ use {
packet,
quic::DEFAULT_QUIC_ENDPOINTS,
socket::SocketAddrSpace,
streamer::{PacketBatchReceiver, PacketBatchSender},
streamer::{ChannelSend, PacketBatchReceiver},
},
solana_vote::vote_parser,
solana_vote_program::vote_state::MAX_LOCKOUT_HISTORY,
Expand Down Expand Up @@ -244,7 +244,7 @@ impl ClusterInfo {
recycler: &PacketBatchRecycler,
stakes: &HashMap<Pubkey, u64>,
gossip_validators: Option<&HashSet<Pubkey>>,
sender: &PacketBatchSender,
sender: &impl ChannelSend<PacketBatch>,
) {
let shred_version = self.my_contact_info.read().unwrap().shred_version();
let self_keypair: Arc<Keypair> = self.keypair().clone();
Expand Down Expand Up @@ -1367,7 +1367,7 @@ impl ClusterInfo {
gossip_validators: Option<&HashSet<Pubkey>>,
recycler: &PacketBatchRecycler,
stakes: &HashMap<Pubkey, u64>,
sender: &PacketBatchSender,
sender: &impl ChannelSend<PacketBatch>,
generate_pull_requests: bool,
) -> Result<(), GossipError> {
let _st = ScopedTimer::from(&self.stats.gossip_transmit_loop_time);
Expand Down Expand Up @@ -1489,7 +1489,7 @@ impl ClusterInfo {
pub fn gossip(
self: Arc<Self>,
bank_forks: Option<Arc<RwLock<BankForks>>>,
sender: PacketBatchSender,
sender: impl ChannelSend<PacketBatch>,
gossip_validators: Option<HashSet<Pubkey>>,
exit: Arc<AtomicBool>,
) -> JoinHandle<()> {
Expand Down Expand Up @@ -1626,7 +1626,7 @@ impl ClusterInfo {
thread_pool: &ThreadPool,
recycler: &PacketBatchRecycler,
stakes: &HashMap<Pubkey, u64>,
response_sender: &PacketBatchSender,
response_sender: &impl ChannelSend<PacketBatch>,
) {
let _st = ScopedTimer::from(&self.stats.handle_batch_pull_requests_time);
if requests.is_empty() {
Expand Down Expand Up @@ -1897,7 +1897,7 @@ impl ClusterInfo {
&self,
pings: I,
recycler: &PacketBatchRecycler,
response_sender: &PacketBatchSender,
response_sender: &impl ChannelSend<PacketBatch>,
) where
I: IntoIterator<Item = (SocketAddr, Ping)>,
{
Expand Down Expand Up @@ -1955,7 +1955,7 @@ impl ClusterInfo {
thread_pool: &ThreadPool,
recycler: &PacketBatchRecycler,
stakes: &HashMap<Pubkey, u64>,
response_sender: &PacketBatchSender,
response_sender: &impl ChannelSend<PacketBatch>,
) {
let _st = ScopedTimer::from(&self.stats.handle_batch_push_messages_time);
if messages.is_empty() {
Expand Down Expand Up @@ -2074,7 +2074,7 @@ impl ClusterInfo {
packets: VecDeque<(/*from:*/ SocketAddr, Protocol)>,
thread_pool: &ThreadPool,
recycler: &PacketBatchRecycler,
response_sender: &PacketBatchSender,
response_sender: &impl ChannelSend<PacketBatch>,
stakes: &HashMap<Pubkey, u64>,
epoch_duration: Duration,
should_check_duplicate_instance: bool,
Expand Down Expand Up @@ -2213,7 +2213,7 @@ impl ClusterInfo {
thread_pool: &ThreadPool,
epoch_specs: Option<&mut EpochSpecs>,
receiver: &PacketBatchReceiver,
sender: &Sender<Vec<(/*from:*/ SocketAddr, Protocol)>>,
sender: &impl ChannelSend<Vec<(/*from:*/ SocketAddr, Protocol)>>,
) -> Result<(), GossipError> {
const RECV_TIMEOUT: Duration = Duration::from_secs(1);
fn count_dropped_packets(packets: &PacketBatch, dropped_packets_counts: &mut [u64; 7]) {
Expand Down Expand Up @@ -2305,7 +2305,7 @@ impl ClusterInfo {
recycler: &PacketBatchRecycler,
mut epoch_specs: Option<&mut EpochSpecs>,
receiver: &Receiver<Vec<(/*from:*/ SocketAddr, Protocol)>>,
response_sender: &PacketBatchSender,
response_sender: &impl ChannelSend<PacketBatch>,
thread_pool: &ThreadPool,
last_print: &mut Instant,
should_check_duplicate_instance: bool,
Expand Down Expand Up @@ -2355,7 +2355,7 @@ impl ClusterInfo {
self: Arc<Self>,
bank_forks: Option<Arc<RwLock<BankForks>>>,
receiver: PacketBatchReceiver,
sender: Sender<Vec<(/*from:*/ SocketAddr, Protocol)>>,
sender: impl ChannelSend<Vec<(/*from:*/ SocketAddr, Protocol)>>,
exit: Arc<AtomicBool>,
) -> JoinHandle<()> {
let thread_pool = ThreadPoolBuilder::new()
Expand Down Expand Up @@ -2390,7 +2390,7 @@ impl ClusterInfo {
self: Arc<Self>,
bank_forks: Option<Arc<RwLock<BankForks>>>,
requests_receiver: Receiver<Vec<(/*from:*/ SocketAddr, Protocol)>>,
response_sender: PacketBatchSender,
response_sender: impl ChannelSend<PacketBatch>,
should_check_duplicate_instance: bool,
exit: Arc<AtomicBool>,
) -> JoinHandle<()> {
Expand Down
32 changes: 30 additions & 2 deletions streamer/src/streamer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,34 @@ pub struct StakedNodes {
min_stake: u64,
}

pub trait ChannelSend<T>: Send + 'static {
fn send(&self, msg: T) -> std::result::Result<(), SendError<T>>;

fn is_empty(&self) -> bool;

fn len(&self) -> usize;
}

impl<T> ChannelSend<T> for Sender<T>
where
T: Send + 'static,
{
#[inline]
fn send(&self, msg: T) -> std::result::Result<(), SendError<T>> {
self.send(msg)
}

#[inline]
fn is_empty(&self) -> bool {
self.is_empty()
}

#[inline]
fn len(&self) -> usize {
self.len()
}
}

pub type PacketBatchReceiver = Receiver<PacketBatch>;
pub type PacketBatchSender = Sender<PacketBatch>;

Expand Down Expand Up @@ -106,7 +134,7 @@ pub type Result<T> = std::result::Result<T, StreamerError>;
fn recv_loop(
socket: &UdpSocket,
exit: &AtomicBool,
packet_batch_sender: &PacketBatchSender,
packet_batch_sender: &impl ChannelSend<PacketBatch>,
recycler: &PacketBatchRecycler,
stats: &StreamerReceiveStats,
coalesce: Duration,
Expand Down Expand Up @@ -166,7 +194,7 @@ pub fn receiver(
thread_name: String,
socket: Arc<UdpSocket>,
exit: Arc<AtomicBool>,
packet_batch_sender: PacketBatchSender,
packet_batch_sender: impl ChannelSend<PacketBatch>,
recycler: PacketBatchRecycler,
stats: Arc<StreamerReceiveStats>,
coalesce: Duration,
Expand Down
Loading