Skip to content

Commit 50a8fa3

Browse files
committed
feat: Defer packet signature verification in gossip
Moves expensive `par_verify` from initial packet handling (`verify_packet`) to later in the processing pipeline (`process_packets`) after cheaper checks. This avoids unnecessary cryptographic work for packets that might be dropped, improving performance under load.
1 parent 1262cb2 commit 50a8fa3

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

gossip/src/cluster_info.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -2013,6 +2013,14 @@ impl ClusterInfo {
20132013
let mut ping_messages = vec![];
20142014
let mut pong_messages = vec![];
20152015
for (from_addr, packet) in packets.drain(..).flatten() {
2016+
// Deferred verification - we now do this later (here) instead of in verify_packet because it is expensive
2017+
if !packet.par_verify() {
2018+
continue;
2019+
}
2020+
2021+
// Verification passed, increment stats
2022+
self.stats.packets_received_verified_count.add_relaxed(1);
2023+
20162024
match packet {
20172025
Protocol::PullRequest(filter, caller) => {
20182026
if !check_pull_request_shred_version(self_shred_version, &caller) {
@@ -2129,10 +2137,7 @@ impl ClusterInfo {
21292137
return None;
21302138
}
21312139
}
2132-
protocol.par_verify().then(|| {
2133-
stats.packets_received_verified_count.add_relaxed(1);
2134-
(packet.meta().socket_addr(), protocol)
2135-
})
2140+
Some((packet.meta().socket_addr(), protocol))
21362141
}
21372142
let stakes = epoch_specs
21382143
.map(EpochSpecs::current_epoch_staked_nodes)

0 commit comments

Comments
 (0)