mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 22:41:06 +00:00
Runtime Upgrade ref docs and Single Block Migration example pallet (#1554)
Closes https://github.com/paritytech/polkadot-sdk-docs/issues/55 - Changes 'current storage version' terminology to less ambiguous 'in-code storage version' (suggestion by @ggwpez) - Adds a new example pallet `pallet-example-single-block-migrations` - Adds a new reference doc to replace https://docs.substrate.io/maintain/runtime-upgrades/ (temporarily living in the pallet while we wait for developer hub PR to merge) - Adds documentation for the `storage_alias` macro - Improves `trait Hooks` docs - Improves `trait GetStorageVersion` docs - Update the suggested patterns for using `VersionedMigration`, so that version unchecked migrations are never exported - Prevents accidental usage of version unchecked migrations in runtimes https://github.com/paritytech/substrate/pull/14421#discussion_r1255467895 - Unversioned migration code is kept inside `mod version_unchecked`, versioned code is kept in `pub mod versioned` - It is necessary to use modules to limit visibility because the inner migration must be `pub`. See https://github.com/rust-lang/rust/issues/30905 and https://internals.rust-lang.org/t/lang-team-minutes-private-in-public-rules/4504/40 for more. ### todo - [x] move to reference docs to proper place within sdk-docs (now that https://github.com/paritytech/polkadot-sdk/pull/2102 is merged) - [x] prdoc --------- Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Juan <juangirini@gmail.com> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: command-bot <> Co-authored-by: gupnik <nikhilgupta.iitk@gmail.com>
This commit is contained in:
@@ -46,7 +46,7 @@ use sp_runtime::{traits::Zero, Saturating};
|
||||
#[cfg(feature = "try-runtime")]
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
mod old {
|
||||
mod v14 {
|
||||
use super::*;
|
||||
|
||||
#[derive(
|
||||
@@ -81,7 +81,7 @@ pub fn store_old_contract_info<T: Config>(account: T::AccountId, info: crate::Co
|
||||
let entropy = (b"contract_depo_v1", account.clone()).using_encoded(T::Hashing::hash);
|
||||
let deposit_account = Decode::decode(&mut TrailingZeroInput::new(entropy.as_ref()))
|
||||
.expect("infinite length input; no invalid inputs for type; qed");
|
||||
let info = old::ContractInfo {
|
||||
let info = v14::ContractInfo {
|
||||
trie_id: info.trie_id.clone(),
|
||||
deposit_account,
|
||||
code_hash: info.code_hash,
|
||||
@@ -92,7 +92,7 @@ pub fn store_old_contract_info<T: Config>(account: T::AccountId, info: crate::Co
|
||||
storage_base_deposit: info.storage_base_deposit(),
|
||||
delegate_dependencies: info.delegate_dependencies().clone(),
|
||||
};
|
||||
old::ContractInfoOf::<T>::insert(account, info);
|
||||
v14::ContractInfoOf::<T>::insert(account, info);
|
||||
}
|
||||
|
||||
#[derive(Encode, Decode, CloneNoBound, PartialEq, Eq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
|
||||
@@ -127,11 +127,11 @@ impl<T: Config> MigrationStep for Migration<T> {
|
||||
|
||||
fn step(&mut self) -> (IsFinished, Weight) {
|
||||
let mut iter = if let Some(last_account) = self.last_account.take() {
|
||||
old::ContractInfoOf::<T>::iter_from(old::ContractInfoOf::<T>::hashed_key_for(
|
||||
v14::ContractInfoOf::<T>::iter_from(v14::ContractInfoOf::<T>::hashed_key_for(
|
||||
last_account,
|
||||
))
|
||||
} else {
|
||||
old::ContractInfoOf::<T>::iter()
|
||||
v14::ContractInfoOf::<T>::iter()
|
||||
};
|
||||
|
||||
if let Some((account, old_contract)) = iter.next() {
|
||||
@@ -243,11 +243,11 @@ impl<T: Config> MigrationStep for Migration<T> {
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn pre_upgrade_step() -> Result<Vec<u8>, TryRuntimeError> {
|
||||
let sample: Vec<_> = old::ContractInfoOf::<T>::iter().take(100).collect();
|
||||
let sample: Vec<_> = v14::ContractInfoOf::<T>::iter().take(100).collect();
|
||||
|
||||
log::debug!(target: LOG_TARGET, "Taking sample of {} contracts", sample.len());
|
||||
|
||||
let state: Vec<(T::AccountId, old::ContractInfo<T>, BalanceOf<T>, BalanceOf<T>)> = sample
|
||||
let state: Vec<(T::AccountId, v14::ContractInfo<T>, BalanceOf<T>, BalanceOf<T>)> = sample
|
||||
.iter()
|
||||
.map(|(account, contract)| {
|
||||
(
|
||||
@@ -265,7 +265,7 @@ impl<T: Config> MigrationStep for Migration<T> {
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn post_upgrade_step(state: Vec<u8>) -> Result<(), TryRuntimeError> {
|
||||
let sample =
|
||||
<Vec<(T::AccountId, old::ContractInfo<T>, BalanceOf<T>, BalanceOf<T>)> as Decode>::decode(
|
||||
<Vec<(T::AccountId, v14::ContractInfo<T>, BalanceOf<T>, BalanceOf<T>)> as Decode>::decode(
|
||||
&mut &state[..],
|
||||
)
|
||||
.expect("pre_upgrade_step provides a valid state; qed");
|
||||
|
||||
Reference in New Issue
Block a user