From c129bff69d92400202bcefd1983eb028e3a26155 Mon Sep 17 00:00:00 2001 From: qima Date: Thu, 24 Dec 2020 20:56:04 +0800 Subject: [PATCH] feat: set filter number boundary --- src/consensus/dkg.rs | 4 +--- src/message_filter.rs | 11 +++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/consensus/dkg.rs b/src/consensus/dkg.rs index 886daa0be3..b1f8e40ab3 100644 --- a/src/consensus/dkg.rs +++ b/src/consensus/dkg.rs @@ -771,9 +771,7 @@ mod tests { self.outcome = Some(outcome.public_key_set.public_key()); vec![] } - DkgCommand::ScheduleTimeout { .. } => { - vec![] - } + DkgCommand::ScheduleTimeout { .. } => vec![], DkgCommand::SendFailureObservation { .. } | DkgCommand::HandleFailureAgreement { .. } => { panic!("unexpected command: {:?}", command) diff --git a/src/message_filter.rs b/src/message_filter.rs index 86dc27a2a0..b4f2007f9e 100644 --- a/src/message_filter.rs +++ b/src/message_filter.rs @@ -16,6 +16,7 @@ use xor_name::XorName; const INCOMING_EXPIRY_DURATION: Duration = Duration::from_secs(20 * 60); const OUTGOING_EXPIRY_DURATION: Duration = Duration::from_secs(10 * 60); +const MAX_ENTRIES: usize = 5_000; /// An enum representing a result of message filtering #[derive(Eq, PartialEq)] @@ -44,8 +45,14 @@ pub(crate) struct MessageFilter { impl MessageFilter { pub fn new() -> Self { Self { - incoming: LruCache::with_expiry_duration(INCOMING_EXPIRY_DURATION), - outgoing: LruCache::with_expiry_duration(OUTGOING_EXPIRY_DURATION), + incoming: LruCache::with_expiry_duration_and_capacity( + INCOMING_EXPIRY_DURATION, + MAX_ENTRIES, + ), + outgoing: LruCache::with_expiry_duration_and_capacity( + OUTGOING_EXPIRY_DURATION, + MAX_ENTRIES, + ), } }