Expand description
Implements a re-usable migration for the authority keys type
§Usage
Important: This migration assumes that the runtime is using [pallet_session] and will migrate that pallet’s key storage as well.
Authority keys migration is done by adding AuthorityKeysMigration to the runtime migrations as part of the runtime upgrade that will change the key type.
Preserve the old authority keys type and implement UpgradeAuthorityKeys trait for it. For example, if a chain that originally used Aura and Grandpa keys is being upgraded to also use Beefy, the definition of the legacy keys type could look like this:
use pallet_session_validator_management::migrations::authority_keys::UpgradeAuthorityKeys;
use sp_core::*;
use sp_runtime::impl_opaque_keys;
impl_opaque_keys! {
pub struct AuthorityKeys {
pub aura: Aura,
pub grandpa: Grandpa,
pub beefy: Beefy,
}
}
impl_opaque_keys! {
pub struct LegacyAuthorityKeys {
pub aura: Aura,
pub grandpa: Grandpa,
}
}
impl UpgradeAuthorityKeys<AuthorityKeys> for LegacyAuthorityKeys {
fn upgrade(self) -> AuthorityKeys {
AuthorityKeys {
aura: self.aura,
grandpa: self.grandpa,
beefy: ecdsa::Public::default().into(),
}
}
}The upgrade implementation can arbitrarily transform the data but must not fail for any
of the migrated key sets.
After implementing UpgradeAuthorityKeys, the migration can be added to the runtime’s migration set:
pub type Migrations = (
AuthorityKeysMigration<Runtime, LegacySessionKeys, 0, 1>,
// ...other migrations
);
// ...
pub type Executive = Executive<
Runtime,
Block,
ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
Migrations,
>;Note that AuthorityKeysMigration is parametrized by the session keys versions from which and to which it migrates, to guarantee idempotency. Current session keys version can be obtained by reading the AuthorityKeysVersion storage and by default starts as 0.
Structs§
- Authority
Keys Migration - Migrates existing committee members data in storage to use new type
AuthorityKeys
Traits§
- Upgrade
Authority Keys - Infallible cast from old to current
T::AuthorityKeys, used for storage migration