Skip to content

Commit

Permalink
Ignore duplicate txns via LRU cache (#3821)
Browse files Browse the repository at this point in the history
* Ignore duplicate txns via LRU cache

* cache just in combined
  • Loading branch information
bfish713 authored Nov 6, 2024
1 parent c5cb368 commit 42cf3cc
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/hotshot/src/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ pub fn add_queue_len_task<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Vers
}

/// Add the network task to handle messages and publish events.
#[allow(clippy::missing_panics_doc)]
pub fn add_network_message_task<
TYPES: NodeType,
I: NodeImplementation<TYPES>,
Expand Down
7 changes: 2 additions & 5 deletions crates/hotshot/src/traits/networking/combined_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,8 @@ impl<TYPES: NodeType> ConnectedNetwork<TYPES::SignatureKey> for CombinedNetworks
// Calculate hash of the message
let message_hash = calculate_hash_of(&message);

// Check if the hash is in the cache
if !self.message_cache.read().contains(&message_hash) {
// Add the hash to the cache
self.message_cache.write().put(message_hash, ());

// Check if the hash is in the cache and update the cache
if self.message_cache.write().put(message_hash, ()).is_none() {
break Ok(message);
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/task-impls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ hotshot-types = { path = "../types" }
hotshot-builder-api = { path = "../builder-api" }
jf-signature = { workspace = true }
jf-vid = { workspace = true }
lru.workspace = true
rand = { workspace = true }
serde = { workspace = true }
sha2 = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/types/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub const LOOK_AHEAD: u64 = 5;
pub const KAD_DEFAULT_REPUB_INTERVAL_SEC: u64 = 28800;

/// the number of messages to cache in the combined network
pub const COMBINED_NETWORK_CACHE_SIZE: usize = 1000;
pub const COMBINED_NETWORK_CACHE_SIZE: usize = 200_000;

/// the number of messages to attempt to send over the primary network before switching to prefer the secondary network
pub const COMBINED_NETWORK_MIN_PRIMARY_FAILURES: u64 = 5;
Expand Down

0 comments on commit 42cf3cc

Please sign in to comment.