From c6b35877efaf38aead8c22ab28db9b22b777b1b8 Mon Sep 17 00:00:00 2001 From: Bastian Gruber Date: Wed, 24 Apr 2024 21:42:27 -0300 Subject: [PATCH] fix: replace LRU with a HashSet --- crates/topos-tce-broadcast/src/double_echo/mod.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/crates/topos-tce-broadcast/src/double_echo/mod.rs b/crates/topos-tce-broadcast/src/double_echo/mod.rs index fe1941e5c..ce676a24d 100644 --- a/crates/topos-tce-broadcast/src/double_echo/mod.rs +++ b/crates/topos-tce-broadcast/src/double_echo/mod.rs @@ -15,7 +15,6 @@ use crate::event::ProtocolEvents; use crate::{DoubleEchoCommand, SubscriptionsView}; -use lru::LruCache; use std::collections::HashSet; use std::num::NonZeroUsize; use std::sync::Arc; @@ -50,7 +49,7 @@ pub struct DoubleEcho { /// List of approved validators through smart contract and/or genesis pub validators: HashSet, pub validator_store: Arc, - pub known_signatures: LruCache, + pub known_signatures: HashSet, pub broadcast_sender: broadcast::Sender, pub task_manager_cancellation: CancellationToken, @@ -58,7 +57,6 @@ pub struct DoubleEcho { impl DoubleEcho { pub const MAX_BUFFER_SIZE: usize = 1024 * 20; - pub const KNOWN_SIGNATURES_CACHE_SIZE: usize = 15 * 10_000; #[allow(clippy::too_many_arguments)] pub fn new( @@ -88,9 +86,7 @@ impl DoubleEcho { }, shutdown, validator_store, - known_signatures: LruCache::new( - NonZeroUsize::new(Self::KNOWN_SIGNATURES_CACHE_SIZE).unwrap(), - ), + known_signatures: HashSet::new(), broadcast_sender, task_manager_cancellation: CancellationToken::new(), } @@ -171,7 +167,7 @@ impl DoubleEcho { continue; } - self.known_signatures.push(signature, ()); + self.known_signatures.insert(signature); self.handle_echo(certificate_id, validator_id, signature).await }, @@ -197,7 +193,7 @@ impl DoubleEcho { continue; } - self.known_signatures.push(signature, ()); + self.known_signatures.insert(signature); self.handle_ready(certificate_id, validator_id, signature).await },