|
52 | 52 | solana_ledger::shred::Shred,
|
53 | 53 | solana_net_utils::{
|
54 | 54 | bind_common_in_range_with_config, bind_common_with_config, bind_in_range,
|
55 |
| - bind_in_range_with_config, bind_more_with_config, bind_to_localhost, bind_to_unspecified, |
56 |
| - bind_to_with_config, bind_two_in_range_with_offset_and_config, |
57 |
| - find_available_port_in_range, multi_bind_in_range_with_config, PortRange, SocketConfig, |
58 |
| - VALIDATOR_PORT_RANGE, |
| 55 | + bind_in_range_with_config, bind_more_with_config, bind_to_unspecified, |
| 56 | + bind_two_in_range_with_offset_and_config, find_available_port_in_range, |
| 57 | + multi_bind_in_range_with_config, PortRange, SocketConfig, VALIDATOR_PORT_RANGE, |
59 | 58 | },
|
60 | 59 | solana_perf::{
|
61 | 60 | data_budget::DataBudget,
|
|
85 | 84 | io::{BufReader, BufWriter, Write},
|
86 | 85 | iter::repeat,
|
87 | 86 | net::{IpAddr, Ipv4Addr, SocketAddr, TcpListener, UdpSocket},
|
88 |
| - num::NonZeroUsize, |
| 87 | + num::{NonZero, NonZeroUsize}, |
89 | 88 | ops::{Deref, Div},
|
90 | 89 | path::{Path, PathBuf},
|
91 | 90 | rc::Rc,
|
@@ -2413,143 +2412,22 @@ impl Node {
|
2413 | 2412 | }
|
2414 | 2413 |
|
2415 | 2414 | pub fn new_localhost_with_pubkey(pubkey: &Pubkey) -> Self {
|
2416 |
| - Self::new_localhost_with_pubkey_and_quic_endpoints(pubkey, DEFAULT_QUIC_ENDPOINTS) |
2417 |
| - } |
2418 |
| - |
2419 |
| - pub fn new_localhost_with_pubkey_and_quic_endpoints( |
2420 |
| - pubkey: &Pubkey, |
2421 |
| - num_quic_endpoints: usize, |
2422 |
| - ) -> Self { |
2423 | 2415 | let localhost_ip_addr = IpAddr::V4(Ipv4Addr::LOCALHOST);
|
2424 | 2416 | let port_range = (1024, 65535);
|
2425 |
| - |
2426 |
| - let udp_config = SocketConfig::default(); |
2427 |
| - let quic_config = SocketConfig::default().reuseport(true); |
2428 |
| - let ((_tpu_port, tpu), (_tpu_quic_port, tpu_quic)) = |
2429 |
| - bind_two_in_range_with_offset_and_config( |
2430 |
| - localhost_ip_addr, |
2431 |
| - port_range, |
2432 |
| - QUIC_PORT_OFFSET, |
2433 |
| - udp_config, |
2434 |
| - quic_config, |
2435 |
| - ) |
2436 |
| - .unwrap(); |
2437 |
| - let tpu_quic = bind_more_with_config(tpu_quic, num_quic_endpoints, quic_config).unwrap(); |
2438 |
| - let (gossip_port, (gossip, ip_echo)) = |
2439 |
| - bind_common_in_range_with_config(localhost_ip_addr, port_range, udp_config).unwrap(); |
2440 |
| - let gossip_addr = SocketAddr::new(localhost_ip_addr, gossip_port); |
2441 |
| - let tvu = bind_to_localhost().unwrap(); |
2442 |
| - let tvu_quic = bind_to_localhost().unwrap(); |
2443 |
| - let ((_tpu_forwards_port, tpu_forwards), (_tpu_forwards_quic_port, tpu_forwards_quic)) = |
2444 |
| - bind_two_in_range_with_offset_and_config( |
2445 |
| - localhost_ip_addr, |
2446 |
| - port_range, |
2447 |
| - QUIC_PORT_OFFSET, |
2448 |
| - udp_config, |
2449 |
| - quic_config, |
2450 |
| - ) |
2451 |
| - .unwrap(); |
2452 |
| - let tpu_forwards_quic = |
2453 |
| - bind_more_with_config(tpu_forwards_quic, num_quic_endpoints, quic_config).unwrap(); |
2454 |
| - let tpu_vote = bind_to_localhost().unwrap(); |
2455 |
| - let tpu_vote_quic = bind_to_localhost().unwrap(); |
2456 |
| - let tpu_vote_quic = |
2457 |
| - bind_more_with_config(tpu_vote_quic, num_quic_endpoints, quic_config).unwrap(); |
2458 |
| - |
2459 |
| - let repair = bind_to_localhost().unwrap(); |
2460 |
| - let repair_quic = bind_to_localhost().unwrap(); |
2461 |
| - let rpc_port = find_available_port_in_range(localhost_ip_addr, port_range).unwrap(); |
2462 |
| - let rpc_addr = SocketAddr::new(localhost_ip_addr, rpc_port); |
2463 |
| - let rpc_pubsub_port = find_available_port_in_range(localhost_ip_addr, port_range).unwrap(); |
2464 |
| - let rpc_pubsub_addr = SocketAddr::new(localhost_ip_addr, rpc_pubsub_port); |
2465 |
| - let broadcast = vec![bind_to_unspecified().unwrap()]; |
2466 |
| - let retransmit_socket = bind_to_unspecified().unwrap(); |
2467 |
| - let serve_repair = bind_to_localhost().unwrap(); |
2468 |
| - let serve_repair_quic = bind_to_localhost().unwrap(); |
2469 |
| - let ancestor_hashes_requests = bind_to_unspecified().unwrap(); |
2470 |
| - let ancestor_hashes_requests_quic = bind_to_unspecified().unwrap(); |
2471 |
| - |
2472 |
| - let tpu_vote_forwards_client = bind_to_localhost().unwrap(); |
2473 |
| - |
2474 |
| - let mut info = ContactInfo::new( |
2475 |
| - *pubkey, |
2476 |
| - timestamp(), // wallclock |
2477 |
| - 0u16, // shred_version |
2478 |
| - ); |
2479 |
| - macro_rules! set_socket { |
2480 |
| - ($method:ident, $addr:expr, $name:literal) => { |
2481 |
| - info.$method($addr).expect(&format!( |
2482 |
| - "Operator must spin up node with valid {} address", |
2483 |
| - $name |
2484 |
| - )) |
2485 |
| - }; |
2486 |
| - ($method:ident, $protocol:ident, $addr:expr, $name:literal) => {{ |
2487 |
| - info.$method(contact_info::Protocol::$protocol, $addr) |
2488 |
| - .expect(&format!( |
2489 |
| - "Operator must spin up node with valid {} address", |
2490 |
| - $name |
2491 |
| - )) |
2492 |
| - }}; |
2493 |
| - } |
2494 |
| - set_socket!(set_gossip, gossip_addr, "gossip"); |
2495 |
| - set_socket!(set_tvu, UDP, tvu.local_addr().unwrap(), "TVU"); |
2496 |
| - set_socket!(set_tvu, QUIC, tvu_quic.local_addr().unwrap(), "TVU QUIC"); |
2497 |
| - set_socket!(set_tpu, tpu.local_addr().unwrap(), "TPU"); |
2498 |
| - set_socket!( |
2499 |
| - set_tpu_forwards, |
2500 |
| - tpu_forwards.local_addr().unwrap(), |
2501 |
| - "TPU-forwards" |
2502 |
| - ); |
2503 |
| - set_socket!( |
2504 |
| - set_tpu_vote, |
2505 |
| - UDP, |
2506 |
| - tpu_vote.local_addr().unwrap(), |
2507 |
| - "TPU-vote" |
2508 |
| - ); |
2509 |
| - set_socket!( |
2510 |
| - set_tpu_vote, |
2511 |
| - QUIC, |
2512 |
| - tpu_vote_quic[0].local_addr().unwrap(), |
2513 |
| - "TPU-vote QUIC" |
2514 |
| - ); |
2515 |
| - set_socket!(set_rpc, rpc_addr, "RPC"); |
2516 |
| - set_socket!(set_rpc_pubsub, rpc_pubsub_addr, "RPC-pubsub"); |
2517 |
| - set_socket!( |
2518 |
| - set_serve_repair, |
2519 |
| - UDP, |
2520 |
| - serve_repair.local_addr().unwrap(), |
2521 |
| - "serve-repair" |
2522 |
| - ); |
2523 |
| - set_socket!( |
2524 |
| - set_serve_repair, |
2525 |
| - QUIC, |
2526 |
| - serve_repair_quic.local_addr().unwrap(), |
2527 |
| - "serve-repair QUIC" |
2528 |
| - ); |
2529 |
| - Node { |
2530 |
| - info, |
2531 |
| - sockets: Sockets { |
2532 |
| - gossip, |
2533 |
| - ip_echo: Some(ip_echo), |
2534 |
| - tvu: vec![tvu], |
2535 |
| - tvu_quic, |
2536 |
| - tpu: vec![tpu], |
2537 |
| - tpu_forwards: vec![tpu_forwards], |
2538 |
| - tpu_vote: vec![tpu_vote], |
2539 |
| - broadcast, |
2540 |
| - repair, |
2541 |
| - repair_quic, |
2542 |
| - retransmit_sockets: vec![retransmit_socket], |
2543 |
| - serve_repair, |
2544 |
| - serve_repair_quic, |
2545 |
| - ancestor_hashes_requests, |
2546 |
| - ancestor_hashes_requests_quic, |
2547 |
| - tpu_quic, |
2548 |
| - tpu_forwards_quic, |
2549 |
| - tpu_vote_quic, |
2550 |
| - tpu_vote_forwards_client, |
2551 |
| - }, |
2552 |
| - } |
| 2417 | + let gossip_port = find_available_port_in_range(localhost_ip_addr, port_range) |
| 2418 | + .expect("At least one open port should be available"); |
| 2419 | + let config = NodeConfig { |
| 2420 | + gossip_addr: SocketAddr::new(localhost_ip_addr, gossip_port), |
| 2421 | + port_range, |
| 2422 | + bind_ip_addr: localhost_ip_addr, |
| 2423 | + public_tpu_addr: None, |
| 2424 | + public_tpu_forwards_addr: None, |
| 2425 | + num_tvu_receive_sockets: NonZero::new(1).unwrap(), |
| 2426 | + num_tvu_retransmit_sockets: NonZero::new(1).unwrap(), |
| 2427 | + num_quic_endpoints: NonZero::new(DEFAULT_QUIC_ENDPOINTS) |
| 2428 | + .expect("Number of QUIC endpoints can not be zero"), |
| 2429 | + }; |
| 2430 | + Self::new_with_external_ip(pubkey, config) |
2553 | 2431 | }
|
2554 | 2432 |
|
2555 | 2433 | fn get_gossip_port(
|
@@ -2652,7 +2530,8 @@ impl Node {
|
2652 | 2530 | let rpc_pubsub_port = find_available_port_in_range(bind_ip_addr, port_range).unwrap();
|
2653 | 2531 |
|
2654 | 2532 | // These are client sockets, so the port is set to be 0 because it must be ephimeral.
|
2655 |
| - let tpu_vote_forwards_client = bind_to_with_config(bind_ip_addr, 0, socket_config).unwrap(); |
| 2533 | + let tpu_vote_forwards_client = |
| 2534 | + Self::bind_with_config(bind_ip_addr, 0, socket_config).unwrap(); |
2656 | 2535 |
|
2657 | 2536 | let addr = gossip_addr.ip();
|
2658 | 2537 | let mut info = ContactInfo::new(
|
|
0 commit comments