Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore duplicate txns via LRU cache #3821

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -118,6 +118,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() {
Comment on lines -465 to +466
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't profiled this enough to have an opinion on which is faster in most cases, but I'm all for making it more succinct

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really for speed, it's so that we update the cache on every duplicate message. So if a really old message that's still in the cache comes in we make sure it becomes the most recently used and doesn't fall out of cache.

Copy link
Collaborator

@rob-maron rob-maron Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right this does work better with LRU semantics

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