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

PoT gossip sort optimization #2325

Merged
merged 1 commit into from
Dec 14, 2023
Merged
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
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
Loading