Unverified Commit d33794f1 authored by Andronik Ordian's avatar Andronik Ordian Committed by GitHub
Browse files

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

* paras_inherent: reject only candidates with concluded disputes

* remove unused Error variant
parent 71a721eb
Pipeline #159860 canceled with stages
in 27 minutes and 31 seconds
......@@ -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]));
......
......@@ -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,
);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment