uses Duration type for gossip discover timeout
This commit is contained in:
parent
d6496376ce
commit
cf1acfb021
|
@ -657,14 +657,14 @@ fn main() {
|
||||||
let rpc_addr = if !skip_gossip {
|
let rpc_addr = if !skip_gossip {
|
||||||
info!("Finding cluster entry: {:?}", entrypoint_addr);
|
info!("Finding cluster entry: {:?}", entrypoint_addr);
|
||||||
let (gossip_nodes, _validators) = discover(
|
let (gossip_nodes, _validators) = discover(
|
||||||
None,
|
None, // keypair
|
||||||
Some(&entrypoint_addr),
|
Some(&entrypoint_addr),
|
||||||
None,
|
None, // num_nodes
|
||||||
Some(60),
|
Duration::from_secs(60), // timeout
|
||||||
None,
|
None, // find_node_by_pubkey
|
||||||
Some(&entrypoint_addr),
|
Some(&entrypoint_addr), // find_node_by_gossip_addr
|
||||||
None,
|
None, // my_gossip_addr
|
||||||
0,
|
0, // my_shred_version
|
||||||
)
|
)
|
||||||
.unwrap_or_else(|err| {
|
.unwrap_or_else(|err| {
|
||||||
eprintln!("Failed to discover {} node: {:?}", entrypoint_addr, err);
|
eprintln!("Failed to discover {} node: {:?}", entrypoint_addr, err);
|
||||||
|
|
|
@ -85,15 +85,16 @@ pub fn discover_cluster(
|
||||||
entrypoint: &SocketAddr,
|
entrypoint: &SocketAddr,
|
||||||
num_nodes: usize,
|
num_nodes: usize,
|
||||||
) -> std::io::Result<Vec<ContactInfo>> {
|
) -> std::io::Result<Vec<ContactInfo>> {
|
||||||
|
const DISCOVER_CLUSTER_TIMEOUT: Duration = Duration::from_secs(120);
|
||||||
let (_all_peers, validators) = discover(
|
let (_all_peers, validators) = discover(
|
||||||
None, // keypair
|
None, // keypair
|
||||||
Some(entrypoint),
|
Some(entrypoint),
|
||||||
Some(num_nodes),
|
Some(num_nodes),
|
||||||
Some(120), // timeout
|
DISCOVER_CLUSTER_TIMEOUT,
|
||||||
None, // find_node_by_pubkey
|
None, // find_node_by_pubkey
|
||||||
None, // find_node_by_gossip_addr
|
None, // find_node_by_gossip_addr
|
||||||
None, // my_gossip_addr
|
None, // my_gossip_addr
|
||||||
0, // my_shred_version
|
0, // my_shred_version
|
||||||
)?;
|
)?;
|
||||||
Ok(validators)
|
Ok(validators)
|
||||||
}
|
}
|
||||||
|
@ -102,12 +103,15 @@ pub fn discover(
|
||||||
keypair: Option<Arc<Keypair>>,
|
keypair: Option<Arc<Keypair>>,
|
||||||
entrypoint: Option<&SocketAddr>,
|
entrypoint: Option<&SocketAddr>,
|
||||||
num_nodes: Option<usize>, // num_nodes only counts validators, excludes spy nodes
|
num_nodes: Option<usize>, // num_nodes only counts validators, excludes spy nodes
|
||||||
timeout: Option<u64>,
|
timeout: Duration,
|
||||||
find_node_by_pubkey: Option<Pubkey>,
|
find_node_by_pubkey: Option<Pubkey>,
|
||||||
find_node_by_gossip_addr: Option<&SocketAddr>,
|
find_node_by_gossip_addr: Option<&SocketAddr>,
|
||||||
my_gossip_addr: Option<&SocketAddr>,
|
my_gossip_addr: Option<&SocketAddr>,
|
||||||
my_shred_version: u16,
|
my_shred_version: u16,
|
||||||
) -> std::io::Result<(Vec<ContactInfo>, Vec<ContactInfo>)> {
|
) -> std::io::Result<(
|
||||||
|
Vec<ContactInfo>, // all gossip peers
|
||||||
|
Vec<ContactInfo>, // tvu peers (validators)
|
||||||
|
)> {
|
||||||
let keypair = keypair.unwrap_or_else(|| Arc::new(Keypair::new()));
|
let keypair = keypair.unwrap_or_else(|| Arc::new(Keypair::new()));
|
||||||
|
|
||||||
let exit = Arc::new(AtomicBool::new(false));
|
let exit = Arc::new(AtomicBool::new(false));
|
||||||
|
@ -129,7 +133,7 @@ pub fn discover(
|
||||||
|
|
||||||
let _ip_echo_server = ip_echo.map(solana_net_utils::ip_echo_server);
|
let _ip_echo_server = ip_echo.map(solana_net_utils::ip_echo_server);
|
||||||
|
|
||||||
let (met_criteria, secs, all_peers, tvu_peers) = spy(
|
let (met_criteria, elapsed, all_peers, tvu_peers) = spy(
|
||||||
spy_ref.clone(),
|
spy_ref.clone(),
|
||||||
num_nodes,
|
num_nodes,
|
||||||
timeout,
|
timeout,
|
||||||
|
@ -143,7 +147,7 @@ pub fn discover(
|
||||||
if met_criteria {
|
if met_criteria {
|
||||||
info!(
|
info!(
|
||||||
"discover success in {}s...\n{}",
|
"discover success in {}s...\n{}",
|
||||||
secs,
|
elapsed.as_secs(),
|
||||||
spy_ref.contact_info_trace()
|
spy_ref.contact_info_trace()
|
||||||
);
|
);
|
||||||
return Ok((all_peers, tvu_peers));
|
return Ok((all_peers, tvu_peers));
|
||||||
|
@ -205,22 +209,21 @@ pub fn get_multi_client(nodes: &[ContactInfo]) -> (ThinClient, usize) {
|
||||||
fn spy(
|
fn spy(
|
||||||
spy_ref: Arc<ClusterInfo>,
|
spy_ref: Arc<ClusterInfo>,
|
||||||
num_nodes: Option<usize>,
|
num_nodes: Option<usize>,
|
||||||
timeout: Option<u64>,
|
timeout: Duration,
|
||||||
find_node_by_pubkey: Option<Pubkey>,
|
find_node_by_pubkey: Option<Pubkey>,
|
||||||
find_node_by_gossip_addr: Option<&SocketAddr>,
|
find_node_by_gossip_addr: Option<&SocketAddr>,
|
||||||
) -> (bool, u64, Vec<ContactInfo>, Vec<ContactInfo>) {
|
) -> (
|
||||||
|
bool, // if found the specified nodes
|
||||||
|
Duration, // elapsed time until found the nodes or timed-out
|
||||||
|
Vec<ContactInfo>, // all gossip peers
|
||||||
|
Vec<ContactInfo>, // tvu peers (validators)
|
||||||
|
) {
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let mut met_criteria = false;
|
let mut met_criteria = false;
|
||||||
let mut all_peers: Vec<ContactInfo> = Vec::new();
|
let mut all_peers: Vec<ContactInfo> = Vec::new();
|
||||||
let mut tvu_peers: Vec<ContactInfo> = Vec::new();
|
let mut tvu_peers: Vec<ContactInfo> = Vec::new();
|
||||||
let mut i = 1;
|
let mut i = 1;
|
||||||
while !met_criteria {
|
while !met_criteria && now.elapsed() < timeout {
|
||||||
if let Some(secs) = timeout {
|
|
||||||
if now.elapsed() >= Duration::from_secs(secs) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
all_peers = spy_ref
|
all_peers = spy_ref
|
||||||
.all_peers()
|
.all_peers()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -266,7 +269,7 @@ fn spy(
|
||||||
));
|
));
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
(met_criteria, now.elapsed().as_secs(), all_peers, tvu_peers)
|
(met_criteria, now.elapsed(), all_peers, tvu_peers)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Makes a spy or gossip node based on whether or not a gossip_addr was passed in
|
/// Makes a spy or gossip node based on whether or not a gossip_addr was passed in
|
||||||
|
@ -329,6 +332,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_gossip_services_spy() {
|
fn test_gossip_services_spy() {
|
||||||
|
const TIMEOUT: Duration = Duration::from_secs(5);
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let peer0 = solana_sdk::pubkey::new_rand();
|
let peer0 = solana_sdk::pubkey::new_rand();
|
||||||
let peer1 = solana_sdk::pubkey::new_rand();
|
let peer1 = solana_sdk::pubkey::new_rand();
|
||||||
|
@ -341,52 +345,57 @@ mod tests {
|
||||||
|
|
||||||
let spy_ref = Arc::new(cluster_info);
|
let spy_ref = Arc::new(cluster_info);
|
||||||
|
|
||||||
let (met_criteria, secs, _, tvu_peers) = spy(spy_ref.clone(), None, Some(1), None, None);
|
let (met_criteria, elapsed, _, tvu_peers) = spy(spy_ref.clone(), None, TIMEOUT, None, None);
|
||||||
assert!(!met_criteria);
|
assert!(!met_criteria);
|
||||||
assert_eq!(secs, 1);
|
assert!((TIMEOUT..TIMEOUT + Duration::from_secs(1)).contains(&elapsed));
|
||||||
assert_eq!(tvu_peers, spy_ref.tvu_peers());
|
assert_eq!(tvu_peers, spy_ref.tvu_peers());
|
||||||
|
|
||||||
// Find num_nodes
|
// Find num_nodes
|
||||||
let (met_criteria, _, _, _) = spy(spy_ref.clone(), Some(1), None, None, None);
|
let (met_criteria, _, _, _) = spy(spy_ref.clone(), Some(1), TIMEOUT, None, None);
|
||||||
assert!(met_criteria);
|
assert!(met_criteria);
|
||||||
let (met_criteria, _, _, _) = spy(spy_ref.clone(), Some(2), None, None, None);
|
let (met_criteria, _, _, _) = spy(spy_ref.clone(), Some(2), TIMEOUT, None, None);
|
||||||
assert!(met_criteria);
|
assert!(met_criteria);
|
||||||
|
|
||||||
// Find specific node by pubkey
|
// Find specific node by pubkey
|
||||||
let (met_criteria, _, _, _) = spy(spy_ref.clone(), None, None, Some(peer0), None);
|
let (met_criteria, _, _, _) = spy(spy_ref.clone(), None, TIMEOUT, Some(peer0), None);
|
||||||
assert!(met_criteria);
|
assert!(met_criteria);
|
||||||
let (met_criteria, _, _, _) = spy(
|
let (met_criteria, _, _, _) = spy(
|
||||||
spy_ref.clone(),
|
spy_ref.clone(),
|
||||||
None,
|
None,
|
||||||
Some(0),
|
TIMEOUT,
|
||||||
Some(solana_sdk::pubkey::new_rand()),
|
Some(solana_sdk::pubkey::new_rand()),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
assert!(!met_criteria);
|
assert!(!met_criteria);
|
||||||
|
|
||||||
// Find num_nodes *and* specific node by pubkey
|
// Find num_nodes *and* specific node by pubkey
|
||||||
let (met_criteria, _, _, _) = spy(spy_ref.clone(), Some(1), None, Some(peer0), None);
|
let (met_criteria, _, _, _) = spy(spy_ref.clone(), Some(1), TIMEOUT, Some(peer0), None);
|
||||||
assert!(met_criteria);
|
assert!(met_criteria);
|
||||||
let (met_criteria, _, _, _) = spy(spy_ref.clone(), Some(3), Some(0), Some(peer0), None);
|
let (met_criteria, _, _, _) = spy(spy_ref.clone(), Some(3), TIMEOUT, Some(peer0), None);
|
||||||
assert!(!met_criteria);
|
assert!(!met_criteria);
|
||||||
let (met_criteria, _, _, _) = spy(
|
let (met_criteria, _, _, _) = spy(
|
||||||
spy_ref.clone(),
|
spy_ref.clone(),
|
||||||
Some(1),
|
Some(1),
|
||||||
Some(0),
|
TIMEOUT,
|
||||||
Some(solana_sdk::pubkey::new_rand()),
|
Some(solana_sdk::pubkey::new_rand()),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
assert!(!met_criteria);
|
assert!(!met_criteria);
|
||||||
|
|
||||||
// Find specific node by gossip address
|
// Find specific node by gossip address
|
||||||
let (met_criteria, _, _, _) =
|
let (met_criteria, _, _, _) = spy(
|
||||||
spy(spy_ref.clone(), None, None, None, Some(&peer0_info.gossip));
|
spy_ref.clone(),
|
||||||
|
None,
|
||||||
|
TIMEOUT,
|
||||||
|
None,
|
||||||
|
Some(&peer0_info.gossip),
|
||||||
|
);
|
||||||
assert!(met_criteria);
|
assert!(met_criteria);
|
||||||
|
|
||||||
let (met_criteria, _, _, _) = spy(
|
let (met_criteria, _, _, _) = spy(
|
||||||
spy_ref,
|
spy_ref,
|
||||||
None,
|
None,
|
||||||
Some(0),
|
TIMEOUT,
|
||||||
None,
|
None,
|
||||||
Some(&"1.1.1.1:1234".parse().unwrap()),
|
Some(&"1.1.1.1:1234".parse().unwrap()),
|
||||||
);
|
);
|
||||||
|
|
|
@ -10,7 +10,7 @@ use solana_sdk::pubkey::Pubkey;
|
||||||
use std::net::{SocketAddr, UdpSocket};
|
use std::net::{SocketAddr, UdpSocket};
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::time::Instant;
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
fn run_dos(
|
fn run_dos(
|
||||||
nodes: &[ContactInfo],
|
nodes: &[ContactInfo],
|
||||||
|
@ -218,14 +218,14 @@ fn main() {
|
||||||
if !skip_gossip {
|
if !skip_gossip {
|
||||||
info!("Finding cluster entry: {:?}", entrypoint_addr);
|
info!("Finding cluster entry: {:?}", entrypoint_addr);
|
||||||
let (gossip_nodes, _validators) = discover(
|
let (gossip_nodes, _validators) = discover(
|
||||||
None,
|
None, // keypair
|
||||||
Some(&entrypoint_addr),
|
Some(&entrypoint_addr),
|
||||||
None,
|
None, // num_nodes
|
||||||
Some(60),
|
Duration::from_secs(60), // timeout
|
||||||
None,
|
None, // find_node_by_pubkey
|
||||||
Some(&entrypoint_addr),
|
Some(&entrypoint_addr), // find_node_by_gossip_addr
|
||||||
None,
|
None, // my_gossip_addr
|
||||||
0,
|
0, // my_shred_version
|
||||||
)
|
)
|
||||||
.unwrap_or_else(|err| {
|
.unwrap_or_else(|err| {
|
||||||
eprintln!("Failed to discover {} node: {:?}", entrypoint_addr, err);
|
eprintln!("Failed to discover {} node: {:?}", entrypoint_addr, err);
|
||||||
|
|
|
@ -15,6 +15,7 @@ use std::{
|
||||||
net::{IpAddr, Ipv4Addr, SocketAddr},
|
net::{IpAddr, Ipv4Addr, SocketAddr},
|
||||||
process::exit,
|
process::exit,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn parse_matches() -> ArgMatches<'static> {
|
fn parse_matches() -> ArgMatches<'static> {
|
||||||
|
@ -238,15 +239,15 @@ fn process_spy(matches: &ArgMatches) -> std::io::Result<()> {
|
||||||
.expect("unable to find an available gossip port")
|
.expect("unable to find an available gossip port")
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
let discover_timeout = Duration::from_secs(timeout.unwrap_or(u64::MAX));
|
||||||
let (_all_peers, validators) = discover(
|
let (_all_peers, validators) = discover(
|
||||||
identity_keypair,
|
identity_keypair,
|
||||||
entrypoint_addr.as_ref(),
|
entrypoint_addr.as_ref(),
|
||||||
num_nodes,
|
num_nodes,
|
||||||
timeout,
|
discover_timeout,
|
||||||
pubkey,
|
pubkey, // find_node_by_pubkey
|
||||||
None,
|
None, // find_node_by_gossip_addr
|
||||||
Some(&gossip_addr),
|
Some(&gossip_addr), // my_gossip_addr
|
||||||
shred_version,
|
shred_version,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
@ -271,13 +272,13 @@ fn process_rpc_url(matches: &ArgMatches) -> std::io::Result<()> {
|
||||||
let timeout = value_t_or_exit!(matches, "timeout", u64);
|
let timeout = value_t_or_exit!(matches, "timeout", u64);
|
||||||
let shred_version = value_t_or_exit!(matches, "shred_version", u16);
|
let shred_version = value_t_or_exit!(matches, "shred_version", u16);
|
||||||
let (_all_peers, validators) = discover(
|
let (_all_peers, validators) = discover(
|
||||||
None,
|
None, // keypair
|
||||||
entrypoint_addr.as_ref(),
|
entrypoint_addr.as_ref(),
|
||||||
Some(1),
|
Some(1), // num_nodes
|
||||||
Some(timeout),
|
Duration::from_secs(timeout),
|
||||||
None,
|
None, // find_node_by_pubkey
|
||||||
entrypoint_addr.as_ref(),
|
entrypoint_addr.as_ref(), // find_node_by_gossip_addr
|
||||||
None,
|
None, // my_gossip_addr
|
||||||
shred_version,
|
shred_version,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue