Clean up --gossip-port argument (#7067)
--gossip-port now specifies exactly that, the gossip port to use. The new --gossip-host argument can be used to specify the DNS name/IP address for gossip if --entrypoint is not supplied (when --entrypoint is supplied, the gossip address is automatically set to the node's ip address as observed by the entrypoint)
This commit is contained in:
parent
c39633f968
commit
b0271394cd
|
@ -48,3 +48,9 @@ pub fn is_release_channel(channel: &str) -> Result<(), String> {
|
||||||
_ => Err(format!("Invalid release channel {}", channel)),
|
_ => Err(format!("Invalid release channel {}", channel)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_port(port: String) -> Result<(), String> {
|
||||||
|
port.parse::<u16>()
|
||||||
|
.map(|_| ())
|
||||||
|
.map_err(|e| format!("{:?}", e))
|
||||||
|
}
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
//! A command-line executable for monitoring a cluster's gossip plane.
|
//! A command-line executable for monitoring a cluster's gossip plane.
|
||||||
|
|
||||||
use clap::{
|
use clap::{
|
||||||
crate_description, crate_name, value_t_or_exit, App, AppSettings, Arg, ArgMatches, SubCommand,
|
crate_description, crate_name, value_t, value_t_or_exit, App, AppSettings, Arg, ArgMatches,
|
||||||
|
SubCommand,
|
||||||
};
|
};
|
||||||
use solana_clap_utils::input_validators::is_pubkey;
|
use solana_clap_utils::input_validators::{is_port, is_pubkey};
|
||||||
use solana_client::rpc_client::RpcClient;
|
use solana_client::rpc_client::RpcClient;
|
||||||
use solana_core::{contact_info::ContactInfo, gossip_service::discover, socketaddr};
|
use solana_core::{contact_info::ContactInfo, gossip_service::discover};
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use std::error;
|
use std::error;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
@ -57,17 +58,26 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||||
.long("entrypoint")
|
.long("entrypoint")
|
||||||
.value_name("HOST:PORT")
|
.value_name("HOST:PORT")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.required_unless("gossip_port")
|
|
||||||
.validator(solana_net_utils::is_host_port)
|
.validator(solana_net_utils::is_host_port)
|
||||||
.help("Rendezvous with the cluster at this entry point"),
|
.help("Rendezvous with the cluster at this entrypoint"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
clap::Arg::with_name("gossip_port")
|
clap::Arg::with_name("gossip_port")
|
||||||
.long("gossip-port")
|
.long("gossip-port")
|
||||||
.value_name("HOST:PORT")
|
.value_name("PORT")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
|
.validator(is_port)
|
||||||
.help("Gossip port number for the node"),
|
.help("Gossip port number for the node"),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
clap::Arg::with_name("gossip_host")
|
||||||
|
.long("gossip-host")
|
||||||
|
.value_name("HOST")
|
||||||
|
.takes_value(true)
|
||||||
|
.conflicts_with("entrypoint")
|
||||||
|
.validator(solana_net_utils::is_host)
|
||||||
|
.help("Gossip DNS name or IP address for the node when --entrypoint is not provided [default: 127.0.0.1]"),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("num_nodes")
|
Arg::with_name("num_nodes")
|
||||||
.short("N")
|
.short("N")
|
||||||
|
@ -152,28 +162,32 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
||||||
.value_of("node_pubkey")
|
.value_of("node_pubkey")
|
||||||
.map(|pubkey_str| pubkey_str.parse::<Pubkey>().unwrap());
|
.map(|pubkey_str| pubkey_str.parse::<Pubkey>().unwrap());
|
||||||
|
|
||||||
let mut gossip_addr = solana_net_utils::parse_port_or_addr(
|
let entrypoint_addr = parse_entrypoint(&matches);
|
||||||
matches.value_of("gossip_port"),
|
|
||||||
socketaddr!(
|
let gossip_host = if let Some(entrypoint_addr) = entrypoint_addr {
|
||||||
[127, 0, 0, 1],
|
solana_net_utils::get_public_ip_addr(&entrypoint_addr).unwrap_or_else(|err| {
|
||||||
|
eprintln!(
|
||||||
|
"Failed to contact cluster entrypoint {}: {}",
|
||||||
|
entrypoint_addr, err
|
||||||
|
);
|
||||||
|
exit(1);
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
solana_net_utils::parse_host(matches.value_of("gossip_host").unwrap_or("127.0.0.1"))
|
||||||
|
.unwrap_or_else(|err| {
|
||||||
|
eprintln!("Error: {}", err);
|
||||||
|
exit(1);
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
let gossip_addr = SocketAddr::new(
|
||||||
|
gossip_host,
|
||||||
|
value_t!(matches, "gossip_port", u16).unwrap_or_else(|_| {
|
||||||
solana_net_utils::find_available_port_in_range((0, 1))
|
solana_net_utils::find_available_port_in_range((0, 1))
|
||||||
.expect("unable to find an available gossip port")
|
.expect("unable to find an available gossip port")
|
||||||
),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
let entrypoint_addr = parse_entrypoint(&matches);
|
|
||||||
if let Some(entrypoint_addr) = entrypoint_addr {
|
|
||||||
gossip_addr.set_ip(
|
|
||||||
solana_net_utils::get_public_ip_addr(&entrypoint_addr).unwrap_or_else(|err| {
|
|
||||||
eprintln!(
|
|
||||||
"Failed to contact cluster entrypoint {}: {}",
|
|
||||||
entrypoint_addr, err
|
|
||||||
);
|
|
||||||
exit(1);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let (nodes, _archivers) = discover(
|
let (nodes, _archivers) = discover(
|
||||||
entrypoint_addr.as_ref(),
|
entrypoint_addr.as_ref(),
|
||||||
num_nodes,
|
num_nodes,
|
||||||
|
|
|
@ -176,6 +176,10 @@ pub fn parse_host(host: &str) -> Result<IpAddr, String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_host(string: String) -> Result<(), String> {
|
||||||
|
parse_host(&string).map(|_| ())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse_host_port(host_port: &str) -> Result<SocketAddr, String> {
|
pub fn parse_host_port(host_port: &str) -> Result<SocketAddr, String> {
|
||||||
let addrs: Vec<_> = host_port
|
let addrs: Vec<_> = host_port
|
||||||
.to_socket_addrs()
|
.to_socket_addrs()
|
||||||
|
@ -189,8 +193,7 @@ pub fn parse_host_port(host_port: &str) -> Result<SocketAddr, String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_host_port(string: String) -> Result<(), String> {
|
pub fn is_host_port(string: String) -> Result<(), String> {
|
||||||
parse_host_port(&string)?;
|
parse_host_port(&string).map(|_| ())
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
|
|
|
@ -238,7 +238,8 @@ EOF
|
||||||
multinode-demo/setup.sh "${args[@]}"
|
multinode-demo/setup.sh "${args[@]}"
|
||||||
fi
|
fi
|
||||||
args=(
|
args=(
|
||||||
--gossip-port "$entrypointIp":8001
|
--gossip-host "$entrypointIp"
|
||||||
|
--gossip-port 8001
|
||||||
--init-complete-file "$initCompleteFile"
|
--init-complete-file "$initCompleteFile"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ use solana_core::{
|
||||||
contact_info::ContactInfo,
|
contact_info::ContactInfo,
|
||||||
gossip_service::GossipService,
|
gossip_service::GossipService,
|
||||||
ledger_cleanup_service::DEFAULT_MAX_LEDGER_SLOTS,
|
ledger_cleanup_service::DEFAULT_MAX_LEDGER_SLOTS,
|
||||||
socketaddr,
|
|
||||||
validator::{Validator, ValidatorConfig},
|
validator::{Validator, ValidatorConfig},
|
||||||
};
|
};
|
||||||
use solana_ledger::bank_forks::SnapshotConfig;
|
use solana_ledger::bank_forks::SnapshotConfig;
|
||||||
|
@ -455,10 +454,19 @@ pub fn main() {
|
||||||
.arg(
|
.arg(
|
||||||
clap::Arg::with_name("gossip_port")
|
clap::Arg::with_name("gossip_port")
|
||||||
.long("gossip-port")
|
.long("gossip-port")
|
||||||
.value_name("HOST:PORT")
|
.value_name("PORT")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.help("Gossip port number for the node"),
|
.help("Gossip port number for the node"),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
clap::Arg::with_name("gossip_host")
|
||||||
|
.long("gossip-host")
|
||||||
|
.value_name("HOST")
|
||||||
|
.takes_value(true)
|
||||||
|
.conflicts_with("entrypoint")
|
||||||
|
.validator(solana_net_utils::is_host)
|
||||||
|
.help("Gossip DNS name or IP address for the node when --entrypoint is not provided [default: 127.0.0.1]"),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
clap::Arg::with_name("dynamic_port_range")
|
clap::Arg::with_name("dynamic_port_range")
|
||||||
.long("dynamic-port-range")
|
.long("dynamic-port-range")
|
||||||
|
@ -672,30 +680,40 @@ pub fn main() {
|
||||||
enable_recycler_warming();
|
enable_recycler_warming();
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut gossip_addr = solana_net_utils::parse_port_or_addr(
|
let entrypoint_addr = matches.value_of("entrypoint").map(|entrypoint| {
|
||||||
matches.value_of("gossip_port"),
|
solana_net_utils::parse_host_port(entrypoint).unwrap_or_else(|e| {
|
||||||
socketaddr!(
|
eprintln!("failed to parse entrypoint address: {}", e);
|
||||||
[127, 0, 0, 1],
|
exit(1);
|
||||||
solana_net_utils::find_available_port_in_range(dynamic_port_range)
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
let gossip_host = if let Some(entrypoint_addr) = entrypoint_addr {
|
||||||
|
solana_net_utils::get_public_ip_addr(&entrypoint_addr).unwrap_or_else(|err| {
|
||||||
|
eprintln!(
|
||||||
|
"Failed to contact cluster entrypoint {}: {}",
|
||||||
|
entrypoint_addr, err
|
||||||
|
);
|
||||||
|
exit(1);
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
solana_net_utils::parse_host(matches.value_of("gossip_host").unwrap_or("127.0.0.1"))
|
||||||
|
.unwrap_or_else(|err| {
|
||||||
|
eprintln!("Error: {}", err);
|
||||||
|
exit(1);
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
let gossip_addr = SocketAddr::new(
|
||||||
|
gossip_host,
|
||||||
|
value_t!(matches, "gossip_port", u16).unwrap_or_else(|_| {
|
||||||
|
solana_net_utils::find_available_port_in_range((0, 1))
|
||||||
.expect("unable to find an available gossip port")
|
.expect("unable to find an available gossip port")
|
||||||
),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
let cluster_entrypoint = entrypoint.map(|entrypoint| {
|
let cluster_entrypoint = entrypoint_addr
|
||||||
let entrypoint_addr = solana_net_utils::parse_host_port(entrypoint)
|
.as_ref()
|
||||||
.expect("failed to parse entrypoint address");
|
.map(ContactInfo::new_gossip_entry_point);
|
||||||
let ip_addr =
|
|
||||||
solana_net_utils::get_public_ip_addr(&entrypoint_addr).unwrap_or_else(|err| {
|
|
||||||
error!(
|
|
||||||
"Failed to contact cluster entrypoint {} ({}): {}",
|
|
||||||
entrypoint, entrypoint_addr, err
|
|
||||||
);
|
|
||||||
exit(1);
|
|
||||||
});
|
|
||||||
gossip_addr.set_ip(ip_addr);
|
|
||||||
|
|
||||||
ContactInfo::new_gossip_entry_point(&entrypoint_addr)
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut tcp_ports = vec![];
|
let mut tcp_ports = vec![];
|
||||||
let mut node =
|
let mut node =
|
||||||
|
|
Loading…
Reference in New Issue