adds flag to disable duplicate instance check (#15006)

This commit is contained in:
behzad nouri
2021-02-03 16:26:17 +00:00
committed by GitHub
parent 971c222cf7
commit 0ad063f4e9
7 changed files with 68 additions and 10 deletions

View File

@ -2540,6 +2540,7 @@ impl ClusterInfo {
stakes: HashMap<Pubkey, u64>,
feature_set: Option<&FeatureSet>,
epoch_time_ms: u64,
should_check_duplicate_instance: bool,
) -> Result<()> {
let _st = ScopedTimer::from(&self.stats.process_gossip_packets_time);
let packets: Vec<_> = thread_pool.install(|| {
@ -2557,9 +2558,11 @@ impl ClusterInfo {
// Check if there is a duplicate instance of
// this node with more recent timestamp.
let check_duplicate_instance = |values: &[CrdsValue]| {
for value in values {
if self.instance.check_duplicate(value) {
return Err(Error::DuplicateNodeInstance);
if should_check_duplicate_instance {
for value in values {
if self.instance.check_duplicate(value) {
return Err(Error::DuplicateNodeInstance);
}
}
}
Ok(())
@ -2620,6 +2623,7 @@ impl ClusterInfo {
response_sender: &PacketSender,
thread_pool: &ThreadPool,
last_print: &mut Instant,
should_check_duplicate_instance: bool,
) -> Result<()> {
const RECV_TIMEOUT: Duration = Duration::from_secs(1);
let packets: Vec<_> = requests_receiver.recv_timeout(RECV_TIMEOUT)?.packets.into();
@ -2655,6 +2659,7 @@ impl ClusterInfo {
stakes,
feature_set.as_deref(),
epoch_time_ms,
should_check_duplicate_instance,
)?;
self.print_reset_stats(last_print);
@ -2900,6 +2905,7 @@ impl ClusterInfo {
bank_forks: Option<Arc<RwLock<BankForks>>>,
requests_receiver: PacketReceiver,
response_sender: PacketSender,
should_check_duplicate_instance: bool,
exit: &Arc<AtomicBool>,
) -> JoinHandle<()> {
let exit = exit.clone();
@ -2921,6 +2927,7 @@ impl ClusterInfo {
&response_sender,
&thread_pool,
&mut last_print,
should_check_duplicate_instance,
) {
match err {
Error::RecvTimeoutError(_) => {

View File

@ -33,6 +33,7 @@ impl GossipService {
bank_forks: Option<Arc<RwLock<BankForks>>>,
gossip_socket: UdpSocket,
gossip_validators: Option<HashSet<Pubkey>>,
should_check_duplicate_instance: bool,
exit: &Arc<AtomicBool>,
) -> Self {
let (request_sender, request_receiver) = channel();
@ -56,6 +57,7 @@ impl GossipService {
bank_forks.clone(),
request_receiver,
response_sender.clone(),
should_check_duplicate_instance,
exit,
);
let t_gossip = ClusterInfo::gossip(
@ -108,8 +110,14 @@ pub fn discover(
let keypair = keypair.unwrap_or_else(|| Arc::new(Keypair::new()));
let exit = Arc::new(AtomicBool::new(false));
let (gossip_service, ip_echo, spy_ref) =
make_gossip_node(keypair, entrypoint, &exit, my_gossip_addr, my_shred_version);
let (gossip_service, ip_echo, spy_ref) = make_gossip_node(
keypair,
entrypoint,
&exit,
my_gossip_addr,
my_shred_version,
true, // should_check_duplicate_instance,
);
let id = spy_ref.id();
info!("Entrypoint: {:?}", entrypoint);
@ -268,6 +276,7 @@ fn make_gossip_node(
exit: &Arc<AtomicBool>,
gossip_addr: Option<&SocketAddr>,
shred_version: u16,
should_check_duplicate_instance: bool,
) -> (GossipService, Option<TcpListener>, Arc<ClusterInfo>) {
let (node, gossip_socket, ip_echo) = if let Some(gossip_addr) = gossip_addr {
ClusterInfo::gossip_node(&keypair.pubkey(), gossip_addr, shred_version)
@ -279,7 +288,14 @@ fn make_gossip_node(
cluster_info.set_entrypoint(ContactInfo::new_gossip_entry_point(entrypoint));
}
let cluster_info = Arc::new(cluster_info);
let gossip_service = GossipService::new(&cluster_info, None, gossip_socket, None, &exit);
let gossip_service = GossipService::new(
&cluster_info,
None,
gossip_socket,
None,
should_check_duplicate_instance,
&exit,
);
(gossip_service, ip_echo, cluster_info)
}
@ -298,7 +314,14 @@ mod tests {
let tn = Node::new_localhost();
let cluster_info = ClusterInfo::new_with_invalid_keypair(tn.info.clone());
let c = Arc::new(cluster_info);
let d = GossipService::new(&c, None, tn.sockets.gossip, None, &exit);
let d = GossipService::new(
&c,
None,
tn.sockets.gossip,
None,
true, // should_check_duplicate_instance
&exit,
);
exit.store(true, Ordering::Relaxed);
d.join().unwrap();
}

View File

@ -405,6 +405,7 @@ impl TestValidator {
vec![Arc::new(validator_vote_account)],
vec![],
&validator_config,
true, // should_check_duplicate_instance
));
// Needed to avoid panics in `solana-responder-gossip` in tests that create a number of

View File

@ -247,6 +247,7 @@ impl Validator {
mut authorized_voter_keypairs: Vec<Arc<Keypair>>,
cluster_entrypoints: Vec<ContactInfo>,
config: &ValidatorConfig,
should_check_duplicate_instance: bool,
) -> Self {
let id = identity_keypair.pubkey();
assert_eq!(id, node.info.id);
@ -517,6 +518,7 @@ impl Validator {
Some(bank_forks.clone()),
node.sockets.gossip,
config.gossip_validators.clone(),
should_check_duplicate_instance,
&exit,
);
let serve_repair = Arc::new(RwLock::new(ServeRepair::new(cluster_info.clone())));
@ -1419,6 +1421,7 @@ mod tests {
vec![voting_keypair.clone()],
vec![leader_node.info],
&config,
true, // should_check_duplicate_instance
);
validator.close();
remove_dir_all(validator_ledger_path).unwrap();
@ -1489,6 +1492,7 @@ mod tests {
vec![Arc::new(vote_account_keypair)],
vec![leader_node.info.clone()],
&config,
true, // should_check_duplicate_instance
)
})
.collect();