Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9eea7cf
move to bind_to / bind_to_async / ditch bind_to_unspecified/ async
puhtaytow Jul 14, 2025
a26d7d5
swap remaining tests
puhtaytow Jul 14, 2025
d498b42
inline bind_to in meta
puhtaytow Jul 14, 2025
a45ca39
support range and single ports scenarios
puhtaytow Jul 17, 2025
66e0081
fix typo
puhtaytow Jul 17, 2025
073dee6
move tests to new bind_to api
puhtaytow Jul 17, 2025
a6dd863
fix import
puhtaytow Jul 17, 2025
c50db86
move to new unique api
puhtaytow Jul 17, 2025
c396d24
finish it
puhtaytow Jul 17, 2025
f62e018
cosmetics / bring docs part / change function names to more explicit
puhtaytow Jul 17, 2025
975fa39
remove obsolete function
puhtaytow Jul 17, 2025
ccb3dac
simplify the code
puhtaytow Jul 17, 2025
2d489d6
further reduce code
puhtaytow Jul 17, 2025
5140795
more explicit function naming
puhtaytow Jul 17, 2025
5123fea
reduce even more code
puhtaytow Jul 17, 2025
993e52c
adjust func name
puhtaytow Jul 17, 2025
98b8402
fix docs
puhtaytow Jul 17, 2025
9f0b88a
remove remaining bind_to
puhtaytow Jul 17, 2025
ee6aef8
bring removed import
puhtaytow Jul 17, 2025
ff43cf2
Merge pull request #2 from puhtaytow/swap-bind_to_unspecified-to-bind…
puhtaytow Jul 17, 2025
807dce4
allocate single port instead of many for cases that don't need more t…
puhtaytow Jul 17, 2025
4d2894b
move to range / adjust code
puhtaytow Jul 18, 2025
b5e1bc0
cleanup
puhtaytow Jul 18, 2025
f836247
cleanup round 2
puhtaytow Jul 18, 2025
738c73a
cleanup round 3
puhtaytow Jul 18, 2025
47c0048
add deprecation for bind_to_unspecified
puhtaytow Jul 18, 2025
796b912
remove the deprecation of bind_to_unspecified / too many things to fi…
puhtaytow Jul 18, 2025
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
7 changes: 5 additions & 2 deletions client-test/tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use {
solana_keypair::Keypair,
solana_ledger::{blockstore::Blockstore, get_tmp_ledger_path_auto_delete},
solana_native_token::sol_to_lamports,
solana_net_utils::sockets::localhost_port_single_for_tests,
solana_pubkey::Pubkey,
solana_pubsub_client::{nonblocking, pubsub_client::PubsubClient},
solana_rpc::{
Expand Down Expand Up @@ -51,8 +52,10 @@ use {
};

fn pubsub_addr() -> SocketAddr {
let port_range = solana_net_utils::sockets::localhost_port_range_for_tests();
SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), port_range.0)
SocketAddr::new(
IpAddr::V4(Ipv4Addr::LOCALHOST),
localhost_port_single_for_tests(),
)
}

#[test]
Expand Down
10 changes: 4 additions & 6 deletions client/src/connection_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,8 @@ mod tests {

#[test]
fn test_connection_with_specified_client_endpoint() {
let port_range = localhost_port_range_for_tests();
let mut port_range = port_range.0..port_range.1;
let client_socket =
bind_to(IpAddr::V4(Ipv4Addr::LOCALHOST), port_range.next().unwrap()).unwrap();
let mut pr = localhost_port_range_for_tests();
let client_socket = bind_to(IpAddr::V4(Ipv4Addr::LOCALHOST), pr.next().unwrap()).unwrap();
let connection_cache = ConnectionCache::new_with_client_options(
"connection_cache_test",
1, // connection_pool_size
Expand All @@ -218,13 +216,13 @@ mod tests {
);

// server port 1:
let port1 = port_range.next().unwrap();
let port1 = pr.next().unwrap();
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), port1);
let conn = connection_cache.get_connection(&addr);
assert_eq!(conn.server_addr().port(), port1);

// server port 2:
let port2 = port_range.next().unwrap();
let port2 = pr.next().unwrap();
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), port2);
let conn = connection_cache.get_connection(&addr);
assert_eq!(conn.server_addr().port(), port2);
Expand Down
5 changes: 3 additions & 2 deletions core/src/repair/ancestor_hashes_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ mod test {
blockstore::make_many_slot_entries, get_tmp_ledger_path,
get_tmp_ledger_path_auto_delete, shred::Nonce,
},
solana_net_utils::bind_to_unspecified,
solana_net_utils::sockets::bind_to_localhost_unique,
solana_perf::packet::Packet,
solana_runtime::bank_forks::BankForks,
solana_signer::Signer,
Expand Down Expand Up @@ -1357,7 +1357,8 @@ mod test {
impl ManageAncestorHashesState {
fn new(bank_forks: Arc<RwLock<BankForks>>) -> Self {
let ancestor_hashes_request_statuses = Arc::new(DashMap::new());
let ancestor_hashes_request_socket = Arc::new(bind_to_unspecified().unwrap());
let ancestor_hashes_request_socket =
Arc::new(bind_to_localhost_unique().expect("should bind"));
let epoch_schedule = bank_forks
.read()
.unwrap()
Expand Down
3 changes: 1 addition & 2 deletions core/src/repair/quic_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1038,9 +1038,8 @@ mod tests {
.build()
.unwrap();
let keypairs: Vec<Keypair> = repeat_with(Keypair::new).take(NUM_ENDPOINTS).collect();
let port_range = localhost_port_range_for_tests();
let ip_addr = IpAddr::V4(Ipv4Addr::LOCALHOST);
let sockets: Vec<UdpSocket> = (port_range.0..port_range.1)
let sockets: Vec<UdpSocket> = localhost_port_range_for_tests()
.map(|port| bind_to(ip_addr, port).unwrap())
.take(NUM_ENDPOINTS)
.collect();
Expand Down
28 changes: 12 additions & 16 deletions core/src/repair/repair_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1276,18 +1276,12 @@ mod test {
get_tmp_ledger_path_auto_delete,
shred::max_ticks_per_n_shreds,
},
solana_net_utils::{
bind_to_unspecified,
sockets::{bind_to, localhost_port_range_for_tests},
},
solana_net_utils::sockets::bind_to_localhost_unique,
solana_runtime::bank::Bank,
solana_signer::Signer,
solana_streamer::socket::SocketAddrSpace,
solana_time_utils::timestamp,
std::{
collections::HashSet,
net::{IpAddr, Ipv4Addr},
},
std::collections::HashSet,
};

fn new_test_cluster_info() -> ClusterInfo {
Expand All @@ -1303,10 +1297,9 @@ mod test {
let pubkey = cluster_info.id();
let slot = 100;
let shred_index = 50;
let port_range = localhost_port_range_for_tests();
let reader = bind_to(IpAddr::V4(Ipv4Addr::LOCALHOST), port_range.0).expect("should bind");
let reader = bind_to_localhost_unique().expect("should bind");
let address = reader.local_addr().unwrap();
let sender = bind_to(IpAddr::V4(Ipv4Addr::LOCALHOST), port_range.1).expect("should bind");
let sender = bind_to_localhost_unique().expect("should bind");
let outstanding_repair_requests = Arc::new(RwLock::new(OutstandingShredRepairs::default()));

// Send a repair request
Expand Down Expand Up @@ -1662,7 +1655,7 @@ mod test {
};
let mut duplicate_slot_repair_statuses = HashMap::new();
let dead_slot = 9;
let receive_socket = &bind_to_unspecified().unwrap();
let receive_socket = &bind_to_localhost_unique().expect("should bind");
let duplicate_status = DuplicateSlotRepairStatus {
correct_ancestor_to_repair: (dead_slot, Hash::default()),
start_ts: u64::MAX,
Expand Down Expand Up @@ -1691,7 +1684,7 @@ mod test {
&blockstore,
&serve_repair,
&mut RepairStats::default(),
&bind_to_unspecified().unwrap(),
&bind_to_localhost_unique().expect("should bind"),
&None,
&RwLock::new(OutstandingRequests::default()),
&identity_keypair,
Expand All @@ -1717,7 +1710,7 @@ mod test {
&blockstore,
&serve_repair,
&mut RepairStats::default(),
&bind_to_unspecified().unwrap(),
&bind_to_localhost_unique().expect("should bind"),
&None,
&RwLock::new(OutstandingRequests::default()),
&identity_keypair,
Expand All @@ -1736,7 +1729,7 @@ mod test {
&blockstore,
&serve_repair,
&mut RepairStats::default(),
&bind_to_unspecified().unwrap(),
&bind_to_localhost_unique().expect("should bind"),
&None,
&RwLock::new(OutstandingRequests::default()),
&identity_keypair,
Expand All @@ -1751,7 +1744,10 @@ mod test {
let bank_forks = BankForks::new_rw_arc(bank);
let dummy_addr = Some((
Pubkey::default(),
bind_to_unspecified().unwrap().local_addr().unwrap(),
bind_to_localhost_unique()
.expect("should bind")
.local_addr()
.unwrap(),
));
let cluster_info = Arc::new(new_test_cluster_info());
let ledger_path = get_tmp_ledger_path_auto_delete!();
Expand Down
19 changes: 10 additions & 9 deletions gossip/src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use {
localhost_port_range_for_tests, multi_bind_in_range_with_config,
SocketConfiguration as SocketConfig,
},
PortRange, VALIDATOR_PORT_RANGE,
PortRange, RangeExt, VALIDATOR_PORT_RANGE,
},
solana_perf::{
data_budget::DataBudget,
Expand Down Expand Up @@ -2440,8 +2440,8 @@ impl Node {
bind_ip_addrs: BindIpAddrs {
addrs: vec![bind_ip_addr],
},
gossip_port: port_range.0,
port_range,
gossip_port: port_range.start,
port_range: port_range.as_tuple(),
advertised_ip: bind_ip_addr,
public_tpu_addr: None,
public_tpu_forwards_addr: None,
Expand All @@ -2452,7 +2452,8 @@ impl Node {
vortexor_receiver_addr: None,
};
let mut node = Self::new_with_external_ip(pubkey, config);
let rpc_ports: [u16; 2] = find_available_ports_in_range(bind_ip_addr, port_range).unwrap();
let rpc_ports: [u16; 2] =
find_available_ports_in_range(bind_ip_addr, port_range.as_tuple()).unwrap();
let rpc_addr = SocketAddr::new(bind_ip_addr, rpc_ports[0]);
let rpc_pubsub_addr = SocketAddr::new(bind_ip_addr, rpc_ports[1]);
node.info.set_rpc(rpc_addr).unwrap();
Expand Down Expand Up @@ -3142,7 +3143,7 @@ mod tests {
let config = NodeConfig {
advertised_ip: IpAddr::V4(ip),
gossip_port: 0,
port_range,
port_range: port_range.as_tuple(),
bind_ip_addrs: BindIpAddrs::new(vec![IpAddr::V4(ip)]).unwrap(),
public_tpu_addr: None,
public_tpu_forwards_addr: None,
Expand All @@ -3154,7 +3155,7 @@ mod tests {

let node = Node::new_with_external_ip(&solana_pubkey::new_rand(), config);

check_node_sockets(&node, IpAddr::V4(ip), port_range);
check_node_sockets(&node, IpAddr::V4(ip), port_range.as_tuple());
}

#[test]
Expand All @@ -3163,11 +3164,11 @@ mod tests {
// port returned by `bind_in_range()` might be snatched up before `Node::new_with_external_ip()` runs
let port_range = localhost_port_range_for_tests();
let ip = IpAddr::V4(Ipv4Addr::LOCALHOST);
let port = port_range.0;
let port = port_range.start;
let config = NodeConfig {
advertised_ip: ip,
gossip_port: port,
port_range,
port_range: port_range.as_tuple(),
bind_ip_addrs: BindIpAddrs::new(vec![ip]).unwrap(),
public_tpu_addr: None,
public_tpu_forwards_addr: None,
Expand All @@ -3179,7 +3180,7 @@ mod tests {

let node = Node::new_with_external_ip(&solana_pubkey::new_rand(), config);

check_node_sockets(&node, ip, port_range);
check_node_sockets(&node, ip, port_range.as_tuple());

assert_eq!(node.sockets.gossip.local_addr().unwrap().port(), port);
}
Expand Down
Loading