Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove state trie migration from kusama, add it to polkadot #170

Merged
merged 21 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Added

- Remove state-trie-migration pallet from kusama, add state trie migration to V1 on polkadot ([polkadot-fellows/runtimes#170](https://github.com/polkadot-fellows/runtimes/pull/170))
- Introduce chain spec generator ([polkadot-fellows/runtimes#127](https://github.com/polkadot-fellows/runtimes/pull/127))
- Add [Encointer](https://encointer.org) system parachain runtime, completing [RFC22](https://github.com/polkadot-fellows/RFCs/blob/main/text/
0022-adopt-encointer-runtime.md) ([polkadot-fellows/runtimes#80](https://github.com/polkadot-fellows/runtimes/pull/80))
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions relay/kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ pallet-session = { default-features = false , version = "29.0.0" }
pallet-society = { default-features = false, version = "29.0.0" }
frame-support = { default-features = false , features = [ "tuples-96" ] , version = "29.0.0" }
pallet-staking = { default-features = false , version = "29.0.0" }
pallet-state-trie-migration = { default-features = false , version = "30.0.0" }
pallet-staking-runtime-api = { default-features = false , version = "15.0.0" }
frame-system = { default-features = false , version = "29.0.0" }
frame-system-rpc-runtime-api = { default-features = false , version = "27.0.0" }
Expand Down Expand Up @@ -175,7 +174,6 @@ std = [
"pallet-society/std",
"pallet-staking-runtime-api/std",
"pallet-staking/std",
"pallet-state-trie-migration/std",
"pallet-timestamp/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment/std",
Expand Down Expand Up @@ -246,7 +244,6 @@ runtime-benchmarks = [
"pallet-session-benchmarking/runtime-benchmarks",
"pallet-society/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
"pallet-state-trie-migration/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
Expand Down Expand Up @@ -300,7 +297,6 @@ 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-transaction-payment/try-runtime",
"pallet-treasury/try-runtime",
Expand Down
86 changes: 2 additions & 84 deletions relay/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1541,27 +1541,6 @@ 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 RuntimeHoldReason = RuntimeHoldReason;
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;
}

impl pallet_asset_rate::Config for Runtime {
type WeightInfo = weights::pallet_asset_rate::WeightInfo<Runtime>;
type RuntimeEvent = RuntimeEvent;
Expand Down Expand Up @@ -1739,9 +1718,6 @@ construct_runtime! {
Crowdloan: crowdloan = 73,
Coretime: coretime = 74,

// State trie migration pallet, only temporary.
StateTrieMigration: pallet_state_trie_migration = 98,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need to write some migration to remove all the old pallet storage items? There already exists the RemovePallet migration that we can use for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I will try to use the code we ran on westend


// Pallet for sending XCM.
XcmPallet: pallet_xcm = 99,

Expand Down Expand Up @@ -1852,6 +1828,7 @@ pub mod migrations {
}

parameter_types! {
pub const StateTrieMigrationName: &'static str = "StateTrieMigration";
pub const ImOnlinePalletName: &'static str = "ImOnline";
}

Expand Down Expand Up @@ -1968,6 +1945,7 @@ pub mod migrations {

bkchr marked this conversation as resolved.
Show resolved Hide resolved
/// Unreleased migrations. Add new ones here:
pub type Unreleased = (
frame_support::migrations::RemovePallet<StateTrieMigrationName, RocksDbWeight>,
pallet_nomination_pools::migration::versioned::V7ToV8<Runtime>,
pallet_staking::migrations::v14::MigrateToV14<Runtime>,
parachains_configuration::migration::v10::MigrateToV10<Runtime>,
Expand Down Expand Up @@ -3064,63 +3042,3 @@ mod remote_tests {
});
}
}

mod init_state_migration {
use super::Runtime;
use frame_support::traits::OnRuntimeUpgrade;
use pallet_state_trie_migration::{AutoLimits, MigrationLimits, MigrationProcess};

/// Initialize an automatic migration process.
pub struct InitMigrate;
impl OnRuntimeUpgrade for InitMigrate {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, sp_runtime::DispatchError> {
use parity_scale_codec::Encode;
let migration_should_start = AutoLimits::<Runtime>::get().is_none() &&
MigrationProcess::<Runtime>::get() == Default::default();
Ok(migration_should_start.encode())
}

fn on_runtime_upgrade() -> frame_support::weights::Weight {
if AutoLimits::<Runtime>::get().is_some() {
log::warn!("Automatic trie migration already started, not proceeding.");
return <Runtime as frame_system::Config>::DbWeight::get().reads(1)
};

if MigrationProcess::<Runtime>::get() != Default::default() {
log::warn!("MigrationProcess is not Default. Not proceeding.");
return <Runtime as frame_system::Config>::DbWeight::get().reads(2)
};

// Migration is not already running and `MigraitonProcess` is Default. Ready to run
// migrations.
//
// 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)
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(
migration_should_start_bytes: sp_std::vec::Vec<u8>,
) -> Result<(), sp_runtime::DispatchError> {
use parity_scale_codec::Decode;
let migration_should_start: bool =
Decode::decode(&mut migration_should_start_bytes.as_slice())
.expect("failed to decode migration should start");

if migration_should_start {
frame_support::ensure!(
AutoLimits::<Runtime>::get().is_some(),
sp_runtime::DispatchError::Other("Automigration did not start as expected.")
);
}

Ok(())
}
}
}
4 changes: 4 additions & 0 deletions relay/polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pallet-staking = { default-features = false , version = "29.0.0" }
pallet-staking-reward-fn = { default-features = false, version = "20.0.0" }
pallet-staking-reward-curve = { version = "11.0.0" }
pallet-staking-runtime-api = { default-features = false , version = "15.0.0" }
pallet-state-trie-migration = { default-features = false , version = "30.0.0" }
frame-system = { default-features = false , version = "29.0.0" }
frame-system-rpc-runtime-api = { default-features = false , version = "27.0.0" }
polkadot-runtime-constants = { package = "polkadot-runtime-constants", path = "constants", default-features = false }
Expand Down Expand Up @@ -166,6 +167,7 @@ std = [
"pallet-staking-reward-fn/std",
"pallet-staking-runtime-api/std",
"pallet-staking/std",
"pallet-state-trie-migration/std",
"pallet-timestamp/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment/std",
Expand Down Expand Up @@ -233,6 +235,7 @@ runtime-benchmarks = [
"pallet-scheduler/runtime-benchmarks",
"pallet-session-benchmarking/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
"pallet-state-trie-migration/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
Expand Down Expand Up @@ -282,6 +285,7 @@ try-runtime = [
"pallet-scheduler/try-runtime",
"pallet-session/try-runtime",
"pallet-staking/try-runtime",
"pallet-state-trie-migration/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-treasury/try-runtime",
Expand Down
89 changes: 88 additions & 1 deletion relay/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 25,
state_version: 0,
state_version: 1,
};

/// The BABE epoch configuration at genesis.
Expand Down Expand Up @@ -1541,6 +1541,27 @@ impl frame_support::traits::OnRuntimeUpgrade for InitiateNominationPools {
}
}

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 RuntimeHoldReason = RuntimeHoldReason;
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;
}

impl pallet_asset_rate::Config for Runtime {
type WeightInfo = weights::pallet_asset_rate::WeightInfo<Runtime>;
type RuntimeEvent = RuntimeEvent;
Expand Down Expand Up @@ -1697,6 +1718,9 @@ construct_runtime! {
Auctions: auctions = 72,
Crowdloan: crowdloan = 73,

// State trie migration pallet, only temporary.
StateTrieMigration: pallet_state_trie_migration = 98,

// Pallet for sending XCM.
XcmPallet: pallet_xcm = 99,

Expand Down Expand Up @@ -1843,6 +1867,7 @@ pub mod migrations {

/// Unreleased migrations. Add new ones here:
pub type Unreleased = (
init_state_migration::InitMigrate,
// Upgrade SessionKeys to exclude ImOnline key
UpgradeSessionKeys,
pallet_nomination_pools::migration::versioned::V7ToV8<Runtime>,
Expand Down Expand Up @@ -3153,3 +3178,65 @@ mod remote_tests {
});
}
}

mod init_state_migration {
use super::Runtime;
use frame_support::traits::OnRuntimeUpgrade;
use pallet_state_trie_migration::{AutoLimits, MigrationLimits, MigrationProcess};
#[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>, sp_runtime::DispatchError> {
use parity_scale_codec::Encode;
let migration_should_start = AutoLimits::<Runtime>::get().is_none() &&
MigrationProcess::<Runtime>::get() == Default::default();
Ok(migration_should_start.encode())
}

fn on_runtime_upgrade() -> frame_support::weights::Weight {
if AutoLimits::<Runtime>::get().is_some() {
log::warn!("Automatic trie migration already started, not proceeding.");
return <Runtime as frame_system::Config>::DbWeight::get().reads(1)
};

if MigrationProcess::<Runtime>::get() != Default::default() {
log::warn!("MigrationProcess is not Default. Not proceeding.");
return <Runtime as frame_system::Config>::DbWeight::get().reads(2)
};

// Migration is not already running and `MigraitonProcess` is Default. Ready to run
// migrations.
//
// 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)
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(
migration_should_start_bytes: Vec<u8>,
) -> Result<(), sp_runtime::DispatchError> {
use parity_scale_codec::Decode;
let migration_should_start: bool =
Decode::decode(&mut migration_should_start_bytes.as_slice())
.expect("failed to decode migration should start");

if migration_should_start {
frame_support::ensure!(
AutoLimits::<Runtime>::get().is_some(),
sp_runtime::DispatchError::Other("Automigration did not start as expected.")
);
}

Ok(())
}
}
}
Loading