Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
fix: replace LRU with a HashSet
Browse files Browse the repository at this point in the history
  • Loading branch information
gruberb committed Apr 25, 2024
1 parent 125b772 commit c6b3587
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions crates/topos-tce-broadcast/src/double_echo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,15 +49,14 @@ pub struct DoubleEcho {
/// List of approved validators through smart contract and/or genesis
pub validators: HashSet<ValidatorId>,
pub validator_store: Arc<ValidatorStore>,
pub known_signatures: LruCache<Signature, ()>,
pub known_signatures: HashSet<Signature>,
pub broadcast_sender: broadcast::Sender<CertificateDeliveredWithPositions>,

pub task_manager_cancellation: CancellationToken,
}

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(
Expand Down Expand Up @@ -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(),
}
Expand Down Expand Up @@ -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
},
Expand All @@ -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
},
Expand Down

0 comments on commit c6b3587

Please sign in to comment.