From 81b54a36011e437b347f4ead68ad1e5eecdc8554 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Mon, 21 Nov 2022 14:39:21 +0200 Subject: [PATCH] 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 9f458421e2ed..869a836391d1 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;