mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 21:37:56 +00:00
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:
@@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user