From 16b1a4d003d50958096d4434eb9e1b0818f7d18a Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sun, 13 Jun 2021 21:12:24 +0000 Subject: [PATCH] short cuts expiration check if origin's contact-info is still valid (#17918) (#17921) Crds::find_old_labels can skip checking values timestamps if the origin's contact info hasn't expired yet: https://github.com/solana-labs/solana/blob/985280ec0/gossip/src/crds.rs#L394-L408 (cherry picked from commit cca46308bc76295aa5cdc018e35572c41b18ee7b) Co-authored-by: behzad nouri --- gossip/src/crds.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/gossip/src/crds.rs b/gossip/src/crds.rs index bd197647aa..a350f306b7 100644 --- a/gossip/src/crds.rs +++ b/gossip/src/crds.rs @@ -391,22 +391,20 @@ impl Crds { // returns crds labels of old values to be evicted. let evict = |pubkey, index: &IndexSet| { let timeout = timeouts.get(pubkey).copied().unwrap_or(default_timeout); - let local_timestamp = { - let origin = CrdsValueLabel::ContactInfo(*pubkey); - match self.table.get(&origin) { - Some(origin) => origin.local_timestamp, - None => 0, + // If the origin's contact-info hasn't expired yet then preserve + // all associated values. + let origin = CrdsValueLabel::ContactInfo(*pubkey); + if let Some(origin) = self.table.get(&origin) { + if now < origin.local_timestamp.saturating_add(timeout) { + return vec![]; } - }; + } + // Otherwise check each value's timestamp individually. index .into_iter() .filter_map(|ix| { let (label, value) = self.table.get_index(*ix).unwrap(); - let expiry_timestamp = value - .local_timestamp - .max(local_timestamp) - .saturating_add(timeout); - if expiry_timestamp <= now { + if value.local_timestamp.saturating_add(timeout) <= now { Some(label.clone()) } else { None