Skip to content

Commit

Permalink
chore(networking): make ChunkVerification probabalistic
Browse files Browse the repository at this point in the history
Previously _any_ replication message with more than one key generated a
ChunkVerification message.

Now we just do this for every 1/10 messages we receive.
This should result in less verificaiton under heavy churn
  • Loading branch information
joshuef committed Jul 18, 2024
1 parent 27bf1ac commit dfc1852
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions sn_networking/src/event/request_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use libp2p::{
request_response::{self, Message},
PeerId,
};
use rand::{rngs::OsRng, Rng};
use rand::{rngs::OsRng, thread_rng, Rng};
use sn_protocol::{
messages::{CmdResponse, Request, Response},
storage::RecordType,
Expand Down Expand Up @@ -235,8 +235,10 @@ impl SwarmDriver {
}
}

// Only trigger chunk_proof check when received a periodical replication request.
if incoming_keys.len() > 1 {
// Only trigger chunk_proof check based every X% of the time
let mut rng = thread_rng();
// 5% probability
if incoming_keys.len() > 1 && rng.gen_bool(0.05) {
let keys_to_verify = self.select_verification_data_candidates(sender);

if keys_to_verify.is_empty() {
Expand Down

0 comments on commit dfc1852

Please sign in to comment.