short cuts expiration check if origin's contact-info is still valid (#17918)

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
This commit is contained in:
behzad nouri 2021-06-13 19:47:07 +00:00 committed by GitHub
parent 985280ec0b
commit cca46308bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 11 deletions

View File

@ -391,22 +391,20 @@ impl Crds {
// returns crds labels of old values to be evicted.
let evict = |pubkey, index: &IndexSet<usize>| {
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