mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 07:01:03 +00:00
Kusama state version switch and migration. (#7015)
* State version switch and migration init * fix * migration declaration (last position, westend was first) * revert unrelated cargo fmt * move to unrelease * fmt? * fmt * Change size of processing per blocks * Dispatch error
This commit is contained in:
Generated
+1
@@ -3853,6 +3853,7 @@ dependencies = [
|
||||
"pallet-society",
|
||||
"pallet-staking",
|
||||
"pallet-staking-runtime-api",
|
||||
"pallet-state-trie-migration",
|
||||
"pallet-timestamp",
|
||||
"pallet-tips",
|
||||
"pallet-transaction-payment",
|
||||
|
||||
@@ -73,6 +73,7 @@ pallet-session = { git = "https://github.com/paritytech/substrate", branch = "ma
|
||||
pallet-society = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
pallet-staking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
pallet-state-trie-migration = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
pallet-staking-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
frame-system = {git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
|
||||
@@ -173,6 +174,7 @@ std = [
|
||||
"pallet-society/std",
|
||||
"pallet-staking/std",
|
||||
"pallet-staking-runtime-api/std",
|
||||
"pallet-state-trie-migration/std",
|
||||
"pallet-timestamp/std",
|
||||
"pallet-tips/std",
|
||||
"pallet-treasury/std",
|
||||
@@ -290,6 +292,7 @@ try-runtime = [
|
||||
"pallet-session/try-runtime",
|
||||
"pallet-society/try-runtime",
|
||||
"pallet-staking/try-runtime",
|
||||
"pallet-state-trie-migration/try-runtime",
|
||||
"pallet-timestamp/try-runtime",
|
||||
"pallet-tips/try-runtime",
|
||||
"pallet-treasury/try-runtime",
|
||||
|
||||
@@ -140,7 +140,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
#[cfg(feature = "disable-runtime-api")]
|
||||
apis: sp_version::create_apis_vec![[]],
|
||||
transaction_version: 23,
|
||||
state_version: 0,
|
||||
state_version: 1,
|
||||
};
|
||||
|
||||
/// The BABE epoch configuration at genesis.
|
||||
@@ -1340,6 +1340,26 @@ impl pallet_nomination_pools::Config for Runtime {
|
||||
type MaxPointsToBalance = MaxPointsToBalance;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
// The deposit configuration for the singed migration. Specially if you want to allow any signed account to do the migration (see `SignedFilter`, these deposits should be high)
|
||||
pub const MigrationSignedDepositPerItem: Balance = 1 * CENTS;
|
||||
pub const MigrationSignedDepositBase: Balance = 20 * CENTS * 100;
|
||||
pub const MigrationMaxKeyLen: u32 = 512;
|
||||
}
|
||||
|
||||
impl pallet_state_trie_migration::Config for Runtime {
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type Currency = Balances;
|
||||
type SignedDepositPerItem = MigrationSignedDepositPerItem;
|
||||
type SignedDepositBase = MigrationSignedDepositBase;
|
||||
type ControlOrigin = EnsureRoot<AccountId>;
|
||||
type SignedFilter = frame_support::traits::NeverEnsureOrigin<AccountId>;
|
||||
|
||||
// Use same weights as substrate ones.
|
||||
type WeightInfo = pallet_state_trie_migration::weights::SubstrateWeight<Runtime>;
|
||||
type MaxKeyLen = MigrationMaxKeyLen;
|
||||
}
|
||||
|
||||
construct_runtime! {
|
||||
pub enum Runtime where
|
||||
Block = Block,
|
||||
@@ -1456,6 +1476,9 @@ construct_runtime! {
|
||||
Auctions: auctions::{Pallet, Call, Storage, Event<T>} = 72,
|
||||
Crowdloan: crowdloan::{Pallet, Call, Storage, Event<T>} = 73,
|
||||
|
||||
// State trie migration pallet, only temporary.
|
||||
StateTrieMigration: pallet_state_trie_migration = 98,
|
||||
|
||||
// Pallet for sending XCM.
|
||||
XcmPallet: pallet_xcm::{Pallet, Call, Storage, Event<T>, Origin, Config} = 99,
|
||||
|
||||
@@ -1534,6 +1557,7 @@ pub mod migrations {
|
||||
|
||||
/// Unreleased migrations. Add new ones here:
|
||||
pub type Unreleased = (
|
||||
init_state_migration::InitMigrate,
|
||||
pallet_society::migrations::MigrateToV2<Runtime, (), past_payouts::PastPayouts>,
|
||||
pallet_im_online::migration::v1::Migration<Runtime>,
|
||||
);
|
||||
@@ -2478,3 +2502,52 @@ mod remote_tests {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
mod init_state_migration {
|
||||
use super::Runtime;
|
||||
use frame_support::traits::OnRuntimeUpgrade;
|
||||
use pallet_state_trie_migration::{AutoLimits, MigrationLimits, MigrationProcess};
|
||||
#[cfg(feature = "try-runtime")]
|
||||
use sp_runtime::DispatchError;
|
||||
#[cfg(not(feature = "std"))]
|
||||
use sp_std::prelude::*;
|
||||
|
||||
/// Initialize an automatic migration process.
|
||||
pub struct InitMigrate;
|
||||
impl OnRuntimeUpgrade for InitMigrate {
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn pre_upgrade() -> Result<Vec<u8>, DispatchError> {
|
||||
frame_support::ensure!(
|
||||
AutoLimits::<Runtime>::get().is_none(),
|
||||
DispatchError::Other("Automigration already started.")
|
||||
);
|
||||
Ok(Default::default())
|
||||
}
|
||||
|
||||
fn on_runtime_upgrade() -> frame_support::weights::Weight {
|
||||
if MigrationProcess::<Runtime>::get() == Default::default() &&
|
||||
AutoLimits::<Runtime>::get().is_none()
|
||||
{
|
||||
// We use limits to target 600ko proofs per block and
|
||||
// avg 800_000_000_000 of weight per block.
|
||||
// See spreadsheet 4800_400 in
|
||||
// https://raw.githubusercontent.com/cheme/substrate/try-runtime-mig/ksm.ods
|
||||
AutoLimits::<Runtime>::put(Some(MigrationLimits { item: 4_800, size: 204800 * 2 }));
|
||||
log::info!("Automatic trie migration started.");
|
||||
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(2, 1)
|
||||
} else {
|
||||
log::info!("Automatic trie migration not started.");
|
||||
<Runtime as frame_system::Config>::DbWeight::get().reads(2)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "try-runtime")]
|
||||
fn post_upgrade(_state: Vec<u8>) -> Result<(), DispatchError> {
|
||||
frame_support::ensure!(
|
||||
AutoLimits::<Runtime>::get().is_some(),
|
||||
DispatchError::Other("Automigration started.")
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user