Refactor out get_rpc_peers() (#20744)
This commit is contained in:
@ -101,22 +101,14 @@ fn start_gossip_node(
|
|||||||
(cluster_info, gossip_exit_flag, gossip_service)
|
(cluster_info, gossip_exit_flag, gossip_service)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_rpc_node(
|
fn get_rpc_peers(
|
||||||
cluster_info: &ClusterInfo,
|
cluster_info: &ClusterInfo,
|
||||||
cluster_entrypoints: &[ContactInfo],
|
cluster_entrypoints: &[ContactInfo],
|
||||||
validator_config: &ValidatorConfig,
|
validator_config: &ValidatorConfig,
|
||||||
blacklisted_rpc_nodes: &mut HashSet<Pubkey>,
|
blacklisted_rpc_nodes: &mut HashSet<Pubkey>,
|
||||||
snapshot_not_required: bool,
|
blacklist_timeout: &Instant,
|
||||||
no_untrusted_rpc: bool,
|
retry_reason: &mut Option<String>,
|
||||||
snapshot_archives_dir: &Path,
|
) -> Option<Vec<ContactInfo>> {
|
||||||
) -> Option<(ContactInfo, Option<(Slot, Hash)>)> {
|
|
||||||
let mut blacklist_timeout = Instant::now();
|
|
||||||
let mut newer_cluster_snapshot_timeout = None;
|
|
||||||
let mut retry_reason = None;
|
|
||||||
loop {
|
|
||||||
sleep(Duration::from_secs(1));
|
|
||||||
info!("\n{}", cluster_info.rpc_info_trace());
|
|
||||||
|
|
||||||
let shred_version = validator_config
|
let shred_version = validator_config
|
||||||
.expected_shred_version
|
.expected_shred_version
|
||||||
.unwrap_or_else(|| cluster_info.my_shred_version());
|
.unwrap_or_else(|| cluster_info.my_shred_version());
|
||||||
@ -128,13 +120,11 @@ fn get_rpc_node(
|
|||||||
});
|
});
|
||||||
|
|
||||||
if all_zero_shred_versions {
|
if all_zero_shred_versions {
|
||||||
eprintln!(
|
eprintln!("Entrypoint shred version is zero. Restart with --expected-shred-version");
|
||||||
"Entrypoint shred version is zero. Restart with --expected-shred-version"
|
|
||||||
);
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
info!("Waiting to adopt entrypoint shred version...");
|
info!("Waiting to adopt entrypoint shred version...");
|
||||||
continue;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
@ -161,9 +151,7 @@ fn get_rpc_node(
|
|||||||
let rpc_peers_blacklisted = rpc_peers_total - rpc_peers.len();
|
let rpc_peers_blacklisted = rpc_peers_total - rpc_peers.len();
|
||||||
let rpc_peers_trusted = rpc_peers
|
let rpc_peers_trusted = rpc_peers
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|rpc_peer| {
|
.filter(|rpc_peer| is_trusted_validator(&rpc_peer.id, &validator_config.trusted_validators))
|
||||||
is_trusted_validator(&rpc_peer.id, &validator_config.trusted_validators)
|
|
||||||
})
|
|
||||||
.count();
|
.count();
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
@ -172,9 +160,8 @@ fn get_rpc_node(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if rpc_peers_blacklisted == rpc_peers_total {
|
if rpc_peers_blacklisted == rpc_peers_total {
|
||||||
retry_reason = if !blacklisted_rpc_nodes.is_empty()
|
*retry_reason =
|
||||||
&& blacklist_timeout.elapsed().as_secs() > 60
|
if !blacklisted_rpc_nodes.is_empty() && blacklist_timeout.elapsed().as_secs() > 60 {
|
||||||
{
|
|
||||||
// If all nodes are blacklisted and no additional nodes are discovered after 60 seconds,
|
// If all nodes are blacklisted and no additional nodes are discovered after 60 seconds,
|
||||||
// remove the blacklist and try them all again
|
// remove the blacklist and try them all again
|
||||||
blacklisted_rpc_nodes.clear();
|
blacklisted_rpc_nodes.clear();
|
||||||
@ -182,8 +169,40 @@ fn get_rpc_node(
|
|||||||
} else {
|
} else {
|
||||||
Some("Wait for known rpc peers".to_owned())
|
Some("Wait for known rpc peers".to_owned())
|
||||||
};
|
};
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(rpc_peers)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_rpc_node(
|
||||||
|
cluster_info: &ClusterInfo,
|
||||||
|
cluster_entrypoints: &[ContactInfo],
|
||||||
|
validator_config: &ValidatorConfig,
|
||||||
|
blacklisted_rpc_nodes: &mut HashSet<Pubkey>,
|
||||||
|
snapshot_not_required: bool,
|
||||||
|
no_untrusted_rpc: bool,
|
||||||
|
snapshot_archives_dir: &Path,
|
||||||
|
) -> Option<(ContactInfo, Option<(Slot, Hash)>)> {
|
||||||
|
let mut blacklist_timeout = Instant::now();
|
||||||
|
let mut newer_cluster_snapshot_timeout = None;
|
||||||
|
let mut retry_reason = None;
|
||||||
|
loop {
|
||||||
|
sleep(Duration::from_secs(1));
|
||||||
|
info!("\n{}", cluster_info.rpc_info_trace());
|
||||||
|
|
||||||
|
let rpc_peers = get_rpc_peers(
|
||||||
|
cluster_info,
|
||||||
|
cluster_entrypoints,
|
||||||
|
validator_config,
|
||||||
|
blacklisted_rpc_nodes,
|
||||||
|
&blacklist_timeout,
|
||||||
|
&mut retry_reason,
|
||||||
|
);
|
||||||
|
if rpc_peers.is_none() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
let rpc_peers = rpc_peers.unwrap();
|
||||||
blacklist_timeout = Instant::now();
|
blacklist_timeout = Instant::now();
|
||||||
|
|
||||||
let mut highest_snapshot_hash = get_highest_local_snapshot_hash(snapshot_archives_dir);
|
let mut highest_snapshot_hash = get_highest_local_snapshot_hash(snapshot_archives_dir);
|
||||||
|
Reference in New Issue
Block a user