`solana-validator --rpc-bind-address` argument now works as expected

This commit is contained in:
Michael Vines 2020-09-10 08:56:26 -07:00
parent 361e5322e4
commit 6f325d4594
4 changed files with 67 additions and 69 deletions

View File

@ -56,7 +56,7 @@ use solana_sdk::{
use solana_vote_program::vote_state::VoteState; use solana_vote_program::vote_state::VoteState;
use std::{ use std::{
collections::HashSet, collections::HashSet,
net::{IpAddr, Ipv4Addr, SocketAddr}, net::SocketAddr,
path::{Path, PathBuf}, path::{Path, PathBuf},
process, process,
sync::atomic::{AtomicBool, Ordering}, sync::atomic::{AtomicBool, Ordering},
@ -77,7 +77,7 @@ pub struct ValidatorConfig {
pub voting_disabled: bool, pub voting_disabled: bool,
pub account_paths: Vec<PathBuf>, pub account_paths: Vec<PathBuf>,
pub rpc_config: JsonRpcConfig, 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<SnapshotConfig>, pub snapshot_config: Option<SnapshotConfig>,
pub max_ledger_shreds: Option<u64>, pub max_ledger_shreds: Option<u64>,
pub broadcast_stage_type: BroadcastStageType, pub broadcast_stage_type: BroadcastStageType,
@ -107,7 +107,7 @@ impl Default for ValidatorConfig {
max_ledger_shreds: None, max_ledger_shreds: None,
account_paths: Vec::new(), account_paths: Vec::new(),
rpc_config: JsonRpcConfig::default(), rpc_config: JsonRpcConfig::default(),
rpc_ports: None, rpc_addrs: None,
snapshot_config: None, snapshot_config: None,
broadcast_stage_type: BroadcastStageType::Standard, broadcast_stage_type: BroadcastStageType::Standard,
enable_partition: None, enable_partition: None,
@ -351,20 +351,20 @@ impl Validator {
let rpc_override_health_check = Arc::new(AtomicBool::new(false)); let rpc_override_health_check = Arc::new(AtomicBool::new(false));
let rpc_service = config let rpc_service = config
.rpc_ports .rpc_addrs
.map(|(rpc_port, rpc_pubsub_port, rpc_banks_port)| { .map(|(rpc_addr, rpc_pubsub_addr, rpc_banks_addr)| {
if ContactInfo::is_valid_address(&node.info.rpc) { if ContactInfo::is_valid_address(&node.info.rpc) {
assert!(ContactInfo::is_valid_address(&node.info.rpc_pubsub)); assert!(ContactInfo::is_valid_address(&node.info.rpc_pubsub));
assert_eq!(rpc_port, node.info.rpc.port()); assert_eq!(rpc_addr.port(), node.info.rpc.port());
assert_eq!(rpc_pubsub_port, node.info.rpc_pubsub.port()); assert_eq!(rpc_pubsub_addr.port(), node.info.rpc_pubsub.port());
assert_eq!(rpc_banks_port, node.info.rpc_banks.port()); assert_eq!(rpc_banks_addr.port(), node.info.rpc_banks.port());
} else { } else {
assert!(!ContactInfo::is_valid_address(&node.info.rpc_pubsub)); assert!(!ContactInfo::is_valid_address(&node.info.rpc_pubsub));
} }
let tpu_address = cluster_info.my_contact_info().tpu; let tpu_address = cluster_info.my_contact_info().tpu;
( (
JsonRpcService::new( JsonRpcService::new(
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), rpc_port), rpc_addr,
config.rpc_config.clone(), config.rpc_config.clone(),
config.snapshot_config.clone(), config.snapshot_config.clone(),
bank_forks.clone(), bank_forks.clone(),
@ -378,13 +378,9 @@ impl Validator {
config.trusted_validators.clone(), config.trusted_validators.clone(),
rpc_override_health_check.clone(), rpc_override_health_check.clone(),
), ),
PubSubService::new( PubSubService::new(&subscriptions, rpc_pubsub_addr, &exit),
&subscriptions,
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), rpc_pubsub_port),
&exit,
),
RpcBanksService::new( RpcBanksService::new(
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), rpc_banks_port), rpc_banks_addr,
tpu_address, tpu_address,
&bank_forks, &bank_forks,
&block_commitment_cache, &block_commitment_cache,
@ -670,7 +666,7 @@ fn new_banks_from_ledger(
let blockstore = Arc::new(blockstore); let blockstore = Arc::new(blockstore);
let transaction_history_services = 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) initialize_rpc_transaction_history_services(blockstore.clone(), exit)
} else { } else {
TransactionHistoryServices::default() TransactionHistoryServices::default()
@ -921,11 +917,7 @@ impl TestValidator {
let (ledger_path, blockhash) = create_new_tmp_ledger!(&genesis_config); let (ledger_path, blockhash) = create_new_tmp_ledger!(&genesis_config);
let config = ValidatorConfig { let config = ValidatorConfig {
rpc_ports: Some(( rpc_addrs: Some((node.info.rpc, node.info.rpc_pubsub, node.info.rpc_banks)),
node.info.rpc.port(),
node.info.rpc_pubsub.port(),
node.info.rpc_banks.port(),
)),
..ValidatorConfig::default() ..ValidatorConfig::default()
}; };
let vote_pubkey = voting_keypair.pubkey(); let vote_pubkey = voting_keypair.pubkey();
@ -1091,10 +1083,10 @@ mod tests {
let voting_keypair = Arc::new(Keypair::new()); let voting_keypair = Arc::new(Keypair::new());
let config = ValidatorConfig { let config = ValidatorConfig {
rpc_ports: Some(( rpc_addrs: Some((
validator_node.info.rpc.port(), validator_node.info.rpc,
validator_node.info.rpc_pubsub.port(), validator_node.info.rpc_pubsub,
validator_node.info.rpc_banks.port(), validator_node.info.rpc_banks,
)), )),
..ValidatorConfig::default() ..ValidatorConfig::default()
}; };
@ -1166,10 +1158,10 @@ mod tests {
ledger_paths.push(validator_ledger_path.clone()); ledger_paths.push(validator_ledger_path.clone());
let vote_account_keypair = Keypair::new(); let vote_account_keypair = Keypair::new();
let config = ValidatorConfig { let config = ValidatorConfig {
rpc_ports: Some(( rpc_addrs: Some((
validator_node.info.rpc.port(), validator_node.info.rpc,
validator_node.info.rpc_pubsub.port(), validator_node.info.rpc_pubsub,
validator_node.info.rpc_banks.port(), validator_node.info.rpc_banks,
)), )),
..ValidatorConfig::default() ..ValidatorConfig::default()
}; };

View File

@ -201,10 +201,10 @@ impl LocalCluster {
let (leader_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config); let (leader_ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config);
let leader_contact_info = leader_node.info.clone(); let leader_contact_info = leader_node.info.clone();
let mut leader_config = config.validator_configs[0].clone(); let mut leader_config = config.validator_configs[0].clone();
leader_config.rpc_ports = Some(( leader_config.rpc_addrs = Some((
leader_node.info.rpc.port(), leader_node.info.rpc,
leader_node.info.rpc_pubsub.port(), leader_node.info.rpc_pubsub,
leader_node.info.rpc_banks.port(), leader_node.info.rpc_banks,
)); ));
leader_config.account_paths = vec![leader_ledger_path.join("accounts")]; leader_config.account_paths = vec![leader_ledger_path.join("accounts")];
let leader_keypair = Arc::new(Keypair::from_bytes(&leader_keypair.to_bytes()).unwrap()); 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(); let mut config = validator_config.clone();
config.rpc_ports = Some(( config.rpc_addrs = Some((
validator_node.info.rpc.port(), validator_node.info.rpc,
validator_node.info.rpc_pubsub.port(), validator_node.info.rpc_pubsub,
validator_node.info.rpc_banks.port(), validator_node.info.rpc_banks,
)); ));
config.account_paths = vec![ledger_path.join("accounts")]; config.account_paths = vec![ledger_path.join("accounts")];
let voting_keypair = voting_keypair.unwrap(); let voting_keypair = voting_keypair.unwrap();
@ -625,11 +625,8 @@ impl Cluster for LocalCluster {
// Update the stored ContactInfo for this node // Update the stored ContactInfo for this node
let node = Node::new_localhost_with_pubkey(&pubkey); let node = Node::new_localhost_with_pubkey(&pubkey);
cluster_validator_info.info.contact_info = node.info.clone(); cluster_validator_info.info.contact_info = node.info.clone();
cluster_validator_info.config.rpc_ports = Some(( cluster_validator_info.config.rpc_addrs =
node.info.rpc.port(), Some((node.info.rpc, node.info.rpc_pubsub, node.info.rpc_banks));
node.info.rpc_pubsub.port(),
node.info.rpc_banks.port(),
));
let entry_point_info = { let entry_point_info = {
if *pubkey == self.entry_point_info.id { if *pubkey == self.entry_point_info.id {

View File

@ -99,6 +99,7 @@ args+=(
--identity "$identity" --identity "$identity"
--vote-account "$vote_account" --vote-account "$vote_account"
--rpc-faucet-address 127.0.0.1:9900 --rpc-faucet-address 127.0.0.1:9900
#--rpc-bind-address 192.168.1.207
) )
default_arg --gossip-port 8001 default_arg --gossip-port 8001
default_arg --log - default_arg --log -

View File

@ -967,6 +967,15 @@ pub fn main() {
"--repair-validator", "--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 { let mut validator_config = ValidatorConfig {
dev_halt_at_slot: value_t!(matches, "dev_halt_at_slot", Slot).ok(), dev_halt_at_slot: value_t!(matches, "dev_halt_at_slot", Slot).ok(),
expected_genesis_hash: matches expected_genesis_hash: matches
@ -994,9 +1003,13 @@ pub fn main() {
u64 u64
), ),
}, },
rpc_ports: value_t!(matches, "rpc_port", u16) rpc_addrs: value_t!(matches, "rpc_port", u16).ok().map(|rpc_port| {
.ok() (
.map(|rpc_port| (rpc_port, rpc_port + 1, rpc_port + 3)), 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"), voting_disabled: matches.is_present("no_voting"),
wait_for_supermajority: value_t!(matches, "wait_for_supermajority", Slot).ok(), wait_for_supermajority: value_t!(matches, "wait_for_supermajority", Slot).ok(),
trusted_validators, trusted_validators,
@ -1017,15 +1030,6 @@ pub fn main() {
solana_net_utils::parse_port_range(matches.value_of("dynamic_port_range").unwrap()) solana_net_utils::parse_port_range(matches.value_of("dynamic_port_range").unwrap())
.expect("invalid dynamic_port_range"); .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") { let account_paths = if let Some(account_paths) = matches.value_of("account_paths") {
account_paths.split(',').map(PathBuf::from).collect() account_paths.split(',').map(PathBuf::from).collect()
} else { } else {
@ -1218,10 +1222,10 @@ pub fn main() {
); );
if !private_rpc { if !private_rpc {
if let Some((rpc_port, rpc_pubsub_port, rpc_banks_port)) = validator_config.rpc_ports { 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_port); node.info.rpc = SocketAddr::new(node.info.gossip.ip(), rpc_addr.port());
node.info.rpc_pubsub = SocketAddr::new(node.info.gossip.ip(), rpc_pubsub_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_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![]; let mut tcp_listeners = vec![];
if !private_rpc { if !private_rpc {
if let Some((rpc_port, rpc_pubsub_port, rpc_banks_port)) = validator_config.rpc_ports { if let Some((rpc_addr, rpc_pubsub_addr, rpc_banks_addr)) = validator_config.rpc_addrs {
for (purpose, port) in &[ for (purpose, addr) in &[
("RPC", rpc_port), ("RPC", rpc_addr),
("RPC pubsub", rpc_pubsub_port), ("RPC pubsub", rpc_pubsub_addr),
("RPC banks", rpc_banks_port), ("RPC banks", rpc_banks_addr),
] { ] {
tcp_listeners.push(( tcp_listeners.push((
*port, addr.port(),
TcpListener::bind(&SocketAddr::from((rpc_bind_address, *port))) TcpListener::bind(addr).unwrap_or_else(|err| {
.unwrap_or_else(|err| { error!(
error!("Unable to bind to tcp/{} for {}: {}", port, purpose, err); "Unable to bind to tcp/{} for {}: {}",
exit(1); addr.port(),
}), purpose,
err
);
exit(1);
}),
)); ));
} }
} }