From 4e0dbd6a7388cc0deff35cede9091d1f0d542160 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 21 Aug 2020 22:24:48 +0000 Subject: [PATCH] Fix filter_crds_values output alignment with the inputs (bp #11734) (#11780) * Fix filter_crds_values output alignment with the inputs (#11734) (cherry picked from commit 418b483af69bf1d25508d10e90860453551814b8) # Conflicts: # core/src/crds_gossip_pull.rs * Resolve conflicts Co-authored-by: behzad nouri Co-authored-by: Carl --- core/src/crds_gossip_pull.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/core/src/crds_gossip_pull.rs b/core/src/crds_gossip_pull.rs index ac4979d4be..73b81bec98 100644 --- a/core/src/crds_gossip_pull.rs +++ b/core/src/crds_gossip_pull.rs @@ -385,7 +385,8 @@ impl CrdsGossipPull { let past = now.saturating_sub(msg_timeout); let recent: Vec<_> = filters .iter() - .filter(|(caller, _)| caller.wallclock() < future && caller.wallclock() >= past) + .enumerate() + .filter(|(_, (caller, _))| caller.wallclock() < future && caller.wallclock() >= past) .collect(); inc_new_counter_info!( "gossip_filter_crds_values-dropped_requests", @@ -396,7 +397,7 @@ impl CrdsGossipPull { } let mut total_skipped = 0; for v in crds.table.values() { - recent.iter().enumerate().for_each(|(i, (caller, filter))| { + recent.iter().for_each(|(i, (caller, filter))| { //skip values that are too new if v.value.wallclock() > caller.wallclock().checked_add(jitter).unwrap_or_else(|| 0) { @@ -404,7 +405,7 @@ impl CrdsGossipPull { return; } if !filter.contains(&v.value_hash) { - ret[i].push(v.value.clone()); + ret[*i].push(v.value.clone()); } }); } @@ -710,15 +711,19 @@ mod test { dest.generate_pull_responses(&dest_crds, &filters, CRDS_GOSSIP_PULL_MSG_TIMEOUT_MS); assert_eq!(rsp[0].len(), 0); + assert_eq!(filters.len(), 1); + filters.push(filters[0].clone()); //should return new value since caller is new - filters[0].0 = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost( + filters[1].0 = CrdsValue::new_unsigned(CrdsData::ContactInfo(ContactInfo::new_localhost( &Pubkey::new_rand(), CRDS_GOSSIP_PULL_MSG_TIMEOUT_MS + 1, ))); let rsp = dest.generate_pull_responses(&dest_crds, &filters, CRDS_GOSSIP_PULL_MSG_TIMEOUT_MS); - assert_eq!(rsp[0].len(), 1); + assert_eq!(rsp.len(), 2); + assert_eq!(rsp[0].len(), 0); + assert_eq!(rsp[1].len(), 1); // Orders are also preserved. } #[test]