From fb4a414f0afff5a41a145a295d0051b7ce3097b6 Mon Sep 17 00:00:00 2001 From: Miguel <64885598+MiguelDD1@users.noreply.github.com> Date: Mon, 9 Jan 2023 14:13:08 +0100 Subject: [PATCH] Enable `try-runtime` feature (#129) * Enable `try-runtime` feature * Add migration Nomination pools & try-runtime support --- Cargo.lock | 21 +---- Cargo.toml | 4 - node/Cargo.toml | 5 +- node/src/chain_spec.rs | 26 +++--- pallets/dactr/Cargo.toml | 1 + pallets/executive/Cargo.toml | 9 ++- pallets/executive/src/lib.rs | 4 +- pallets/system/src/lib.rs | 2 +- pallets/system/src/migrations/mod.rs | 1 + pallets/system/src/migrations/v1.rs | 116 +++++---------------------- runtime/Cargo.toml | 33 +++++++- runtime/src/constants.rs | 16 +++- runtime/src/lib.rs | 65 ++++++++++++++- runtime/src/migration.rs | 110 +++++++++++++++++++++++++ 14 files changed, 270 insertions(+), 143 deletions(-) create mode 100644 runtime/src/migration.rs diff --git a/Cargo.lock b/Cargo.lock index a4a7a78e6..b4bb663ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2493,6 +2493,7 @@ dependencies = [ "da-primitives", "frame-support", "frame-system", + "frame-try-runtime", "hex-literal", "mocked-runtime", "pallet-babe", @@ -10800,23 +10801,3 @@ dependencies = [ "cc", "libc", ] - -[[patch.unused]] -name = "pallet-offences-benchmarking" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git/?branch=polkadot-v0.9.33#2dff067e9f7f6f3cc4dbfdaaa97753eccc407689" - -[[patch.unused]] -name = "pallet-session-benchmarking" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git/?branch=polkadot-v0.9.33#2dff067e9f7f6f3cc4dbfdaaa97753eccc407689" - -[[patch.unused]] -name = "parity-db" -version = "0.3.12" -source = "git+https://github.com/paritytech/parity-db.git?tag=v0.3.12#4e680e18a590ef7826b6d11229bb98448c5ae477" - -[[patch.unused]] -name = "syn" -version = "1.0.96" -source = "git+https://github.com/dtolnay/syn.git?tag=1.0.96#cb8760bcdcc00e9969a7f2e04816ea9bad6b8252" diff --git a/Cargo.toml b/Cargo.toml index 1e8729bc4..093e47f86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,9 +37,7 @@ nomad-base = { git="https://github.com/maticnetwork/avail-core", version = "0.1. nomad-core = { git="https://github.com/maticnetwork/avail-core", version = "0.1.2", tag = "da-primitives/v0.4.2" } # Other stuff -syn = { git = "https://github.com/dtolnay/syn.git", tag = "1.0.96" } primitive-types = { git = "https://github.com/paritytech/parity-common.git", tag = "rlp-v0.5.2" } -parity-db = { git = "https://github.com/paritytech/parity-db.git", tag = "v0.3.12" } parity-util-mem = { git = "https://github.com/paritytech/parity-common.git", tag = "rlp-v0.5.2" } uint = { git = "https://github.com/paritytech/parity-common.git", tag="rlp-v0.5.2" } rlp = { git = "https://github.com/paritytech/parity-common.git", tag="rlp-v0.5.2" } @@ -133,8 +131,6 @@ pallet-multisig = { git = "https://github.com/paritytech/substrate.git", branch pallet-child-bounties = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.33" } pallet-preimage = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.33" } pallet-nomination-pools = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.33" } -pallet-session-benchmarking = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.33" } -pallet-offences-benchmarking = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.33" } pallet-election-provider-support-benchmarking = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.33" } diff --git a/node/Cargo.toml b/node/Cargo.toml index d8a8bfb78..9a25971e6 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -107,11 +107,13 @@ substrate-state-trie-migration-rpc = "4.0.0-dev" frame-benchmarking = "4.0.0-dev" frame-benchmarking-cli = "4.0.0-dev" +# Try-runtime +try-runtime-cli = { version = "0.10.0-dev", optional = true } + [build-dependencies] substrate-build-script-utils = "3.0.0" clap = { version = "4.0.9", optional = true } clap_complete = { version = "4.0.2", optional = true } -try-runtime-cli = { version = "0.10.0-dev", optional = true } frame-benchmarking-cli = { version = "4.0.0-dev", optional = true } [dev-dependencies] @@ -123,7 +125,6 @@ default = ["cli"] cli = [ "clap", "clap_complete", - "try-runtime-cli", "frame-benchmarking-cli", ] runtime-benchmarks = [ diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index 240cd445b..cdc1f5d73 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -1,11 +1,11 @@ use da_control::AppKeyInfo; use da_primitives::currency::AVL; use da_runtime::{ - wasm_binary_unwrap, AccountId, AuthorityDiscoveryConfig, BabeConfig, Balance, BalancesConfig, - Block, CouncilConfig, DataAvailabilityConfig, DemocracyConfig, DesiredMembers, ElectionsConfig, - GenesisConfig, GrandpaConfig, ImOnlineConfig, IndicesConfig, MaxNominations, NomadHomeConfig, - NominationPoolsConfig, SessionConfig, SessionKeys, Signature, StakerStatus, StakingConfig, - SudoConfig, SystemConfig, TechnicalCommitteeConfig, UpdaterManagerConfig, + constants, wasm_binary_unwrap, AccountId, AuthorityDiscoveryConfig, BabeConfig, Balance, + BalancesConfig, Block, CouncilConfig, DataAvailabilityConfig, DemocracyConfig, DesiredMembers, + ElectionsConfig, GenesisConfig, GrandpaConfig, ImOnlineConfig, IndicesConfig, MaxNominations, + NomadHomeConfig, NominationPoolsConfig, SessionConfig, SessionKeys, Signature, StakerStatus, + StakingConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig, UpdaterManagerConfig, }; use frame_system::limits::BlockLength; use kate::config::{MAX_BLOCK_COLUMNS, MAX_BLOCK_ROWS}; @@ -339,9 +339,11 @@ pub fn testnet_genesis( }, da_bridge: Default::default(), nomination_pools: NominationPoolsConfig { - min_create_bond: 10 * AVL, - min_join_bond: 1 * AVL, - ..Default::default() + min_create_bond: constants::nomination_pools::MIN_CREATE_BOND, + min_join_bond: constants::nomination_pools::MIN_JOIN_BOND, + max_pools: Some(constants::nomination_pools::MAX_POOLS), + max_members_per_pool: Some(constants::nomination_pools::MAX_MEMBERS_PER_POOL), + max_members: Some(constants::nomination_pools::MAX_MEMBERS), }, } } @@ -501,9 +503,11 @@ fn genesis_builder( nomad_home: Default::default(), da_bridge: Default::default(), nomination_pools: NominationPoolsConfig { - min_create_bond: 10 * AVL, - min_join_bond: 1 * AVL, - ..Default::default() + min_create_bond: constants::nomination_pools::MIN_CREATE_BOND, + min_join_bond: constants::nomination_pools::MIN_JOIN_BOND, + max_pools: Some(constants::nomination_pools::MAX_POOLS), + max_members_per_pool: Some(constants::nomination_pools::MAX_MEMBERS_PER_POOL), + max_members: Some(constants::nomination_pools::MAX_MEMBERS), }, } } diff --git a/pallets/dactr/Cargo.toml b/pallets/dactr/Cargo.toml index 87a3d7b26..0833cbeb3 100644 --- a/pallets/dactr/Cargo.toml +++ b/pallets/dactr/Cargo.toml @@ -54,3 +54,4 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "frame-support/runtime-benchmarks", ] +try-runtime = ["frame-support/try-runtime"] diff --git a/pallets/executive/Cargo.toml b/pallets/executive/Cargo.toml index f6e8749c6..8006c29b9 100644 --- a/pallets/executive/Cargo.toml +++ b/pallets/executive/Cargo.toml @@ -21,6 +21,7 @@ codec = { package = "parity-scale-codec", version = "3", default-features = fals scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } frame-support = { version = "4.0.0-dev", default-features = false } frame-system = { version = "4.0.0-dev", default-features = false } +frame-try-runtime = { version = "0.10.0-dev", default-features = false, optional = true } sp-runtime = { version = "6.0.0", default-features = false } sp-tracing = { version = "5.0.0", default-features = false} sp-std = { version = "4.0.0", default-features = false } @@ -44,14 +45,14 @@ default = ["std"] with-tracing = ["sp-tracing/with-tracing"] std = [ "codec/std", - "scale-info/std", "frame-support/std", "frame-system/std", + "scale-info/std", "sp-core/std", + "sp-io/std", "sp-runtime/std", - "sp-tracing/std", "sp-std/std", - "sp-io/std", + "sp-tracing/std", "da-primitives/std", ] -try-runtime = ["frame-support/try-runtime"] +try-runtime = ["frame-support/try-runtime", "frame-try-runtime/try-runtime" ] diff --git a/pallets/executive/src/lib.rs b/pallets/executive/src/lib.rs index 0fe8dfd1a..b321fc732 100644 --- a/pallets/executive/src/lib.rs +++ b/pallets/executive/src/lib.rs @@ -841,13 +841,13 @@ mod tests { block_import_works_inner( new_test_ext_v0(1), array_bytes::hex_n_into_unchecked( - "29e2f2885158e4179d302f7f7ed0a64e75423a1fc2cf1d6fdc4219cd30023792", + "6d988b132b3dc0200c6d8102274428b9f58024fbb32c210b8b432302bc85be17", ), ); block_import_works_inner( new_test_ext(1), array_bytes::hex_n_into_unchecked( - "0c32c81e9258686fdb492888b7630e757096548842326e5d603138474ca2e49d", + "0b93b0592690a181d6e080c6cc73108793e0447c24ad82145c763b798d94edc7", ), ); } diff --git a/pallets/system/src/lib.rs b/pallets/system/src/lib.rs index 533623dca..0eafbf4bd 100644 --- a/pallets/system/src/lib.rs +++ b/pallets/system/src/lib.rs @@ -754,7 +754,7 @@ pub mod pallet { sp_io::storage::set(KATE_PUBLIC_PARAMS, &self.kc_public_params); >::put(&self.block_length); - StorageVersion::new(2).put::>(); + StorageVersion::new(1).put::>(); } } } diff --git a/pallets/system/src/migrations/mod.rs b/pallets/system/src/migrations/mod.rs index bd592b814..43e417ebb 100644 --- a/pallets/system/src/migrations/mod.rs +++ b/pallets/system/src/migrations/mod.rs @@ -25,6 +25,7 @@ use frame_support::{ use sp_std::prelude::*; use crate::{Config, Pallet}; +pub mod v1; /// Type used to encode the number of references an account has. type RefCount = u32; diff --git a/pallets/system/src/migrations/v1.rs b/pallets/system/src/migrations/v1.rs index 5ba52e894..c7a6483be 100644 --- a/pallets/system/src/migrations/v1.rs +++ b/pallets/system/src/migrations/v1.rs @@ -1,101 +1,27 @@ use codec::Decode; -use frame_support::traits::{Get, StorageVersion}; +use frame_support::weights::Weight; +use sp_core::Get; -use crate::{Account, AccountInfo, Config, Pallet, RefCount, UpgradedToTripleRefCount, Weight}; +/// # V1 Migrations +/// - `BlockLength` migration to `DynamicBlockLength`. +/// - `AllExtrinsicLen` from single `u32` into `ExtrinsicLen` type. +use crate::{limits::BlockLength, AllExtrinsicsLen, Config, DynamicBlockLength, ExtrinsicLen}; -pub fn migrate() -> Weight { - // Original pallet migrations - let mut weight = if !UpgradedToTripleRefCount::::get() { - UpgradedToTripleRefCount::::put(true); - migrate_to_triple_ref_count::() - } else { - 0 - }; - - // Polygon versions. - let curr_version = StorageVersion::get::>(); - if curr_version < 1 { - weight = weight.saturating_add(v1::migrate::()); - } - - // Update the pallet version. - StorageVersion::new(1).put::>(); - weight.saturating_add(T::DbWeight::get().reads_writes(0, 1)) -} +pub const BLOCK_LENGTH: &[u8] = b":block_length:"; -#[allow(dead_code)] -/// Migrate from unique `u8` reference counting to triple `u32` reference counting. -pub fn migrate_all() -> frame_support::weights::Weight { - Account::::translate::<(T::Index, u8, T::AccountData), _>(|_key, (nonce, rc, data)| { - Some(AccountInfo { - nonce, - consumers: rc as RefCount, - providers: 1, - sufficients: 0, - data, - }) +pub fn migrate() -> Weight { + let mut weight = Weight::zero(); + + // 1. Raw storage ":block_length:" into `System::DynamicBlockLength`. + let encoded_block_len = sp_io::storage::get(BLOCK_LENGTH).unwrap_or_default(); + let block_len = BlockLength::decode(&mut &encoded_block_len[..]).unwrap_or_default(); + DynamicBlockLength::::put(block_len); + weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1)); + + // 2. Storage `AllExtrinsicsLen` from `u32` to `ExtrinsicLen`. + // As it is called before `on_initialize`, it should be 0. + let _ = >::translate(|maybe_len: Option| -> Option { + maybe_len.map(|_| ExtrinsicLen::default()) }); - 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() -> frame_support::weights::Weight { - Account::::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() -> frame_support::weights::Weight { - Account::::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 -} - -/// V1 Migrations -/// - -mod v1 { - use super::*; - use crate::{limits::BlockLength, AllExtrinsicsLen, DynamicBlockLength, ExtrinsicLen}; - - pub const BLOCK_LENGTH: &[u8] = b":block_length:"; - - pub fn migrate() -> Weight { - let mut weight: Weight = 0; - - // 1. Raw storage ":block_length:" into `System::DynamicBlockLength`. - let encoded_block_len = sp_io::storage::get(BLOCK_LENGTH).unwrap_or_default(); - let block_len = BlockLength::decode(&mut &encoded_block_len[..]).unwrap_or_default(); - DynamicBlockLength::::put(block_len); - weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1)); - - // 2. Storage `AllExtrinsicsLen` from `u32` to `ExtrinsicLen`. - // As it is called before `on_initialize`, it should be 0. - let _ = - >::translate(|maybe_len: Option| -> Option { - maybe_len.map(|_| ExtrinsicLen::default()) - }); - weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1)); - - weight - } + weight.saturating_add(T::DbWeight::get().reads_writes(1, 1)) } diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 320f1af86..5005e595b 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -204,5 +204,36 @@ try-runtime = [ "frame-executive/try-runtime", "frame-system/try-runtime", "frame-support/try-runtime", - + "da-control/try-runtime", + "nomad-home/try-runtime", + "da-bridge/try-runtime", + "nomad-updater-manager/try-runtime", + "pallet-utility/try-runtime", + "pallet-babe/try-runtime", + "pallet-timestamp/try-runtime", + "pallet-authorship/try-runtime", + "pallet-indices/try-runtime", + "pallet-balances/try-runtime", + "pallet-election-provider-multi-phase/try-runtime", + "pallet-staking/try-runtime", + "pallet-session/try-runtime", + "pallet-democracy/try-runtime", + "pallet-collective/try-runtime", + "pallet-elections-phragmen/try-runtime", + "pallet-membership/try-runtime", + "pallet-grandpa/try-runtime", + "pallet-treasury/try-runtime", + "pallet-sudo/try-runtime", + "pallet-im-online/try-runtime", + "pallet-authority-discovery/try-runtime", + "pallet-offences/try-runtime", + "pallet-scheduler/try-runtime", + "pallet-bounties/try-runtime", + "pallet-mmr/try-runtime", + "pallet-preimage/try-runtime", + "pallet-multisig/try-runtime", + "pallet-bags-list/try-runtime", + "pallet-nomination-pools/try-runtime", + "pallet-transaction-payment/try-runtime", + "pallet-tips/try-runtime", ] diff --git a/runtime/src/constants.rs b/runtime/src/constants.rs index 8b2db692a..471fbd296 100644 --- a/runtime/src/constants.rs +++ b/runtime/src/constants.rs @@ -17,9 +17,11 @@ //! A set of constant values used in substrate runtime. +use da_primitives::currency::Balance; + /// Money matters. pub mod currency { - use da_primitives::currency::Balance; + use super::Balance; pub const MILLICENTS: Balance = 1_000_000_000; pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent. @@ -72,6 +74,18 @@ pub mod time { pub const DAYS: BlockNumber = HOURS * 24; } +pub mod nomination_pools { + use da_primitives::currency::AVL; + + use super::Balance; + + pub const MIN_CREATE_BOND: Balance = 10 * AVL; + pub const MIN_JOIN_BOND: Balance = 1 * AVL; + pub const MAX_POOLS: u32 = 16; + pub const MAX_MEMBERS_PER_POOL: u32 = 100; + pub const MAX_MEMBERS: u32 = MAX_POOLS * MAX_MEMBERS_PER_POOL; +} + /// The BABE epoch configuration at genesis. pub const BABE_GENESIS_EPOCH_CONFIG: sp_consensus_babe::BabeEpochConfiguration = sp_consensus_babe::BabeEpochConfiguration { diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 703177b65..6bcc969d2 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -105,6 +105,8 @@ pub mod constants; use constants::{currency::*, time::*, BABE_GENESIS_EPOCH_CONFIG}; use sp_runtime::generic::Era; +mod migration; + /// An index to a block. pub type BlockNumber = u32; @@ -1326,7 +1328,7 @@ pub type Executive = frame_executive::Executive< // All migrations executed on runtime upgrade as a nested tuple of types implementing // `OnRuntimeUpgrade`. -type Migrations = (); +type Migrations = (migration::Migration,); /// MMR helper types. mod mmr { @@ -1437,7 +1439,6 @@ impl_runtime_apis! { _set_id: fg_primitives::SetId, authority_id: GrandpaId, ) -> Option { - // with no values). use codec::Encode; Historical::prove((fg_primitives::KEY_TYPE, authority_id)) @@ -1709,6 +1710,66 @@ mod tests { use super::*; + /// This test was used to detect any missing support of `TryState` needed for `try-runtime` + /// feature. + #[cfg(feature = "try-runtime")] + #[allow(dead_code)] + fn check_try_runtime_support_on_pallets() -> Result<(), &'static str> { + use frame_support::traits::{TryState, TryStateSelect::All}; + use sp_runtime::traits::Zero; + + let block = Zero::zero(); + + as TryState>::try_state(block, All)?; + + as TryState>::try_state(block, All)?; + as TryState>::try_state(block, All)?; + as TryState>::try_state(block, All)?; + as TryState>::try_state(block, All)?; + as TryState>::try_state(block, All)?; + as TryState>::try_state(block, All)?; + as TryState>::try_state( + block, All, + )?; + as TryState>::try_state(block, All)?; + as TryState>::try_state(block, All)?; + as TryState>::try_state(block, All)?; + as TryState>::try_state(block, All)?; + as TryState>::try_state(block, All)?; + as TryState>::try_state(block, All)?; + as TryState>::try_state( + block, All, + )?; + as TryState< + BlockNumber, + >>::try_state(block, All)?; + as TryState>::try_state(block, All)?; + as TryState>::try_state(block, All)?; + as TryState>::try_state(block, All)?; + as TryState>::try_state(block, All)?; + as TryState>::try_state( + block, All, + )?; + as TryState>::try_state(block, All)?; + as TryState>::try_state( + block, All, + )?; + as TryState>::try_state(block, All)?; + as TryState>::try_state(block, All)?; + as TryState>::try_state(block, All)?; + as TryState>::try_state(block, All)?; + as TryState>::try_state(block, All)?; + as TryState>::try_state(block, All)?; + as TryState>::try_state(block, All)?; + as TryState>::try_state(block, All)?; + as TryState>::try_state(block, All)?; + as TryState>::try_state(block, All)?; + as TryState< + BlockNumber, + >>::try_state(block, All)?; + as TryState>::try_state(block, All) + } + #[test] fn check_whitelist() { let whitelist: HashSet = AllPalletsWithSystem::whitelisted_storage_keys() diff --git a/runtime/src/migration.rs b/runtime/src/migration.rs new file mode 100644 index 000000000..c062bdac0 --- /dev/null +++ b/runtime/src/migration.rs @@ -0,0 +1,110 @@ +// This file is part of Data-Availability. + +// Copyright (C) 2022 +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use frame_support::{pallet_prelude::*, traits::OnRuntimeUpgrade}; +use log; +use pallet_nomination_pools::{ + MaxPoolMembers, MaxPoolMembersPerPool, MaxPools, MinCreateBond, MinJoinBond, Pallet, +}; +#[cfg(feature = "try-runtime")] +use sp_std::vec::Vec; + +use crate::Weight; + +/// Implements `OnRuntimeUpgrade` trait. +pub struct Migration {} + +impl OnRuntimeUpgrade for Migration { + fn on_runtime_upgrade() -> Weight { nomination_pools::migrate() } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, &'static str> { nomination_pools::pre_upgrade() } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(state: Vec) -> Result<(), &'static str> { + nomination_pools::post_upgrade(state) + } +} + +mod nomination_pools { + use super::*; + use crate::Runtime; + + /// The current storage version. + const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); + + /// Wrapper for all migrations of this pallet. + pub(crate) fn migrate() -> Weight { + let onchain_version = Pallet::::on_chain_storage_version(); + let mut weight: Weight = Weight::zero(); + + if onchain_version < 1 { + weight = weight.saturating_add(v0_to_v1::migrate()); + } + + STORAGE_VERSION.put::>(); + weight.saturating_add(::DbWeight::get().writes(1)) + } + + #[cfg(feature = "try-runtime")] + pub(crate) fn pre_upgrade() -> Result, &'static str> { Ok(vec![]) } + + #[cfg(feature = "try-runtime")] + pub(crate) fn post_upgrade(_state: Vec) -> Result<(), &'static str> { + use crate::constants::nomination_pools::*; + + ensure!( + MinJoinBond::::get() == MIN_JOIN_BOND, + "Expected `nomination_pools::MinJoinBond == 1 * AVL`" + ); + ensure!( + MinCreateBond::::get() == MIN_CREATE_BOND, + "Expected `nomination_pools::MinCreateBond == 10 * AVL`" + ); + ensure!( + MaxPools::::get() == Some(MAX_POOLS), + "Expected `nomination_pools::MaxPools == 16`" + ); + ensure!( + MaxPoolMembersPerPool::::get() == Some(MAX_MEMBERS_PER_POOL), + "Expected `nomination_pools::MaxPoolMembersPerPool == 100`" + ); + ensure!( + MaxPoolMembers::::get() == Some(MAX_MEMBERS), + "Expected `nomination_pools::MaxMembers == 1600`" + ); + + Ok(()) + } + + mod v0_to_v1 { + use super::*; + use crate::constants::nomination_pools::*; + + /// It sets `min_create_bond = 10 AVL` and + pub(crate) fn migrate() -> Weight { + log::info!(target: "runtime::migration", "Nomination pools migration from V0 to V1"); + MinJoinBond::::put(MIN_JOIN_BOND); + MinCreateBond::::put(MIN_CREATE_BOND); + MaxPools::::put(MAX_POOLS); + MaxPoolMembersPerPool::::put(MAX_MEMBERS_PER_POOL); + MaxPoolMembers::::put(MAX_MEMBERS); + + ::DbWeight::get().writes(5u64) + } + } +}