mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 19:21:13 +00:00
BEEFY: define on-chain beefy-genesis and use it to coordinate voter initialization (#13215)
* beefy: add support to configure BEEFY genesis * client/beefy: more flexible test runtime api * client/beefy: add tests for custom BEEFY genesis * client/beefy: ignore old state that didn't account for pallet genesis * client/beefy: fix clippy * frame/beefy: default BEEFY-genesis is block One::one() * frame/beefy: add extra doc comments --------- Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -49,6 +49,7 @@ pub use pallet::*;
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {
|
||||
@@ -91,15 +92,32 @@ pub mod pallet {
|
||||
pub(super) type NextAuthorities<T: Config> =
|
||||
StorageValue<_, BoundedVec<T::BeefyId, T::MaxAuthorities>, ValueQuery>;
|
||||
|
||||
/// Block number where BEEFY consensus is enabled/started.
|
||||
/// If changing this, make sure `Self::ValidatorSetId` is also reset to
|
||||
/// `GENESIS_AUTHORITY_SET_ID` in the state of the new block number configured here.
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn genesis_block)]
|
||||
pub(super) type GenesisBlock<T: Config> =
|
||||
StorageValue<_, Option<BlockNumberFor<T>>, ValueQuery>;
|
||||
|
||||
#[pallet::genesis_config]
|
||||
pub struct GenesisConfig<T: Config> {
|
||||
/// Initial set of BEEFY authorities.
|
||||
pub authorities: Vec<T::BeefyId>,
|
||||
/// Block number where BEEFY consensus should start.
|
||||
/// Should match the session where initial authorities are active.
|
||||
/// *Note:* Ideally use block number where GRANDPA authorities are changed,
|
||||
/// to guarantee the client gets a finality notification for exactly this block.
|
||||
pub genesis_block: Option<BlockNumberFor<T>>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<T: Config> Default for GenesisConfig<T> {
|
||||
fn default() -> Self {
|
||||
Self { authorities: Vec::new() }
|
||||
// BEEFY genesis will be first BEEFY-MANDATORY block,
|
||||
// use block number one instead of chain-genesis.
|
||||
let genesis_block = Some(sp_runtime::traits::One::one());
|
||||
Self { authorities: Vec::new(), genesis_block }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,6 +128,7 @@ pub mod pallet {
|
||||
// we panic here as runtime maintainers can simply reconfigure genesis and restart
|
||||
// the chain easily
|
||||
.expect("Authorities vec too big");
|
||||
<GenesisBlock<T>>::put(&self.genesis_block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user