Skip to content

Commit

Permalink
Pick an RPC node at random to avoid getting stuck on a bad RPC node (#…
Browse files Browse the repository at this point in the history
…7762)

automerge
  • Loading branch information
mergify[bot] authored and solana-grimes committed Jan 13, 2020
1 parent 633e820 commit 4499173
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions validator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ chrono = { version = "0.4.10", features = ["serde"] }
console = "0.9.1"
log = "0.4.8"
indicatif = "0.13.0"
rand = "0.6.5"
reqwest = { version = "0.9.22", default-features = false }
serde_json = "1.0.41"
solana-clap-utils = { path = "../clap-utils", version = "0.21.8" }
Expand Down
8 changes: 5 additions & 3 deletions validator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use clap::{crate_description, crate_name, value_t, value_t_or_exit, App, Arg};
use console::{style, Emoji};
use indicatif::{ProgressBar, ProgressStyle};
use log::*;
use rand::{thread_rng, Rng};
use solana_clap_utils::{
input_parsers::pubkey_of,
input_validators::{is_keypair, is_pubkey_or_keypair},
Expand Down Expand Up @@ -217,15 +218,16 @@ fn get_rpc_addr(
.any(|contact_info| contact_info.gossip == *entrypoint_gossip);

if found_entrypoint & !rpc_peers.is_empty() {
// Prefer the entrypoint's RPC service it it has one, otherwise pick the first RPC
// service found
// Prefer the entrypoint's RPC service if present, otherwise pick a node at random
if let Some(contact_info) = rpc_peers
.iter()
.find(|contact_info| contact_info.gossip == *entrypoint_gossip)
{
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));
Expand Down

0 comments on commit 4499173

Please sign in to comment.