mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 15:47:58 +00:00
generate_storage_alias: Rewrite as proc macro attribute (#11387)
* generate_storage_alias: Rewrite as proc macro attribute
This rewrites the `generate_storage_alias!` declarative macro as proc-macro attribute. While doing
this the name is changed to `storage_alias`. The prefix can now also be the name of a pallet. This
makes storage aliases work in migrations for all kind of chains and not just for the ones that use
predefined prefixes.
* Fix compilation and FMT
* Moare fixes
* 🤦
* ......
* Rework the syntax and support instancing
* FMT
* Prefix variants with `Storage`
* Make it compile
* Fix where clause on rust stable
This commit is contained in:
@@ -139,18 +139,20 @@ pub mod v8 {
|
||||
|
||||
pub mod v7 {
|
||||
use super::*;
|
||||
use frame_support::generate_storage_alias;
|
||||
use frame_support::storage_alias;
|
||||
|
||||
generate_storage_alias!(Staking, CounterForValidators => Value<u32>);
|
||||
generate_storage_alias!(Staking, CounterForNominators => Value<u32>);
|
||||
#[storage_alias]
|
||||
type CounterForValidators<T: Config> = StorageValue<Pallet<T>, u32>;
|
||||
#[storage_alias]
|
||||
type CounterForNominators<T: Config> = StorageValue<Pallet<T>, u32>;
|
||||
|
||||
pub fn pre_migrate<T: Config>() -> Result<(), &'static str> {
|
||||
assert!(
|
||||
CounterForValidators::get().unwrap().is_zero(),
|
||||
CounterForValidators::<T>::get().unwrap().is_zero(),
|
||||
"CounterForValidators already set."
|
||||
);
|
||||
assert!(
|
||||
CounterForNominators::get().unwrap().is_zero(),
|
||||
CounterForNominators::<T>::get().unwrap().is_zero(),
|
||||
"CounterForNominators already set."
|
||||
);
|
||||
assert!(Validators::<T>::count().is_zero(), "Validators already set.");
|
||||
@@ -164,8 +166,8 @@ pub mod v7 {
|
||||
let validator_count = Validators::<T>::iter().count() as u32;
|
||||
let nominator_count = Nominators::<T>::iter().count() as u32;
|
||||
|
||||
CounterForValidators::put(validator_count);
|
||||
CounterForNominators::put(nominator_count);
|
||||
CounterForValidators::<T>::put(validator_count);
|
||||
CounterForNominators::<T>::put(nominator_count);
|
||||
|
||||
StorageVersion::<T>::put(Releases::V7_0_0);
|
||||
log!(info, "Completed staking migration to Releases::V7_0_0");
|
||||
@@ -176,26 +178,35 @@ pub mod v7 {
|
||||
|
||||
pub mod v6 {
|
||||
use super::*;
|
||||
use frame_support::{generate_storage_alias, traits::Get, weights::Weight};
|
||||
use frame_support::{storage_alias, traits::Get, weights::Weight};
|
||||
|
||||
// NOTE: value type doesn't matter, we just set it to () here.
|
||||
generate_storage_alias!(Staking, SnapshotValidators => Value<()>);
|
||||
generate_storage_alias!(Staking, SnapshotNominators => Value<()>);
|
||||
generate_storage_alias!(Staking, QueuedElected => Value<()>);
|
||||
generate_storage_alias!(Staking, QueuedScore => Value<()>);
|
||||
generate_storage_alias!(Staking, EraElectionStatus => Value<()>);
|
||||
generate_storage_alias!(Staking, IsCurrentSessionFinal => Value<()>);
|
||||
#[storage_alias]
|
||||
type SnapshotValidators<T: Config> = StorageValue<Pallet<T>, ()>;
|
||||
#[storage_alias]
|
||||
type SnapshotNominators<T: Config> = StorageValue<Pallet<T>, ()>;
|
||||
#[storage_alias]
|
||||
type QueuedElected<T: Config> = StorageValue<Pallet<T>, ()>;
|
||||
#[storage_alias]
|
||||
type QueuedScore<T: Config> = StorageValue<Pallet<T>, ()>;
|
||||
#[storage_alias]
|
||||
type EraElectionStatus<T: Config> = StorageValue<Pallet<T>, ()>;
|
||||
#[storage_alias]
|
||||
type IsCurrentSessionFinal<T: Config> = StorageValue<Pallet<T>, ()>;
|
||||
|
||||
/// check to execute prior to migration.
|
||||
pub fn pre_migrate<T: Config>() -> Result<(), &'static str> {
|
||||
// these may or may not exist.
|
||||
log!(info, "SnapshotValidators.exits()? {:?}", SnapshotValidators::exists());
|
||||
log!(info, "SnapshotNominators.exits()? {:?}", SnapshotNominators::exists());
|
||||
log!(info, "QueuedElected.exits()? {:?}", QueuedElected::exists());
|
||||
log!(info, "QueuedScore.exits()? {:?}", QueuedScore::exists());
|
||||
log!(info, "SnapshotValidators.exits()? {:?}", SnapshotValidators::<T>::exists());
|
||||
log!(info, "SnapshotNominators.exits()? {:?}", SnapshotNominators::<T>::exists());
|
||||
log!(info, "QueuedElected.exits()? {:?}", QueuedElected::<T>::exists());
|
||||
log!(info, "QueuedScore.exits()? {:?}", QueuedScore::<T>::exists());
|
||||
// these must exist.
|
||||
assert!(IsCurrentSessionFinal::exists(), "IsCurrentSessionFinal storage item not found!");
|
||||
assert!(EraElectionStatus::exists(), "EraElectionStatus storage item not found!");
|
||||
assert!(
|
||||
IsCurrentSessionFinal::<T>::exists(),
|
||||
"IsCurrentSessionFinal storage item not found!"
|
||||
);
|
||||
assert!(EraElectionStatus::<T>::exists(), "EraElectionStatus storage item not found!");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -203,12 +214,12 @@ pub mod v6 {
|
||||
pub fn migrate<T: Config>() -> Weight {
|
||||
log!(info, "Migrating staking to Releases::V6_0_0");
|
||||
|
||||
SnapshotValidators::kill();
|
||||
SnapshotNominators::kill();
|
||||
QueuedElected::kill();
|
||||
QueuedScore::kill();
|
||||
EraElectionStatus::kill();
|
||||
IsCurrentSessionFinal::kill();
|
||||
SnapshotValidators::<T>::kill();
|
||||
SnapshotNominators::<T>::kill();
|
||||
QueuedElected::<T>::kill();
|
||||
QueuedScore::<T>::kill();
|
||||
EraElectionStatus::<T>::kill();
|
||||
IsCurrentSessionFinal::<T>::kill();
|
||||
|
||||
StorageVersion::<T>::put(Releases::V6_0_0);
|
||||
log!(info, "Done.");
|
||||
|
||||
Reference in New Issue
Block a user