From bbddffa805e46d76ec57e99760b83cc0f198a56f Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 10 Sep 2020 22:02:50 +0000 Subject: [PATCH] `solana-validator --rpc-bind-address` argument now works as expected (bp #12168) (#12174) * `solana-validator --rpc-bind-address` argument now works as expected (cherry picked from commit 6f325d4594f0dee35600e549b9a58dfd95a15022) * Update bootstrap-validator.sh Co-authored-by: Michael Vines --- core/src/validator.rs | 50 ++++++++++-------------- local-cluster/src/local_cluster.rs | 23 +++++------ validator/src/main.rs | 62 +++++++++++++++++------------- 3 files changed, 66 insertions(+), 69 deletions(-) diff --git a/core/src/validator.rs b/core/src/validator.rs index f6e4d43a886ce8..aa573e6d52e301 100644 --- a/core/src/validator.rs +++ b/core/src/validator.rs @@ -55,7 +55,7 @@ use solana_sdk::{ use solana_vote_program::vote_state::VoteState; use std::{ collections::HashSet, - net::{IpAddr, Ipv4Addr, SocketAddr}, + net::SocketAddr, path::{Path, PathBuf}, process, sync::atomic::{AtomicBool, Ordering}, @@ -76,7 +76,7 @@ pub struct ValidatorConfig { pub voting_disabled: bool, pub account_paths: Vec, pub rpc_config: JsonRpcConfig, - pub rpc_ports: Option<(u16, u16, u16)>, // (JsonRpc, JsonRpcPubSub, Banks) + pub rpc_addrs: Option<(SocketAddr, SocketAddr, SocketAddr)>, // (JsonRpc, JsonRpcPubSub, Banks) pub snapshot_config: Option, pub max_ledger_shreds: Option, pub broadcast_stage_type: BroadcastStageType, @@ -106,7 +106,7 @@ impl Default for ValidatorConfig { max_ledger_shreds: None, account_paths: Vec::new(), rpc_config: JsonRpcConfig::default(), - rpc_ports: None, + rpc_addrs: None, snapshot_config: None, broadcast_stage_type: BroadcastStageType::Standard, enable_partition: None, @@ -345,20 +345,20 @@ impl Validator { let rpc_override_health_check = Arc::new(AtomicBool::new(false)); let rpc_service = config - .rpc_ports - .map(|(rpc_port, rpc_pubsub_port, rpc_banks_port)| { + .rpc_addrs + .map(|(rpc_addr, rpc_pubsub_addr, rpc_banks_addr)| { if ContactInfo::is_valid_address(&node.info.rpc) { assert!(ContactInfo::is_valid_address(&node.info.rpc_pubsub)); - assert_eq!(rpc_port, node.info.rpc.port()); - assert_eq!(rpc_pubsub_port, node.info.rpc_pubsub.port()); - assert_eq!(rpc_banks_port, node.info.rpc_banks.port()); + assert_eq!(rpc_addr.port(), node.info.rpc.port()); + assert_eq!(rpc_pubsub_addr.port(), node.info.rpc_pubsub.port()); + assert_eq!(rpc_banks_addr.port(), node.info.rpc_banks.port()); } else { assert!(!ContactInfo::is_valid_address(&node.info.rpc_pubsub)); } let tpu_address = cluster_info.my_contact_info().tpu; ( JsonRpcService::new( - SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), rpc_port), + rpc_addr, config.rpc_config.clone(), config.snapshot_config.clone(), bank_forks.clone(), @@ -372,13 +372,9 @@ impl Validator { config.trusted_validators.clone(), rpc_override_health_check.clone(), ), - PubSubService::new( - &subscriptions, - SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), rpc_pubsub_port), - &exit, - ), + PubSubService::new(&subscriptions, rpc_pubsub_addr, &exit), RpcBanksService::new( - SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), rpc_banks_port), + rpc_banks_addr, tpu_address, &bank_forks, &block_commitment_cache, @@ -658,7 +654,7 @@ fn new_banks_from_ledger( let blockstore = Arc::new(blockstore); let transaction_history_services = - if config.rpc_ports.is_some() && config.rpc_config.enable_rpc_transaction_history { + if config.rpc_addrs.is_some() && config.rpc_config.enable_rpc_transaction_history { initialize_rpc_transaction_history_services(blockstore.clone(), exit) } else { TransactionHistoryServices::default() @@ -902,11 +898,7 @@ impl TestValidator { let (ledger_path, blockhash) = create_new_tmp_ledger!(&genesis_config); let config = ValidatorConfig { - rpc_ports: Some(( - node.info.rpc.port(), - node.info.rpc_pubsub.port(), - node.info.rpc_banks.port(), - )), + rpc_addrs: Some((node.info.rpc, node.info.rpc_pubsub, node.info.rpc_banks)), ..ValidatorConfig::default() }; let vote_pubkey = voting_keypair.pubkey(); @@ -1072,10 +1064,10 @@ mod tests { let voting_keypair = Arc::new(Keypair::new()); let config = ValidatorConfig { - rpc_ports: Some(( - validator_node.info.rpc.port(), - validator_node.info.rpc_pubsub.port(), - validator_node.info.rpc_banks.port(), + rpc_addrs: Some(( + validator_node.info.rpc, + validator_node.info.rpc_pubsub, + validator_node.info.rpc_banks, )), ..ValidatorConfig::default() }; @@ -1147,10 +1139,10 @@ mod tests { ledger_paths.push(validator_ledger_path.clone()); let vote_account_keypair = Keypair::new(); let config = ValidatorConfig { - rpc_ports: Some(( - validator_node.info.rpc.port(), - validator_node.info.rpc_pubsub.port(), - validator_node.info.rpc_banks.port(), + rpc_addrs: Some(( + validator_node.info.rpc, + validator_node.info.rpc_pubsub, + validator_node.info.rpc_banks, )), ..ValidatorConfig::default() }; diff --git a/local-cluster/src/local_cluster.rs b/local-cluster/src/local_cluster.rs index 5443160cc59a28..ebb67ecac4b6cf 100644 --- a/local-cluster/src/local_cluster.rs +++ b/local-cluster/src/local_cluster.rs @@ -201,10 +201,10 @@ impl LocalCluster { let (leader_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config); let leader_contact_info = leader_node.info.clone(); let mut leader_config = config.validator_configs[0].clone(); - leader_config.rpc_ports = Some(( - leader_node.info.rpc.port(), - leader_node.info.rpc_pubsub.port(), - leader_node.info.rpc_banks.port(), + leader_config.rpc_addrs = Some(( + leader_node.info.rpc, + leader_node.info.rpc_pubsub, + leader_node.info.rpc_banks, )); leader_config.account_paths = vec![leader_ledger_path.join("accounts")]; let leader_keypair = Arc::new(Keypair::from_bytes(&leader_keypair.to_bytes()).unwrap()); @@ -351,10 +351,10 @@ impl LocalCluster { } let mut config = validator_config.clone(); - config.rpc_ports = Some(( - validator_node.info.rpc.port(), - validator_node.info.rpc_pubsub.port(), - validator_node.info.rpc_banks.port(), + config.rpc_addrs = Some(( + validator_node.info.rpc, + validator_node.info.rpc_pubsub, + validator_node.info.rpc_banks, )); config.account_paths = vec![ledger_path.join("accounts")]; let voting_keypair = voting_keypair.unwrap(); @@ -625,11 +625,8 @@ impl Cluster for LocalCluster { // Update the stored ContactInfo for this node let node = Node::new_localhost_with_pubkey(&pubkey); cluster_validator_info.info.contact_info = node.info.clone(); - cluster_validator_info.config.rpc_ports = Some(( - node.info.rpc.port(), - node.info.rpc_pubsub.port(), - node.info.rpc_banks.port(), - )); + cluster_validator_info.config.rpc_addrs = + Some((node.info.rpc, node.info.rpc_pubsub, node.info.rpc_banks)); let entry_point_info = { if *pubkey == self.entry_point_info.id { diff --git a/validator/src/main.rs b/validator/src/main.rs index f7a466a790cf35..39a1a65792ce4e 100644 --- a/validator/src/main.rs +++ b/validator/src/main.rs @@ -967,6 +967,15 @@ pub fn main() { "--repair-validator", ); + let bind_address = solana_net_utils::parse_host(matches.value_of("bind_address").unwrap()) + .expect("invalid bind_address"); + let rpc_bind_address = if matches.is_present("rpc_bind_address") { + solana_net_utils::parse_host(matches.value_of("rpc_bind_address").unwrap()) + .expect("invalid rpc_bind_address") + } else { + bind_address + }; + let mut validator_config = ValidatorConfig { dev_halt_at_slot: value_t!(matches, "dev_halt_at_slot", Slot).ok(), expected_genesis_hash: matches @@ -994,9 +1003,13 @@ pub fn main() { u64 ), }, - rpc_ports: value_t!(matches, "rpc_port", u16) - .ok() - .map(|rpc_port| (rpc_port, rpc_port + 1, rpc_port + 3)), + rpc_addrs: value_t!(matches, "rpc_port", u16).ok().map(|rpc_port| { + ( + SocketAddr::new(rpc_bind_address, rpc_port), + SocketAddr::new(rpc_bind_address, rpc_port + 1), + SocketAddr::new(rpc_bind_address, rpc_port + 3), + ) + }), voting_disabled: matches.is_present("no_voting"), wait_for_supermajority: value_t!(matches, "wait_for_supermajority", Slot).ok(), trusted_validators, @@ -1017,15 +1030,6 @@ pub fn main() { solana_net_utils::parse_port_range(matches.value_of("dynamic_port_range").unwrap()) .expect("invalid dynamic_port_range"); - let bind_address = solana_net_utils::parse_host(matches.value_of("bind_address").unwrap()) - .expect("invalid bind_address"); - let rpc_bind_address = if matches.is_present("rpc_bind_address") { - solana_net_utils::parse_host(matches.value_of("rpc_bind_address").unwrap()) - .expect("invalid rpc_bind_address") - } else { - bind_address - }; - let account_paths = if let Some(account_paths) = matches.value_of("account_paths") { account_paths.split(',').map(PathBuf::from).collect() } else { @@ -1218,10 +1222,10 @@ pub fn main() { ); if !private_rpc { - if let Some((rpc_port, rpc_pubsub_port, rpc_banks_port)) = validator_config.rpc_ports { - node.info.rpc = SocketAddr::new(node.info.gossip.ip(), rpc_port); - node.info.rpc_pubsub = SocketAddr::new(node.info.gossip.ip(), rpc_pubsub_port); - node.info.rpc_banks = SocketAddr::new(node.info.gossip.ip(), rpc_banks_port); + if let Some((rpc_addr, rpc_pubsub_addr, rpc_banks_addr)) = validator_config.rpc_addrs { + node.info.rpc = SocketAddr::new(node.info.gossip.ip(), rpc_addr.port()); + node.info.rpc_pubsub = SocketAddr::new(node.info.gossip.ip(), rpc_pubsub_addr.port()); + node.info.rpc_banks = SocketAddr::new(node.info.gossip.ip(), rpc_banks_addr.port()); } } @@ -1240,19 +1244,23 @@ pub fn main() { let mut tcp_listeners = vec![]; if !private_rpc { - if let Some((rpc_port, rpc_pubsub_port, rpc_banks_port)) = validator_config.rpc_ports { - for (purpose, port) in &[ - ("RPC", rpc_port), - ("RPC pubsub", rpc_pubsub_port), - ("RPC banks", rpc_banks_port), + if let Some((rpc_addr, rpc_pubsub_addr, rpc_banks_addr)) = validator_config.rpc_addrs { + for (purpose, addr) in &[ + ("RPC", rpc_addr), + ("RPC pubsub", rpc_pubsub_addr), + ("RPC banks", rpc_banks_addr), ] { tcp_listeners.push(( - *port, - TcpListener::bind(&SocketAddr::from((rpc_bind_address, *port))) - .unwrap_or_else(|err| { - error!("Unable to bind to tcp/{} for {}: {}", port, purpose, err); - exit(1); - }), + addr.port(), + TcpListener::bind(addr).unwrap_or_else(|err| { + error!( + "Unable to bind to tcp/{} for {}: {}", + addr.port(), + purpose, + err + ); + exit(1); + }), )); } }