Skip to content

Commit 1d4b5da

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 1d4b5da

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

gossip/src/cluster_info.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -2013,6 +2013,15 @@ 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+
2024+
// Process the verified packet (original match block, no extra indent)
20162025
match packet {
20172026
Protocol::PullRequest(filter, caller) => {
20182027
if !check_pull_request_shred_version(self_shred_version, &caller) {
@@ -2129,10 +2138,7 @@ impl ClusterInfo {
21292138
return None;
21302139
}
21312140
}
2132-
protocol.par_verify().then(|| {
2133-
stats.packets_received_verified_count.add_relaxed(1);
2134-
(packet.meta().socket_addr(), protocol)
2135-
})
2141+
Some((packet.meta().socket_addr(), protocol))
21362142
}
21372143
let stakes = epoch_specs
21382144
.map(EpochSpecs::current_epoch_staked_nodes)

0 commit comments

Comments
 (0)