convert std::sync::mpsc to crossbeam_channel (#22264)

This commit is contained in:
Jeff Biseda
2022-01-11 02:44:46 -08:00
committed by GitHub
parent 3c44d405c7
commit 8b66625c95
81 changed files with 313 additions and 346 deletions

View File

@@ -13,6 +13,7 @@ documentation = "https://docs.rs/solana-gossip"
bincode = "1.3.3"
bv = { version = "0.11.1", features = ["serde"] }
clap = "2.33.1"
crossbeam-channel = "0.5"
flate2 = "1.0"
indexmap = { version = "1.8", features = ["rayon"] }
itertools = "0.10.3"

View File

@@ -33,6 +33,7 @@ use {
weighted_shuffle::WeightedShuffle,
},
bincode::{serialize, serialized_size},
crossbeam_channel::{Receiver, RecvTimeoutError, Sender},
itertools::Itertools,
rand::{seq::SliceRandom, thread_rng, CryptoRng, Rng},
rayon::{prelude::*, ThreadPool, ThreadPoolBuilder},
@@ -85,7 +86,6 @@ use {
result::Result,
sync::{
atomic::{AtomicBool, Ordering},
mpsc::{Receiver, RecvTimeoutError, Sender},
Arc, Mutex, RwLock, RwLockReadGuard,
},
thread::{sleep, Builder, JoinHandle},

View File

@@ -1,6 +1,7 @@
use {
crate::duplicate_shred,
std::{io, sync},
crossbeam_channel::{RecvTimeoutError, SendError},
std::io,
thiserror::Error,
};
@@ -13,15 +14,15 @@ pub enum GossipError {
#[error(transparent)]
Io(#[from] io::Error),
#[error(transparent)]
RecvTimeoutError(#[from] sync::mpsc::RecvTimeoutError),
RecvTimeoutError(#[from] RecvTimeoutError),
#[error("send error")]
SendError,
#[error("serialization error")]
Serialize(#[from] Box<bincode::ErrorKind>),
}
impl<T> std::convert::From<sync::mpsc::SendError<T>> for GossipError {
fn from(_e: sync::mpsc::SendError<T>) -> GossipError {
impl<T> std::convert::From<SendError<T>> for GossipError {
fn from(_e: SendError<T>) -> GossipError {
GossipError::SendError
}
}

View File

@@ -5,6 +5,7 @@ use {
cluster_info::{ClusterInfo, VALIDATOR_PORT_RANGE},
contact_info::ContactInfo,
},
crossbeam_channel::{unbounded, Sender},
rand::{thread_rng, Rng},
solana_client::thin_client::{create_client, ThinClient},
solana_perf::recycler::Recycler,
@@ -19,7 +20,6 @@ use {
net::{IpAddr, Ipv4Addr, SocketAddr, TcpListener, UdpSocket},
sync::{
atomic::{AtomicBool, Ordering},
mpsc::{channel, Sender},
Arc, RwLock,
},
thread::{self, sleep, JoinHandle},
@@ -41,7 +41,7 @@ impl GossipService {
stats_reporter_sender: Option<Sender<Box<dyn FnOnce() + Send>>>,
exit: &Arc<AtomicBool>,
) -> Self {
let (request_sender, request_receiver) = channel();
let (request_sender, request_receiver) = unbounded();
let gossip_socket = Arc::new(gossip_socket);
trace!(
"GossipService: id: {}, listening on: {:?}",
@@ -58,15 +58,13 @@ impl GossipService {
1,
false,
);
let (consume_sender, listen_receiver) = channel();
// https://github.com/rust-lang/rust/issues/39364#issuecomment-634545136
let _consume_sender = consume_sender.clone();
let (consume_sender, listen_receiver) = unbounded();
let t_socket_consume = cluster_info.clone().start_socket_consume_thread(
request_receiver,
consume_sender,
exit.clone(),
);
let (response_sender, response_receiver) = channel();
let (response_sender, response_receiver) = unbounded();
let t_listen = cluster_info.clone().listen(
bank_forks.clone(),
listen_receiver,
@@ -80,10 +78,6 @@ impl GossipService {
gossip_validators,
exit.clone(),
);
// To work around:
// https://github.com/rust-lang/rust/issues/54267
// responder thread should start after response_sender.clone(). see:
// https://github.com/rust-lang/rust/issues/39364#issuecomment-381446873
let t_responder = streamer::responder(
"gossip",
gossip_socket,

View File

@@ -1,5 +1,6 @@
#![allow(clippy::integer_arithmetic)]
use {
crossbeam_channel::{unbounded, Receiver, Sender, TryRecvError},
rayon::{iter::ParallelIterator, prelude::*},
serial_test::serial,
solana_gossip::{
@@ -11,10 +12,7 @@ use {
solana_streamer::socket::SocketAddrSpace,
std::{
collections::{HashMap, HashSet},
sync::{
mpsc::{channel, Receiver, Sender, TryRecvError},
Arc, Mutex,
},
sync::{Arc, Mutex},
time::Instant,
},
};
@@ -90,7 +88,7 @@ fn run_simulation(stakes: &[u64], fanout: usize) {
let mut staked_nodes = HashMap::new();
// setup accounts for all nodes (leader has 0 bal)
let (s, r) = channel();
let (s, r) = unbounded();
let senders: Arc<Mutex<HashMap<Pubkey, Sender<(i32, bool)>>>> =
Arc::new(Mutex::new(HashMap::new()));
senders.lock().unwrap().insert(leader_info.id, s);
@@ -109,7 +107,7 @@ fn run_simulation(stakes: &[u64], fanout: usize) {
let node = ContactInfo::new_localhost(&solana_sdk::pubkey::new_rand(), 0);
staked_nodes.insert(node.id, stakes[*i - 1]);
cluster_info.insert_info(node.clone());
let (s, r) = channel();
let (s, r) = unbounded();
batches
.get_mut(batch_ix)
.unwrap()