From 4e40c771a4e92b3a3c9ea25d674382b1344869d9 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Mon, 21 Nov 2022 14:39:21 +0200 Subject: [PATCH 1/3] disputes pallet: Filter disputes with votes less than supermajority threshold --- runtime/parachains/src/disputes.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/runtime/parachains/src/disputes.rs b/runtime/parachains/src/disputes.rs index b5e9d2540045..aba935b5369f 100644 --- a/runtime/parachains/src/disputes.rs +++ b/runtime/parachains/src/disputes.rs @@ -521,6 +521,8 @@ pub mod pallet { PotentialSpam, /// A dispute where there are only votes on one side. SingleSidedDispute, + /// Unconfirmed dispute statement sets provided + UnconfirmedDispute, } #[pallet::call] @@ -1038,6 +1040,13 @@ impl Pallet { return StatementSetFilter::RemoveAll } + // Reject disputes containing less votes than needed for confirmation. + if summary.state.validators_for.count_ones() + summary.state.validators_against.count_ones() < + supermajority_threshold(summary.state.validators_for.len()) + { + return StatementSetFilter::RemoveAll + } + // Apply spam slot changes. Bail early if too many occupied. let is_local = >::contains_key(&set.session, &set.candidate_hash); if !is_local { @@ -1200,6 +1209,14 @@ impl Pallet { Error::::SingleSidedDispute, ); + // Reject disputes containing less votes than needed for confirmation. + ensure!( + summary.state.validators_for.count_ones() + + summary.state.validators_against.count_ones() >= + supermajority_threshold(summary.state.validators_for.len()), + Error::::UnconfirmedDispute, + ); + let DisputeStatementSet { ref session, ref candidate_hash, .. } = set; let session = *session; let candidate_hash = *candidate_hash; From fa68ca6ff536393446b93022d9c4768d1d6be33d Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Tue, 22 Nov 2022 22:29:07 +0200 Subject: [PATCH 2/3] Code review feedback - fix vote count --- runtime/parachains/src/disputes.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/runtime/parachains/src/disputes.rs b/runtime/parachains/src/disputes.rs index aba935b5369f..443e1add74f9 100644 --- a/runtime/parachains/src/disputes.rs +++ b/runtime/parachains/src/disputes.rs @@ -1041,8 +1041,8 @@ impl Pallet { } // Reject disputes containing less votes than needed for confirmation. - if summary.state.validators_for.count_ones() + summary.state.validators_against.count_ones() < - supermajority_threshold(summary.state.validators_for.len()) + if (summary.state.validators_for.clone() | &summary.state.validators_against).count_ones() <= + byzantine_threshold(summary.state.validators_for.len()) { return StatementSetFilter::RemoveAll } @@ -1211,9 +1211,8 @@ impl Pallet { // Reject disputes containing less votes than needed for confirmation. ensure!( - summary.state.validators_for.count_ones() + - summary.state.validators_against.count_ones() >= - supermajority_threshold(summary.state.validators_for.len()), + (summary.state.validators_for.clone() | &summary.state.validators_against).count_ones() > + byzantine_threshold(summary.state.validators_for.len()), Error::::UnconfirmedDispute, ); From ac5b9f72195b95d87d0a7073a17c462e1158c35f Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Wed, 23 Nov 2022 14:52:20 +0200 Subject: [PATCH 3/3] Add comment --- runtime/parachains/src/disputes.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/parachains/src/disputes.rs b/runtime/parachains/src/disputes.rs index 443e1add74f9..3c1f1a334c9f 100644 --- a/runtime/parachains/src/disputes.rs +++ b/runtime/parachains/src/disputes.rs @@ -939,6 +939,7 @@ impl Pallet { // // Votes which are duplicate or already known by the chain are filtered out. // The entire set is removed if the dispute is both, ancient and concluded. + // Disputes without enough votes to get confirmed are also filtered out. fn filter_dispute_data( set: &DisputeStatementSet, post_conclusion_acceptance_period: ::BlockNumber,