Pick an RPC node at random to avoid getting stuck on a bad RPC node
This commit is contained in:
parent
9754fc789e
commit
ad4d41e602
|
@ -4347,6 +4347,7 @@ dependencies = [
|
||||||
"gag 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
"gag 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"indicatif 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"indicatif 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"reqwest 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"reqwest 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"solana-clap-utils 0.23.0",
|
"solana-clap-utils 0.23.0",
|
||||||
|
|
|
@ -15,6 +15,7 @@ chrono = { version = "0.4.10", features = ["serde"] }
|
||||||
console = "0.9.1"
|
console = "0.9.1"
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
indicatif = "0.13.0"
|
indicatif = "0.13.0"
|
||||||
|
rand = "0.6.5"
|
||||||
reqwest = { version = "0.10.1", default-features = false, features = ["blocking"] }
|
reqwest = { version = "0.10.1", default-features = false, features = ["blocking"] }
|
||||||
serde_json = "1.0.44"
|
serde_json = "1.0.44"
|
||||||
solana-clap-utils = { path = "../clap-utils", version = "0.23.0" }
|
solana-clap-utils = { path = "../clap-utils", version = "0.23.0" }
|
||||||
|
|
|
@ -3,6 +3,7 @@ use clap::{crate_description, crate_name, value_t, value_t_or_exit, App, Arg};
|
||||||
use console::{style, Emoji};
|
use console::{style, Emoji};
|
||||||
use indicatif::{ProgressBar, ProgressStyle};
|
use indicatif::{ProgressBar, ProgressStyle};
|
||||||
use log::*;
|
use log::*;
|
||||||
|
use rand::{thread_rng, Rng};
|
||||||
use solana_clap_utils::{
|
use solana_clap_utils::{
|
||||||
input_parsers::pubkey_of,
|
input_parsers::pubkey_of,
|
||||||
input_validators::{is_keypair, is_pubkey_or_keypair},
|
input_validators::{is_keypair, is_pubkey_or_keypair},
|
||||||
|
@ -217,15 +218,16 @@ fn get_rpc_addr(
|
||||||
.any(|contact_info| contact_info.gossip == *entrypoint_gossip);
|
.any(|contact_info| contact_info.gossip == *entrypoint_gossip);
|
||||||
|
|
||||||
if found_entrypoint & !rpc_peers.is_empty() {
|
if found_entrypoint & !rpc_peers.is_empty() {
|
||||||
// Prefer the entrypoint's RPC service it it has one, otherwise pick the first RPC
|
// Prefer the entrypoint's RPC service if present, otherwise pick a node at random
|
||||||
// service found
|
|
||||||
if let Some(contact_info) = rpc_peers
|
if let Some(contact_info) = rpc_peers
|
||||||
.iter()
|
.iter()
|
||||||
.find(|contact_info| contact_info.gossip == *entrypoint_gossip)
|
.find(|contact_info| contact_info.gossip == *entrypoint_gossip)
|
||||||
{
|
{
|
||||||
break (contact_info.id, contact_info.rpc);
|
break (contact_info.id, contact_info.rpc);
|
||||||
}
|
}
|
||||||
break (rpc_peers[0].id, rpc_peers[0].rpc);
|
|
||||||
|
let i = thread_rng().gen_range(0, rpc_peers.len());
|
||||||
|
break (rpc_peers[i].id, rpc_peers[i].rpc);
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep(Duration::from_secs(1));
|
sleep(Duration::from_secs(1));
|
||||||
|
|
Loading…
Reference in New Issue