babe: make plan_config_change callable (#8233)

This commit is contained in:
André Silva
2021-03-01 14:58:49 +00:00
committed by GitHub
parent 68390d4085
commit 13ef9ad39e
3 changed files with 59 additions and 14 deletions
+15 -10
View File
@@ -29,7 +29,7 @@ use frame_support::{
weights::{Pays, Weight},
Parameter,
};
use frame_system::{ensure_none, ensure_signed};
use frame_system::{ensure_none, ensure_root, ensure_signed};
use sp_application_crypto::Public;
use sp_runtime::{
generic::DigestItem,
@@ -108,6 +108,7 @@ pub trait Config: pallet_timestamp::Config {
}
pub trait WeightInfo {
fn plan_config_change() -> Weight;
fn report_equivocation(validator_count: u32) -> Weight;
}
@@ -314,6 +315,19 @@ decl_module! {
key_owner_proof,
)
}
/// Plan an epoch config change. The epoch config change is recorded and will be enacted on
/// the next call to `enact_epoch_change`. The config will be activated one epoch after.
/// Multiple calls to this method will replace any existing planned config change that had
/// not been enacted yet.
#[weight = <T as Config>::WeightInfo::plan_config_change()]
fn plan_config_change(
origin,
config: NextConfigDescriptor,
) {
ensure_root(origin)?;
NextEpochConfig::put(config);
}
}
}
@@ -432,15 +446,6 @@ impl<T: Config> Module<T> {
})
}
/// Plan an epoch config change. The epoch config change is recorded and will be enacted on the
/// next call to `enact_epoch_change`. The config will be activated one epoch after. Multiple calls to this
/// method will replace any existing planned config change that had not been enacted yet.
pub fn plan_config_change(
config: NextConfigDescriptor,
) {
NextEpochConfig::put(config);
}
/// DANGEROUS: Enact an epoch change. Should be done on every block where `should_epoch_change` has returned `true`,
/// and the caller is the only caller of this function.
///