mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 19:37:56 +00:00
Sanity check for Babe's configuration (#11385)
* Prevent div by zero in native babe code * Additional sanity check for babe config * Further sanity checks and postpone threshold computation * Apply suggestions from code review Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
use codec::{Decode, Encode};
|
||||
use frame_support::{
|
||||
dispatch::DispatchResultWithPostInfo,
|
||||
ensure,
|
||||
traits::{
|
||||
ConstU32, DisabledValidators, FindAuthor, Get, KeyOwnerProofSystem, OnTimestampSet,
|
||||
OneSessionHandler,
|
||||
@@ -42,8 +43,8 @@ use sp_std::prelude::*;
|
||||
|
||||
use sp_consensus_babe::{
|
||||
digests::{NextConfigDescriptor, NextEpochDescriptor, PreDigest},
|
||||
BabeAuthorityWeight, BabeEpochConfiguration, ConsensusLog, Epoch, EquivocationProof, Slot,
|
||||
BABE_ENGINE_ID,
|
||||
AllowedSlots, BabeAuthorityWeight, BabeEpochConfiguration, ConsensusLog, Epoch,
|
||||
EquivocationProof, Slot, BABE_ENGINE_ID,
|
||||
};
|
||||
use sp_consensus_vrf::schnorrkel;
|
||||
|
||||
@@ -185,6 +186,8 @@ pub mod pallet {
|
||||
InvalidKeyOwnershipProof,
|
||||
/// A given equivocation report is valid but already previously reported.
|
||||
DuplicateOffenceReport,
|
||||
/// Submitted configuration is invalid.
|
||||
InvalidConfiguration,
|
||||
}
|
||||
|
||||
/// Current epoch index.
|
||||
@@ -447,6 +450,14 @@ pub mod pallet {
|
||||
config: NextConfigDescriptor,
|
||||
) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
match config {
|
||||
NextConfigDescriptor::V1 { c, allowed_slots } => {
|
||||
ensure!(
|
||||
(c.0 != 0 || allowed_slots != AllowedSlots::PrimarySlots) && c.1 != 0,
|
||||
Error::<T>::InvalidConfiguration
|
||||
);
|
||||
},
|
||||
}
|
||||
PendingEpochConfigChange::<T>::put(config);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user