`solana-validator --rpc-bind-address` argument now works as expected
This commit is contained in:
parent
361e5322e4
commit
6f325d4594
|
@ -56,7 +56,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},
|
||||
|
@ -77,7 +77,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,
|
||||
|
@ -107,7 +107,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,
|
||||
|
@ -351,20 +351,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(),
|
||||
|
@ -378,13 +378,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,
|
||||
|
@ -670,7 +666,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()
|
||||
|
@ -921,11 +917,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();
|
||||
|
@ -1091,10 +1083,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()
|
||||
};
|
||||
|
@ -1166,10 +1158,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()
|
||||
};
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -99,6 +99,7 @@ args+=(
|
|||
--identity "$identity"
|
||||
--vote-account "$vote_account"
|
||||
--rpc-faucet-address 127.0.0.1:9900
|
||||
#--rpc-bind-address 192.168.1.207
|
||||
)
|
||||
default_arg --gossip-port 8001
|
||||
default_arg --log -
|
||||
|
|
|
@ -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);
|
||||
}),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue