Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Fix incomplete sorting. #4795

Merged
merged 8 commits into from
Jan 27, 2022
Merged
Changes from 2 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
23 changes: 21 additions & 2 deletions runtime/parachains/src/disputes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,14 @@ where
(None, Some(_)) => Ordering::Greater,
(Some(_), None) => Ordering::Less,
// For local disputes, prioritize those that occur at an earlier height.
(Some(a_height), Some(b_height)) => a_height.cmp(&b_height),
(Some(a_height), Some(b_height)) => {
let height_ord = a_height.cmp(&b_height);
if height_ord == Ordering::Equal {
a.candidate_hash.cmp(&b.candidate_hash)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

} else {
height_ord
}
drahnr marked this conversation as resolved.
Show resolved Hide resolved
},
// Prioritize earlier remote disputes using session as rough proxy.
(None, None) => {
let session_ord = a.session.cmp(&b.session);
Expand Down Expand Up @@ -163,7 +170,19 @@ pub trait DisputesHandler<BlockNumber: Ord> {
) {
return Err(())
}
if statement_sets.as_slice().windows(2).any(|sub| sub.get(0) == sub.get(1)) {
let compare_statement_sets_window_same_dispute = |sub: &[DisputeStatementSet]| {
match (sub.get(0), sub.get(1)) {
// should not be possible:
(None, None) | (None, Some(_)) | (Some(_), None) => false,
(Some(set1), Some(set2)) =>
set1.session == set2.session && set1.candidate_hash == set2.candidate_hash,
}
};
if statement_sets
.as_slice()
.windows(2)
.any(compare_statement_sets_window_same_dispute)
{
return Err(())
}
Ok(())
Expand Down