Skip to content

Commit 13f5a3f

Browse files
authored
fix client side binds in TPU (#7455)
* fix client side binds in TPU * add changelog entry
1 parent 8abf225 commit 13f5a3f

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Release channels have their own copy of this changelog:
4040
* `--skip-poh-verify`
4141
* Deprecated snapshot archive formats have been removed and are no longer loadable.
4242
* Using `--snapshot-interval-slots 0` to disable generating snapshots has been removed. Use `--no-snapshots` instead.
43+
* Validator will now bind all ports within provided `--dynamic-port-range`, including the client ports. A range of at least 25 ports is recommended to avoid failures to bind during startup.
4344

4445
#### Changes
4546
* `--transaction-structure view` is now the default.

gossip/src/node.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ use {
1010
find_available_ports_in_range,
1111
sockets::{
1212
bind_gossip_port_in_range, bind_in_range_with_config, bind_more_with_config,
13-
bind_to_with_config, bind_two_in_range_with_offset_and_config,
14-
localhost_port_range_for_tests, multi_bind_in_range_with_config,
15-
SocketConfiguration as SocketConfig,
13+
bind_two_in_range_with_offset_and_config, localhost_port_range_for_tests,
14+
multi_bind_in_range_with_config, SocketConfiguration as SocketConfig,
1615
},
1716
PortRange,
1817
},
@@ -202,13 +201,17 @@ impl Node {
202201
let (alpenglow_port, alpenglow) =
203202
bind_in_range_with_config(bind_ip_addr, port_range, socket_config)
204203
.expect("Alpenglow port bind should succeed");
205-
// These are client sockets, so the port is set to be 0 because it must be ephimeral.
206-
let tpu_vote_forwarding_client =
207-
bind_to_with_config(bind_ip_addr, 0, socket_config).unwrap();
208-
let tpu_transaction_forwarding_client =
209-
bind_to_with_config(bind_ip_addr, 0, socket_config).unwrap();
210-
let quic_vote_client = bind_to_with_config(bind_ip_addr, 0, socket_config).unwrap();
211-
let rpc_sts_client = bind_to_with_config(bind_ip_addr, 0, socket_config).unwrap();
204+
// These are "client" sockets, so they could use ephemeral ports, but we
205+
// force them into the provided port_range to simplify the operations.
206+
let (_, tpu_vote_forwarding_client) =
207+
bind_in_range_with_config(bind_ip_addr, port_range, socket_config).unwrap();
208+
let (_, tpu_transaction_forwarding_client) =
209+
bind_in_range_with_config(bind_ip_addr, port_range, socket_config).unwrap();
210+
let (_, quic_vote_client) =
211+
bind_in_range_with_config(bind_ip_addr, port_range, socket_config).unwrap();
212+
213+
let (_, rpc_sts_client) =
214+
bind_in_range_with_config(bind_ip_addr, port_range, socket_config).unwrap();
212215

213216
let mut info = ContactInfo::new(
214217
*pubkey,

net-utils/src/sockets.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use {
1212
},
1313
};
1414
// base port for deconflicted allocations
15-
const BASE_PORT: u16 = 5000;
15+
const BASE_PORT: u16 = 2000;
1616
// how much to allocate per individual process.
1717
// we expect to have at most 64 concurrent tests in CI at any moment on a given host.
1818
const SLICE_PER_PROCESS: u16 = (u16::MAX - BASE_PORT) / 64;
@@ -26,7 +26,7 @@ const SLICE_PER_PROCESS: u16 = (u16::MAX - BASE_PORT) / 64;
2626
#[allow(clippy::arithmetic_side_effects)]
2727
pub fn unique_port_range_for_tests(size: u16) -> Range<u16> {
2828
static SLICE: AtomicU16 = AtomicU16::new(0);
29-
let offset = SLICE.fetch_add(size, Ordering::Relaxed);
29+
let offset = SLICE.fetch_add(size, Ordering::SeqCst);
3030
let start = offset
3131
+ match std::env::var("NEXTEST_TEST_GLOBAL_SLOT") {
3232
Ok(slot) => {
@@ -44,7 +44,7 @@ pub fn unique_port_range_for_tests(size: u16) -> Range<u16> {
4444
start..start + size
4545
}
4646

47-
/// Retrieve a free 20-port slice for unit tests
47+
/// Retrieve a free 25-port slice for unit tests
4848
///
4949
/// When running under nextest, this will try to provide
5050
/// a unique slice of port numbers (assuming no other nextest processes
@@ -54,7 +54,7 @@ pub fn unique_port_range_for_tests(size: u16) -> Range<u16> {
5454
/// When running without nextest, this will only bump an atomic and eventually
5555
/// panic when it runs out of port numbers to assign.
5656
pub fn localhost_port_range_for_tests() -> (u16, u16) {
57-
let pr = unique_port_range_for_tests(20);
57+
let pr = unique_port_range_for_tests(25);
5858
(pr.start, pr.end)
5959
}
6060

0 commit comments

Comments
 (0)