Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
solana-validator --rpc-bind-address argument now works as expected …
Browse files Browse the repository at this point in the history
…(bp #12168) (#12174)

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

(cherry picked from commit 6f325d4)

* Update bootstrap-validator.sh

Co-authored-by: Michael Vines <mvines@gmail.com>
  • Loading branch information
mergify[bot] and mvines authored Sep 10, 2020
1 parent 61cf432 commit bbddffa
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 69 deletions.
50 changes: 21 additions & 29 deletions core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -76,7 +76,7 @@ pub struct ValidatorConfig {
pub voting_disabled: bool,
pub account_paths: Vec<PathBuf>,
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 max_ledger_shreds: Option<u64>,
pub broadcast_stage_type: BroadcastStageType,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand All @@ -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,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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()
};
Expand Down Expand Up @@ -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()
};
Expand Down
23 changes: 10 additions & 13 deletions local-cluster/src/local_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down
62 changes: 35 additions & 27 deletions validator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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());
}
}

Expand All @@ -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);
}),
));
}
}
Expand Down

0 comments on commit bbddffa

Please sign in to comment.