Skip to content

Commit

Permalink
Merge pull request #2325 from subspace/pot-gossip-sort-optimization
Browse files Browse the repository at this point in the history
PoT gossip sort optimization
  • Loading branch information
nazar-pc authored Dec 14, 2023
2 parents 5be3c33 + cd1aecb commit 3f3a82a
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions crates/sc-proof-of-time/src/source/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,21 @@ where
return;
}

// This sorts from lowest reputation to highest
potentially_matching_proofs.sort_by_cached_key(|(_proof, peer_ids)| {
peer_ids
.iter()
.map(|peer_id| network.peer_reputation(peer_id))
.max()
});

// If we have too many unique proofs to verify it might be cheaper to prove it ourselves
let correct_proof = if potentially_matching_proofs.len() < EXPECTED_POT_VERIFICATION_SPEEDUP
{
let mut correct_proof = None;

// Verify all proofs
for (proof, _senders) in &potentially_matching_proofs {
// Verify all proofs, starting with those sent by most reputable peers
for (proof, _senders) in potentially_matching_proofs.iter().rev() {
if pot_verifier.verify_checkpoints(
proof.seed,
proof.slot_iterations,
Expand All @@ -438,13 +446,6 @@ where

correct_proof
} else {
// This sorts from lowest reputation to highest
potentially_matching_proofs.sort_by_cached_key(|(_proof, peer_ids)| {
peer_ids
.iter()
.map(|peer_id| network.peer_reputation(peer_id))
.max()
});
// Last proof includes peer with the highest reputation
let (proof, _senders) = potentially_matching_proofs
.last()
Expand Down

0 comments on commit 3f3a82a

Please sign in to comment.