Fixed logic of the storage migration to triple reference counting. (#10337)

* Fixed logic of the storage migration to triple reference counting. The previous behaviour made it impossible for any chain not already upgraded to dual reference counting to upgrade the runtime.

* +Removed the on_runtime_upgrade() function from frame-system.
+Removed the specific migration .anciallaries from the frame-system pallet level.
+Introducted a new module that hosts self-contained ancillary functions and logic to perform the storage migration. The current logic attempts to infer the state of the storage based on whether or not a given migration can be conducted.

* Formatting.

* + Removed specific AccountData struct. AccountData must now be provided during the runtime implementation of the trait V2ToV3.
+ Removed apply function.
+ Made the individual translation function self-sufficient.

* + Removed unused decorators.
This commit is contained in:
remzrn
2021-12-09 08:05:48 +03:00
committed by GitHub
parent e1dc6c38e2
commit af64383214
2 changed files with 141 additions and 49 deletions
+2 -49
View File
@@ -114,6 +114,8 @@ pub mod mocking;
mod tests;
pub mod weights;
pub mod migrations;
pub use extensions::{
check_genesis::CheckGenesis, check_mortality::CheckMortality,
check_non_zero_sender::CheckNonZeroSender, check_nonce::CheckNonce,
@@ -315,15 +317,6 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
if !UpgradedToTripleRefCount::<T>::get() {
UpgradedToTripleRefCount::<T>::put(true);
migrations::migrate_to_triple_ref_count::<T>()
} else {
0
}
}
fn integrity_test() {
T::BlockWeights::get().validate().expect("The weights are invalid.");
}
@@ -634,46 +627,6 @@ pub mod pallet {
}
}
pub mod migrations {
use super::*;
#[allow(dead_code)]
/// Migrate from unique `u8` reference counting to triple `u32` reference counting.
pub fn migrate_all<T: Config>() -> frame_support::weights::Weight {
Account::<T>::translate::<(T::Index, u8, T::AccountData), _>(|_key, (nonce, rc, data)| {
Some(AccountInfo {
nonce,
consumers: rc as RefCount,
providers: 1,
sufficients: 0,
data,
})
});
T::BlockWeights::get().max_block
}
#[allow(dead_code)]
/// Migrate from unique `u32` reference counting to triple `u32` reference counting.
pub fn migrate_to_dual_ref_count<T: Config>() -> frame_support::weights::Weight {
Account::<T>::translate::<(T::Index, RefCount, T::AccountData), _>(
|_key, (nonce, consumers, data)| {
Some(AccountInfo { nonce, consumers, providers: 1, sufficients: 0, data })
},
);
T::BlockWeights::get().max_block
}
/// Migrate from dual `u32` reference counting to triple `u32` reference counting.
pub fn migrate_to_triple_ref_count<T: Config>() -> frame_support::weights::Weight {
Account::<T>::translate::<(T::Index, RefCount, RefCount, T::AccountData), _>(
|_key, (nonce, consumers, providers, data)| {
Some(AccountInfo { nonce, consumers, providers, sufficients: 0, data })
},
);
T::BlockWeights::get().max_block
}
}
#[cfg(feature = "std")]
impl GenesisConfig {
/// Direct implementation of `GenesisBuild::build_storage`.