Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Pick an RPC node at random to avoid getting stuck on a bad RPC node #7759

Merged
merged 1 commit into from
Jan 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.10.1", default-features = false, features = ["blocking"] }
serde_json = "1.0.44"
solana-clap-utils = { path = "../clap-utils", version = "0.23.0" }
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