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

multitask quic socket operations #611

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion client/src/connection_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ mod tests {
let staked_nodes = Arc::new(RwLock::new(StakedNodes::default()));

let SpawnServerResult {
endpoint: response_recv_endpoint,
endpoints: mut response_recv_endpoints,
thread: response_recv_thread,
key_updater: _,
} = solana_streamer::quic::spawn_server(
Expand All @@ -275,6 +275,9 @@ mod tests {
)
.unwrap();

let response_recv_endpoint = response_recv_endpoints

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not strictly related to this PR because pre-change the test is doing the same,
but: why is it using one of the server endpoints? Why isn't it creating a new
endpoint? Makes the test confusing - I had to triple check that it's fine to
just pick one from the now multi-endpoints.

Maybe add a comment that explicitly says that it doesn't really matter which
endpoint is used?

.pop()
.expect("at least one endpoint");
let connection_cache = ConnectionCache::new_with_client_options(
"connection_cache_test",
1, // connection_pool_size
Expand Down
16 changes: 9 additions & 7 deletions core/src/tpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ use {
solana_sdk::{clock::Slot, pubkey::Pubkey, quic::NotifyKeyUpdate, signature::Keypair},
solana_streamer::{
nonblocking::quic::DEFAULT_WAIT_FOR_CHUNK_TIMEOUT,
quic::{spawn_server, SpawnServerResult, MAX_STAKED_CONNECTIONS, MAX_UNSTAKED_CONNECTIONS},
quic::{
spawn_server_multi, SpawnServerResult, MAX_STAKED_CONNECTIONS, MAX_UNSTAKED_CONNECTIONS,
},
streamer::StakedNodes,
},
solana_turbine::broadcast_stage::{BroadcastStage, BroadcastStageType},
Expand All @@ -57,8 +59,8 @@ pub struct TpuSockets {
pub transaction_forwards: Vec<UdpSocket>,
pub vote: Vec<UdpSocket>,
pub broadcast: Vec<UdpSocket>,
pub transactions_quic: UdpSocket,
pub transactions_forwards_quic: UdpSocket,
pub transactions_quic: Vec<UdpSocket>,
pub transactions_forwards_quic: Vec<UdpSocket>,
}

pub struct Tpu {
Expand Down Expand Up @@ -149,10 +151,10 @@ impl Tpu {
let (non_vote_sender, non_vote_receiver) = banking_tracer.create_channel_non_vote();

let SpawnServerResult {
endpoint: _,
endpoints: _,
thread: tpu_quic_t,
key_updater,
} = spawn_server(
} = spawn_server_multi(
"solQuicTpu",
"quic_streamer_tpu",
transactions_quic_sockets,
Expand All @@ -169,10 +171,10 @@ impl Tpu {
.unwrap();

let SpawnServerResult {
endpoint: _,
endpoints: _,
thread: tpu_forwards_quic_t,
key_updater: forwards_key_updater,
} = spawn_server(
} = spawn_server_multi(
"solQuicTpuFwd",
"quic_streamer_tpu_forwards",
transactions_forwards_quic_sockets,
Expand Down
99 changes: 88 additions & 11 deletions gossip/src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ use {
solana_ledger::shred::Shred,
solana_measure::measure::Measure,
solana_net_utils::{
bind_common, bind_common_in_range, bind_in_range, bind_two_in_range_with_offset,
find_available_port_in_range, multi_bind_in_range, PortRange,
bind_common, bind_common_in_range, bind_in_range, bind_in_range_with_config,
bind_more_with_config, bind_two_in_range_with_offset_and_config,
find_available_port_in_range, multi_bind_in_range, PortRange, SocketConfig,
},
solana_perf::{
data_budget::DataBudget,
Expand Down Expand Up @@ -2782,8 +2783,8 @@ pub struct Sockets {
pub serve_repair: UdpSocket,
pub serve_repair_quic: UdpSocket,
pub ancestor_hashes_requests: UdpSocket,
pub tpu_quic: UdpSocket,
pub tpu_forwards_quic: UdpSocket,
pub tpu_quic: Vec<UdpSocket>,
pub tpu_forwards_quic: Vec<UdpSocket>,
}

pub struct NodeConfig {
Expand All @@ -2794,6 +2795,8 @@ pub struct NodeConfig {
pub public_tpu_forwards_addr: Option<SocketAddr>,
}

const QUIC_ENDPOINTS: usize = 10;

#[derive(Debug)]
pub struct Node {
pub info: ContactInfo,
Expand All @@ -2811,15 +2814,41 @@ impl Node {
let unspecified_bind_addr = format!("{:?}:0", IpAddr::V4(Ipv4Addr::UNSPECIFIED));
let port_range = (1024, 65535);

let udp_config = SocketConfig {
reuseaddr: false,
reuseport: true,
};
let quic_config = SocketConfig {
reuseaddr: false,
reuseport: true,
};
let ((_tpu_port, tpu), (_tpu_quic_port, tpu_quic)) =
bind_two_in_range_with_offset(localhost_ip_addr, port_range, QUIC_PORT_OFFSET).unwrap();
bind_two_in_range_with_offset_and_config(
localhost_ip_addr,
port_range,
QUIC_PORT_OFFSET,
udp_config.clone(),
quic_config.clone(),
)
.unwrap();
let tpu_quic =
bind_more_with_config(tpu_quic, QUIC_ENDPOINTS, quic_config.clone()).unwrap();
let (gossip_port, (gossip, ip_echo)) =
bind_common_in_range(localhost_ip_addr, port_range).unwrap();
let gossip_addr = SocketAddr::new(localhost_ip_addr, gossip_port);
let tvu = UdpSocket::bind(&localhost_bind_addr).unwrap();
let tvu_quic = UdpSocket::bind(&localhost_bind_addr).unwrap();
let ((_tpu_forwards_port, tpu_forwards), (_tpu_forwards_quic_port, tpu_forwards_quic)) =
bind_two_in_range_with_offset(localhost_ip_addr, port_range, QUIC_PORT_OFFSET).unwrap();
bind_two_in_range_with_offset_and_config(
localhost_ip_addr,
port_range,
QUIC_PORT_OFFSET,
udp_config,
quic_config.clone(),
)
.unwrap();
let tpu_forwards_quic =
bind_more_with_config(tpu_forwards_quic, QUIC_ENDPOINTS, quic_config).unwrap();
let tpu_vote = UdpSocket::bind(&localhost_bind_addr).unwrap();
let repair = UdpSocket::bind(&localhost_bind_addr).unwrap();
let rpc_port = find_available_port_in_range(localhost_ip_addr, port_range).unwrap();
Expand Down Expand Up @@ -2906,7 +2935,19 @@ impl Node {
}
}
fn bind(bind_ip_addr: IpAddr, port_range: PortRange) -> (u16, UdpSocket) {
bind_in_range(bind_ip_addr, port_range).expect("Failed to bind")
let config = SocketConfig {
reuseaddr: false,
reuseport: false,
};
Self::bind_with_config(bind_ip_addr, port_range, config)
}

fn bind_with_config(
bind_ip_addr: IpAddr,
port_range: PortRange,
config: SocketConfig,
) -> (u16, UdpSocket) {
bind_in_range_with_config(bind_ip_addr, port_range, config).expect("Failed to bind")
}

pub fn new_single_bind(
Expand All @@ -2919,10 +2960,36 @@ impl Node {
Self::get_gossip_port(gossip_addr, port_range, bind_ip_addr);
let (tvu_port, tvu) = Self::bind(bind_ip_addr, port_range);
let (tvu_quic_port, tvu_quic) = Self::bind(bind_ip_addr, port_range);
let udp_config = SocketConfig {
reuseaddr: false,
reuseport: false,
};
let quic_config = SocketConfig {
reuseaddr: false,
reuseport: true,
};
let ((tpu_port, tpu), (_tpu_quic_port, tpu_quic)) =
bind_two_in_range_with_offset(bind_ip_addr, port_range, QUIC_PORT_OFFSET).unwrap();
bind_two_in_range_with_offset_and_config(
bind_ip_addr,
port_range,
QUIC_PORT_OFFSET,
udp_config.clone(),
quic_config.clone(),
)
.unwrap();
let tpu_quic =
bind_more_with_config(tpu_quic, QUIC_ENDPOINTS, quic_config.clone()).unwrap();
let ((tpu_forwards_port, tpu_forwards), (_tpu_forwards_quic_port, tpu_forwards_quic)) =
bind_two_in_range_with_offset(bind_ip_addr, port_range, QUIC_PORT_OFFSET).unwrap();
bind_two_in_range_with_offset_and_config(
bind_ip_addr,
port_range,
QUIC_PORT_OFFSET,
udp_config,
quic_config.clone(),
)
.unwrap();
let tpu_forwards_quic =
bind_more_with_config(tpu_forwards_quic, QUIC_ENDPOINTS, quic_config).unwrap();
let (tpu_vote_port, tpu_vote) = Self::bind(bind_ip_addr, port_range);
let (_, retransmit_socket) = Self::bind(bind_ip_addr, port_range);
let (_, repair) = Self::bind(bind_ip_addr, port_range);
Expand Down Expand Up @@ -3004,21 +3071,31 @@ impl Node {
let (tpu_port, tpu_sockets) =
multi_bind_in_range(bind_ip_addr, port_range, 32).expect("tpu multi_bind");

let (_tpu_port_quic, tpu_quic) = Self::bind(
let quic_config = SocketConfig {
reuseaddr: false,
reuseport: true,
};
let (_tpu_port_quic, tpu_quic) = Self::bind_with_config(
bind_ip_addr,
(tpu_port + QUIC_PORT_OFFSET, tpu_port + QUIC_PORT_OFFSET + 1),
quic_config.clone(),
);
let tpu_quic =
bind_more_with_config(tpu_quic, QUIC_ENDPOINTS, quic_config.clone()).unwrap();

let (tpu_forwards_port, tpu_forwards_sockets) =
multi_bind_in_range(bind_ip_addr, port_range, 8).expect("tpu_forwards multi_bind");

let (_tpu_forwards_port_quic, tpu_forwards_quic) = Self::bind(
let (_tpu_forwards_port_quic, tpu_forwards_quic) = Self::bind_with_config(
bind_ip_addr,
(
tpu_forwards_port + QUIC_PORT_OFFSET,
tpu_forwards_port + QUIC_PORT_OFFSET + 1,
),
quic_config.clone(),
);
let tpu_forwards_quic =
bind_more_with_config(tpu_forwards_quic, QUIC_ENDPOINTS, quic_config).unwrap();

let (tpu_vote_port, tpu_vote_sockets) =
multi_bind_in_range(bind_ip_addr, port_range, 1).expect("tpu_vote multi_bind");
Expand Down
Loading
Loading