debash: Add `solana-gossip get-rpc-url` command to avoid hard coding (#5513)
This commit is contained in:
parent
97d57d168b
commit
08f6a2ea3e
|
@ -107,7 +107,7 @@ pub fn discover(
|
|||
);
|
||||
Err(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
"Failed to converge",
|
||||
"Discover failed",
|
||||
))
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,10 @@
|
|||
#[macro_use]
|
||||
extern crate solana;
|
||||
|
||||
use clap::{crate_description, crate_name, crate_version, App, AppSettings, Arg, SubCommand};
|
||||
use clap::{
|
||||
crate_description, crate_name, crate_version, value_t_or_exit, App, AppSettings, Arg,
|
||||
SubCommand,
|
||||
};
|
||||
use solana::contact_info::ContactInfo;
|
||||
use solana::gossip_service::discover;
|
||||
use solana_client::rpc_client::RpcClient;
|
||||
|
@ -38,6 +41,19 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
.global(true)
|
||||
.help("Rendezvous with the cluster at this entry point"),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("get-rpc-url")
|
||||
.about("Get an RPC URL for the cluster")
|
||||
.arg(
|
||||
Arg::with_name("timeout")
|
||||
.long("timeout")
|
||||
.value_name("SECONDS")
|
||||
.takes_value(true)
|
||||
.default_value("5")
|
||||
.help("Timeout in seconds"),
|
||||
)
|
||||
.setting(AppSettings::DisableVersion),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("spy")
|
||||
.about("Monitor the gossip entrypoint")
|
||||
|
@ -49,7 +65,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
.value_name("NUM")
|
||||
.takes_value(true)
|
||||
.conflicts_with("num_nodes_exactly")
|
||||
.help("Wait for at least NUM nodes to converge"),
|
||||
.help("Wait for at least NUM nodes to be visible"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("num_nodes_exactly")
|
||||
|
@ -57,7 +73,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
.long("num-nodes-exactly")
|
||||
.value_name("NUM")
|
||||
.takes_value(true)
|
||||
.help("Wait for exactly NUM nodes to converge"),
|
||||
.help("Wait for exactly NUM nodes to be visible"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("node_pubkey")
|
||||
|
@ -71,11 +87,9 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
.arg(
|
||||
Arg::with_name("timeout")
|
||||
.long("timeout")
|
||||
.value_name("SECS")
|
||||
.value_name("SECONDS")
|
||||
.takes_value(true)
|
||||
.help(
|
||||
"Maximum time to wait for cluster to converge [default: wait forever]",
|
||||
),
|
||||
.help("Maximum time to wait in seconds [default: wait forever]"),
|
||||
),
|
||||
)
|
||||
.subcommand(
|
||||
|
@ -99,6 +113,18 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
exit(1)
|
||||
});
|
||||
}
|
||||
|
||||
let gossip_addr = {
|
||||
let mut addr = socketaddr_any!();
|
||||
addr.set_ip(
|
||||
solana_netutil::get_public_ip_addr(&entrypoint_addr).unwrap_or_else(|err| {
|
||||
eprintln!("failed to contact {}: {}", entrypoint_addr, err);
|
||||
exit(1)
|
||||
}),
|
||||
);
|
||||
Some(addr)
|
||||
};
|
||||
|
||||
match matches.subcommand() {
|
||||
("spy", Some(matches)) => {
|
||||
let num_nodes_exactly = matches
|
||||
|
@ -115,17 +141,6 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
.value_of("node_pubkey")
|
||||
.map(|pubkey_str| pubkey_str.parse::<Pubkey>().unwrap());
|
||||
|
||||
let gossip_addr = {
|
||||
let mut addr = socketaddr_any!();
|
||||
addr.set_ip(
|
||||
solana_netutil::get_public_ip_addr(&entrypoint_addr).unwrap_or_else(|err| {
|
||||
eprintln!("failed to contact {}: {}", entrypoint_addr, err);
|
||||
exit(1)
|
||||
}),
|
||||
);
|
||||
Some(addr)
|
||||
};
|
||||
|
||||
let (nodes, _replicators) = discover(
|
||||
&entrypoint_addr,
|
||||
num_nodes,
|
||||
|
@ -161,13 +176,42 @@ fn main() -> Result<(), Box<dyn error::Error>> {
|
|||
);
|
||||
}
|
||||
}
|
||||
("get-rpc-url", Some(matches)) => {
|
||||
let timeout = value_t_or_exit!(matches, "timeout", u64);
|
||||
let (nodes, _replicators) = discover(
|
||||
&entrypoint_addr,
|
||||
Some(1),
|
||||
Some(timeout),
|
||||
None,
|
||||
gossip_addr.as_ref(),
|
||||
)?;
|
||||
|
||||
let rpc_addr = nodes
|
||||
.iter()
|
||||
.filter_map(ContactInfo::valid_client_facing_addr)
|
||||
.map(|addrs| addrs.0)
|
||||
.find(|rpc_addr| rpc_addr.ip() == entrypoint_addr.ip());
|
||||
|
||||
if rpc_addr.is_none() {
|
||||
eprintln!("No RPC URL found");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
println!("http://{}", rpc_addr.unwrap());
|
||||
}
|
||||
("stop", Some(matches)) => {
|
||||
let pubkey = matches
|
||||
.value_of("node_pubkey")
|
||||
.unwrap()
|
||||
.parse::<Pubkey>()
|
||||
.unwrap();
|
||||
let (nodes, _replicators) = discover(&entrypoint_addr, None, None, Some(pubkey), None)?;
|
||||
let (nodes, _replicators) = discover(
|
||||
&entrypoint_addr,
|
||||
None,
|
||||
None,
|
||||
Some(pubkey),
|
||||
gossip_addr.as_ref(),
|
||||
)?;
|
||||
let node = nodes.iter().find(|x| x.id == pubkey).unwrap();
|
||||
|
||||
if !ContactInfo::is_valid_address(&node.rpc) {
|
||||
|
|
|
@ -56,7 +56,7 @@ done
|
|||
: "${storage_keypair:="$SOLANA_ROOT"/farf/replicator-storage-keypair"$label".json}"
|
||||
ledger="$SOLANA_ROOT"/farf/replicator-ledger"$label"
|
||||
|
||||
rpc_url=$("$here"/rpc-url.sh "$entrypoint")
|
||||
rpc_url=$($solana_gossip get-rpc-url --entrypoint "$entrypoint")
|
||||
|
||||
if [[ ! -r $identity_keypair ]]; then
|
||||
$solana_keygen new -o "$identity_keypair"
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
#
|
||||
# Given a gossip entrypoint derive the entrypoint's RPC address
|
||||
#
|
||||
|
||||
entrypoint_address=$1
|
||||
if [[ -z $entrypoint_address ]]; then
|
||||
echo "Error: entrypoint address not specified" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# TODO: Rather than hard coding, add a `solana-gossip rpc-address` command that
|
||||
# actually asks the entrypoint itself for its RPC address
|
||||
echo "http://${entrypoint_address%:*}:8899"
|
|
@ -175,7 +175,7 @@ else
|
|||
gossip_entrypoint="$entrypoint_hostname":8001
|
||||
fi
|
||||
fi
|
||||
rpc_url=$("$here"/rpc-url.sh "$gossip_entrypoint")
|
||||
|
||||
drone_address="${gossip_entrypoint%:*}":9900
|
||||
|
||||
: "${identity_keypair_path:=$ledger_dir/identity-keypair.json}"
|
||||
|
@ -291,6 +291,7 @@ setup_validator_accounts() {
|
|||
}
|
||||
|
||||
while true; do
|
||||
rpc_url=$($solana_gossip get-rpc-url --entrypoint "$gossip_entrypoint")
|
||||
if new_genesis_block; then
|
||||
# If the genesis block has changed remove the now stale ledger and start all
|
||||
# over again
|
||||
|
|
Loading…
Reference in New Issue