From 019d4e3b995cca8ac45b2e7954008d6278e27ffe Mon Sep 17 00:00:00 2001 From: Andronik Ordian <write@reusable.software> Date: Wed, 29 Sep 2021 20:58:04 +0200 Subject: [PATCH] paras_inherent: reject only candidates with concluded disputes (#3969) * paras_inherent: reject only candidates with concluded disputes * remove unused Error variant --- polkadot/runtime/parachains/src/disputes.rs | 23 +++++++++---------- .../runtime/parachains/src/paras_inherent.rs | 10 ++++---- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/polkadot/runtime/parachains/src/disputes.rs b/polkadot/runtime/parachains/src/disputes.rs index aa7acee6d27..b63305efb27 100644 --- a/polkadot/runtime/parachains/src/disputes.rs +++ b/polkadot/runtime/parachains/src/disputes.rs @@ -129,9 +129,8 @@ pub trait DisputesHandler<BlockNumber> { included_in: BlockNumber, ); - /// Whether the given candidate could be invalid, i.e. there is an ongoing - /// or concluded dispute with supermajority-against. - fn could_be_invalid(session: SessionIndex, candidate_hash: CandidateHash) -> bool; + /// Whether the given candidate concluded invalid in a dispute with supermajority. + fn concluded_invalid(session: SessionIndex, candidate_hash: CandidateHash) -> bool; /// Called by the initializer to initialize the configuration module. fn initializer_initialize(now: BlockNumber) -> Weight; @@ -165,7 +164,7 @@ impl<BlockNumber> DisputesHandler<BlockNumber> for () { ) { } - fn could_be_invalid(_session: SessionIndex, _candidate_hash: CandidateHash) -> bool { + fn concluded_invalid(_session: SessionIndex, _candidate_hash: CandidateHash) -> bool { false } @@ -201,8 +200,8 @@ impl<T: Config> DisputesHandler<T::BlockNumber> for pallet::Pallet<T> { pallet::Pallet::<T>::note_included(session, candidate_hash, included_in) } - fn could_be_invalid(session: SessionIndex, candidate_hash: CandidateHash) -> bool { - pallet::Pallet::<T>::could_be_invalid(session, candidate_hash) + fn concluded_invalid(session: SessionIndex, candidate_hash: CandidateHash) -> bool { + pallet::Pallet::<T>::concluded_invalid(session, candidate_hash) } fn initializer_initialize(now: T::BlockNumber) -> Weight { @@ -1114,10 +1113,10 @@ impl<T: Config> Pallet<T> { } } - pub(crate) fn could_be_invalid(session: SessionIndex, candidate_hash: CandidateHash) -> bool { + pub(crate) fn concluded_invalid(session: SessionIndex, candidate_hash: CandidateHash) -> bool { <Disputes<T>>::get(&session, &candidate_hash).map_or(false, |dispute| { - // A dispute that is ongoing or has concluded with supermajority-against. - dispute.concluded_at.is_none() || has_supermajority_against(&dispute) + // A dispute that has concluded with supermajority-against. + has_supermajority_against(&dispute) }) } @@ -2207,9 +2206,9 @@ mod tests { ] ); - assert_eq!(Pallet::<Test>::could_be_invalid(3, candidate_hash.clone()), false); // It has 5 votes for - assert_eq!(Pallet::<Test>::could_be_invalid(4, candidate_hash.clone()), true); - assert_eq!(Pallet::<Test>::could_be_invalid(5, candidate_hash.clone()), true); + assert!(!Pallet::<Test>::concluded_invalid(3, candidate_hash.clone())); + assert!(!Pallet::<Test>::concluded_invalid(4, candidate_hash.clone())); + assert!(Pallet::<Test>::concluded_invalid(5, candidate_hash.clone())); // Ensure inclusion removes spam slots assert_eq!(SpamSlots::<Test>::get(4), Some(vec![0, 0, 1, 1, 0, 0, 0])); diff --git a/polkadot/runtime/parachains/src/paras_inherent.rs b/polkadot/runtime/parachains/src/paras_inherent.rs index a972dbfaa3d..9ac8e014154 100644 --- a/polkadot/runtime/parachains/src/paras_inherent.rs +++ b/polkadot/runtime/parachains/src/paras_inherent.rs @@ -66,8 +66,8 @@ pub mod pallet { /// The hash of the submitted parent header doesn't correspond to the saved block hash of /// the parent. InvalidParentHeader, - /// Potentially invalid candidate. - CandidateCouldBeInvalid, + /// Disputed candidate that was concluded invalid. + CandidateConcludedInvalid, } /// Whether the paras inherent was included within this block. @@ -238,14 +238,14 @@ pub mod pallet { let backed_candidates = limit_backed_candidates::<T>(backed_candidates); let backed_candidates_len = backed_candidates.len() as Weight; - // Refuse to back any candidates that are disputed or invalid. + // Refuse to back any candidates that were disputed and are concluded invalid. for candidate in &backed_candidates { ensure!( - !T::DisputesHandler::could_be_invalid( + !T::DisputesHandler::concluded_invalid( current_session, candidate.candidate.hash(), ), - Error::<T>::CandidateCouldBeInvalid, + Error::<T>::CandidateConcludedInvalid, ); } -- GitLab