paras_inherent: reject only candidates with concluded disputes (#3969)

* paras_inherent: reject only candidates with concluded disputes

* remove unused Error variant
This commit is contained in:
Andronik Ordian
2021-09-29 20:58:04 +02:00
committed by GitHub
parent 3c8e8637ff
commit 019d4e3b99
2 changed files with 16 additions and 17 deletions
+11 -12
View File
@@ -129,9 +129,8 @@ pub trait DisputesHandler<BlockNumber> {
included_in: BlockNumber, included_in: BlockNumber,
); );
/// Whether the given candidate could be invalid, i.e. there is an ongoing /// Whether the given candidate concluded invalid in a dispute with supermajority.
/// or concluded dispute with supermajority-against. fn concluded_invalid(session: SessionIndex, candidate_hash: CandidateHash) -> bool;
fn could_be_invalid(session: SessionIndex, candidate_hash: CandidateHash) -> bool;
/// Called by the initializer to initialize the configuration module. /// Called by the initializer to initialize the configuration module.
fn initializer_initialize(now: BlockNumber) -> Weight; 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 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) pallet::Pallet::<T>::note_included(session, candidate_hash, included_in)
} }
fn could_be_invalid(session: SessionIndex, candidate_hash: CandidateHash) -> bool { fn concluded_invalid(session: SessionIndex, candidate_hash: CandidateHash) -> bool {
pallet::Pallet::<T>::could_be_invalid(session, candidate_hash) pallet::Pallet::<T>::concluded_invalid(session, candidate_hash)
} }
fn initializer_initialize(now: T::BlockNumber) -> Weight { 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| { <Disputes<T>>::get(&session, &candidate_hash).map_or(false, |dispute| {
// A dispute that is ongoing or has concluded with supermajority-against. // A dispute that has concluded with supermajority-against.
dispute.concluded_at.is_none() || has_supermajority_against(&dispute) 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!(!Pallet::<Test>::concluded_invalid(3, candidate_hash.clone()));
assert_eq!(Pallet::<Test>::could_be_invalid(4, candidate_hash.clone()), true); assert!(!Pallet::<Test>::concluded_invalid(4, candidate_hash.clone()));
assert_eq!(Pallet::<Test>::could_be_invalid(5, candidate_hash.clone()), true); assert!(Pallet::<Test>::concluded_invalid(5, candidate_hash.clone()));
// Ensure inclusion removes spam slots // Ensure inclusion removes spam slots
assert_eq!(SpamSlots::<Test>::get(4), Some(vec![0, 0, 1, 1, 0, 0, 0])); assert_eq!(SpamSlots::<Test>::get(4), Some(vec![0, 0, 1, 1, 0, 0, 0]));
@@ -66,8 +66,8 @@ pub mod pallet {
/// The hash of the submitted parent header doesn't correspond to the saved block hash of /// The hash of the submitted parent header doesn't correspond to the saved block hash of
/// the parent. /// the parent.
InvalidParentHeader, InvalidParentHeader,
/// Potentially invalid candidate. /// Disputed candidate that was concluded invalid.
CandidateCouldBeInvalid, CandidateConcludedInvalid,
} }
/// Whether the paras inherent was included within this block. /// 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 = limit_backed_candidates::<T>(backed_candidates);
let backed_candidates_len = backed_candidates.len() as Weight; 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 { for candidate in &backed_candidates {
ensure!( ensure!(
!T::DisputesHandler::could_be_invalid( !T::DisputesHandler::concluded_invalid(
current_session, current_session,
candidate.candidate.hash(), candidate.candidate.hash(),
), ),
Error::<T>::CandidateCouldBeInvalid, Error::<T>::CandidateConcludedInvalid,
); );
} }