From d21752616ec6fd930b9f29b8f68d8e1c733c46a2 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 20 Feb 2020 17:15:21 +0100 Subject: [PATCH 01/17] Assign unique storage names to pallets. --- bin/node-template/pallets/template/src/lib.rs | 3 +++ frame/elections/src/lib.rs | 2 +- frame/evm/src/lib.rs | 2 +- frame/example-offchain-worker/src/lib.rs | 2 +- frame/example/src/lib.rs | 4 ++++ frame/finality-tracker/src/lib.rs | 2 +- frame/identity/src/lib.rs | 2 +- frame/nicks/src/lib.rs | 2 +- frame/support/src/lib.rs | 2 +- frame/support/test/tests/genesisconfig.rs | 2 +- frame/transaction-payment/src/lib.rs | 2 +- 11 files changed, 16 insertions(+), 9 deletions(-) diff --git a/bin/node-template/pallets/template/src/lib.rs b/bin/node-template/pallets/template/src/lib.rs index 34e055bf546b0..892778adeb46b 100644 --- a/bin/node-template/pallets/template/src/lib.rs +++ b/bin/node-template/pallets/template/src/lib.rs @@ -28,6 +28,9 @@ pub trait Trait: system::Trait { // This pallet's storage items. decl_storage! { + // It is important to update your storage name so that your pallet's + // storage items are isolated from other pallets. + // ---------------------------------vvvvvvvvvvvvvv trait Store for Module as TemplateModule { // Just a dummy storage item. // Here we are declaring a StorageValue, `Something` as a Option diff --git a/frame/elections/src/lib.rs b/frame/elections/src/lib.rs index 95d1858476287..d93d18fe23f64 100644 --- a/frame/elections/src/lib.rs +++ b/frame/elections/src/lib.rs @@ -209,7 +209,7 @@ pub trait Trait: frame_system::Trait { } decl_storage! { - trait Store for Module as Council { + trait Store for Module as Elections { // ---- parameters /// How long to give each top candidate to present themselves after the vote ends. diff --git a/frame/evm/src/lib.rs b/frame/evm/src/lib.rs index abf20114f2c6a..df0ddaafbbe16 100644 --- a/frame/evm/src/lib.rs +++ b/frame/evm/src/lib.rs @@ -131,7 +131,7 @@ pub trait Trait: frame_system::Trait + pallet_timestamp::Trait { } decl_storage! { - trait Store for Module as Example { + trait Store for Module as EVM { Accounts get(fn accounts) config(): map hasher(blake2_256) H160 => Account; AccountCodes: map hasher(blake2_256) H160 => Vec; AccountStorages: double_map hasher(blake2_256) H160, hasher(blake2_256) H256 => H256; diff --git a/frame/example-offchain-worker/src/lib.rs b/frame/example-offchain-worker/src/lib.rs index 1c72a8be68653..d4905d26b00d0 100644 --- a/frame/example-offchain-worker/src/lib.rs +++ b/frame/example-offchain-worker/src/lib.rs @@ -106,7 +106,7 @@ pub trait Trait: frame_system::Trait { } decl_storage! { - trait Store for Module as Example { + trait Store for Module as ExampleOffchainWorker { /// A vector of recently submitted prices. /// /// This is used to calculate average price, should have bounded size. diff --git a/frame/example/src/lib.rs b/frame/example/src/lib.rs index 39f0d25d3232a..553614ce218da 100644 --- a/frame/example/src/lib.rs +++ b/frame/example/src/lib.rs @@ -324,6 +324,10 @@ decl_storage! { // A macro for the Storage trait, and its implementation, for this pallet. // This allows for type-safe usage of the Substrate storage database, so you can // keep things around between blocks. + // + // It is important to update your storage name so that your pallet's + // storage items are isolated from other pallets. + // ---------------------------------vvvvvvv trait Store for Module as Example { // Any storage declarations of the form: // `pub? Name get(fn getter_name)? [config()|config(myname)] [build(|_| {...})] : (= )?;` diff --git a/frame/finality-tracker/src/lib.rs b/frame/finality-tracker/src/lib.rs index ef6e0d9a4bbbe..f254d50fc849d 100644 --- a/frame/finality-tracker/src/lib.rs +++ b/frame/finality-tracker/src/lib.rs @@ -40,7 +40,7 @@ pub trait Trait: SystemTrait { } decl_storage! { - trait Store for Module as Timestamp { + trait Store for Module as FinalityTracker { /// Recent hints. RecentHints get(fn recent_hints) build(|_| vec![T::BlockNumber::zero()]): Vec; /// Ordered recent hints. diff --git a/frame/identity/src/lib.rs b/frame/identity/src/lib.rs index 895efa1c819cd..04488b1f5c243 100644 --- a/frame/identity/src/lib.rs +++ b/frame/identity/src/lib.rs @@ -381,7 +381,7 @@ pub struct RegistrarInfo< } decl_storage! { - trait Store for Module as Sudo { + trait Store for Module as Identity { /// Information that is pertinent to identify the entity behind an account. pub IdentityOf get(fn identity): map hasher(blake2_256) T::AccountId => Option>>; diff --git a/frame/nicks/src/lib.rs b/frame/nicks/src/lib.rs index 2b2d59014d8b2..cdb7496377c92 100644 --- a/frame/nicks/src/lib.rs +++ b/frame/nicks/src/lib.rs @@ -76,7 +76,7 @@ pub trait Trait: frame_system::Trait { } decl_storage! { - trait Store for Module as Sudo { + trait Store for Module as Nicks { /// The lookup table for names. NameOf: map hasher(blake2_256) T::AccountId => Option<(Vec, BalanceOf)>; } diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index 531f2557140e1..005a92ff616a6 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -251,7 +251,7 @@ mod tests { use self::module::Module; decl_storage! { - trait Store for Module as Example { + trait Store for Module as Test { pub Data get(fn data) build(|_| vec![(15u32, 42u64)]): linked_map hasher(twox_64_concat) u32 => u64; pub OptionLinkedMap: linked_map hasher(blake2_256) u32 => Option; diff --git a/frame/support/test/tests/genesisconfig.rs b/frame/support/test/tests/genesisconfig.rs index 12af18aac90fa..5a5ab9d1dbcdd 100644 --- a/frame/support/test/tests/genesisconfig.rs +++ b/frame/support/test/tests/genesisconfig.rs @@ -24,7 +24,7 @@ frame_support::decl_module! { } frame_support::decl_storage! { - trait Store for Module as Example { + trait Store for Module as Test { pub AppendableDM config(t): double_map hasher(blake2_256) u32, hasher(blake2_256) T::BlockNumber => Vec; } } diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index 0d9cfc0b77683..e625f7f261424 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -75,7 +75,7 @@ pub trait Trait: frame_system::Trait { } decl_storage! { - trait Store for Module as Balances { + trait Store for Module as TransactionPayment { pub NextFeeMultiplier get(fn next_fee_multiplier): Multiplier = Multiplier::from_parts(0); } } From e6cb2512757cb28245877614625b987943900521 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 20 Feb 2020 17:23:18 +0100 Subject: [PATCH 02/17] Bump spec --- bin/node/runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 617ca2257a341..674f1fbf49b82 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -81,7 +81,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 224, + spec_version: 225, impl_version: 0, apis: RUNTIME_API_VERSIONS, }; From e4da049ea6e1f06dd15d4fc21a50e65452f71482 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 20 Feb 2020 23:47:16 +0100 Subject: [PATCH 03/17] Upgrade logic for finality tracker (untested) --- frame/finality-tracker/src/lib.rs | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/frame/finality-tracker/src/lib.rs b/frame/finality-tracker/src/lib.rs index f254d50fc849d..698d360db795f 100644 --- a/frame/finality-tracker/src/lib.rs +++ b/frame/finality-tracker/src/lib.rs @@ -53,6 +53,11 @@ decl_storage! { // when initialized through config this is set in the beginning. Initialized get(fn initialized) build(|_| false): bool; + + /// True if network has been upgraded to this version. + /// + /// True for new networks. + IsUpgraded build(|_| true): bool; } } @@ -89,6 +94,36 @@ decl_module! { fn on_finalize() { Self::update_hint(::Update::take()) } + + fn on_initialize() { + if !IsUpgraded::get() { + IsUpgraded::put(true); + Self::do_upgrade(); + } + } + } +} + +// Migration code to update storage name +use frame_support::storage::migration::{put_storage_value, take_storage_value}; +impl Module { + pub fn do_upgrade() { + sp_runtime::print("Migrating Finality Tracker."); + + let recent_hints = take_storage_value::>(b"Timestamp", b"RecentHints", &[]).unwrap_or_default(); + put_storage_value(b"FinalityTracker", b"RecentHints", &[], recent_hints); + + let ordered_hints = take_storage_value::>(b"Timestamp", b"OrderedHints", &[]).unwrap_or_default(); + put_storage_value(b"FinalityTracker", b"OrderedHints", &[], ordered_hints); + + let median = take_storage_value::(b"Timestamp", b"Median", &[]).unwrap_or_default(); + put_storage_value(b"FinalityTracker", b"Median", &[], median); + + let update = take_storage_value::>(b"Timestamp", b"Update", &[]).unwrap_or_default(); + put_storage_value(b"FinalityTracker", b"Update", &[], update); + + let initialized = take_storage_value::(b"Timestamp", b"Initialized", &[]).unwrap_or_default(); + put_storage_value(b"FinalityTracker", b"Initialized", &[], initialized); } } From 48da9c8cf26e9050e85867bf297ff1479b10de97 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Fri, 21 Feb 2020 00:01:12 +0100 Subject: [PATCH 04/17] Logic for migrating Identity (untested) --- frame/identity/src/lib.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/frame/identity/src/lib.rs b/frame/identity/src/lib.rs index 04488b1f5c243..ce7a5950cb462 100644 --- a/frame/identity/src/lib.rs +++ b/frame/identity/src/lib.rs @@ -402,6 +402,11 @@ decl_storage! { /// /// The index into this can be cast to `RegistrarIndex` to get a valid value. pub Registrars get(fn registrars): Vec, T::AccountId>>>; + + /// True if network has been upgraded to this version. + /// + /// True for new networks. + IsUpgraded build(|_| true): bool; } } @@ -872,6 +877,36 @@ decl_module! { Self::deposit_event(RawEvent::IdentityKilled(target, deposit)); } + + fn on_initialize() { + if !IsUpgraded::get() { + IsUpgraded::put(true); + Self::do_upgrade(); + } + } + } +} + +// Migration code to update storage name +use frame_support::storage::migration::{put_storage_value, take_storage_value, StorageIterator}; +impl Module { + pub fn do_upgrade() { + sp_runtime::print("Migrating Identity."); + + for (hash, identity_of) in StorageIterator::>>>::new(b"Sudo", b"IdentityOf").drain() { + put_storage_value(b"Identity", b"IdentityOf", &hash, identity_of); + } + + for (hash, super_of) in StorageIterator::>::new(b"Sudo", b"SuperOf").drain() { + put_storage_value(b"Identity", b"SuperOf", &hash, super_of); + } + + for (hash, subs_of) in StorageIterator::>::new(b"Sudo", b"SubsOf").drain() { + put_storage_value(b"Identity", b"SubsOf", &hash, subs_of); + } + + let recent_hints = take_storage_value::, T::AccountId>>>>(b"Sudo", b"Registrars", &[]).unwrap_or_default(); + put_storage_value(b"Identity", b"Registrars", &[], recent_hints); } } From a6033e92150e893a909c0881ac367fbf7b4bb9d8 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Fri, 21 Feb 2020 00:15:39 +0100 Subject: [PATCH 05/17] Logic for migrating transaction-payment --- frame/transaction-payment/src/lib.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index e625f7f261424..e216a2b7178d0 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -77,6 +77,11 @@ pub trait Trait: frame_system::Trait { decl_storage! { trait Store for Module as TransactionPayment { pub NextFeeMultiplier get(fn next_fee_multiplier): Multiplier = Multiplier::from_parts(0); + + /// True if network has been upgraded to this version. + /// + /// True for new networks. + IsUpgraded build(|_| true): bool; } } @@ -93,6 +98,24 @@ decl_module! { *fm = T::FeeMultiplierUpdate::convert(*fm) }); } + + fn on_initialize() { + if !IsUpgraded::get() { + IsUpgraded::put(true); + Self::do_upgrade(); + } + } + } +} + +// Migration code to update storage name +use frame_support::storage::migration::{put_storage_value, take_storage_value}; +impl Module { + pub fn do_upgrade() { + sp_runtime::print("Migrating Transaction Payment."); + + let next_fee_multiplier = take_storage_value::(b"Balances", b"NextFeeMultiplier", &[]).unwrap_or_default(); + put_storage_value(b"TransactionPayment", b"NextFeeMultiplier", &[], next_fee_multiplier); } } From 24225b748148b656f3748dc522f2b9047b88df2e Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Fri, 21 Feb 2020 00:25:34 +0100 Subject: [PATCH 06/17] Fix tests --- frame/support/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index 005a92ff616a6..00b229750db47 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -488,7 +488,7 @@ mod tests { } const EXPECTED_METADATA: StorageMetadata = StorageMetadata { - prefix: DecodeDifferent::Encode("Example"), + prefix: DecodeDifferent::Encode("Test"), entries: DecodeDifferent::Encode( &[ StorageEntryMetadata { From cec417293cdefddb43d1d0f724cafb6bb6b5b8d3 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Fri, 21 Feb 2020 00:37:40 +0100 Subject: [PATCH 07/17] Fix `decl_storage` build --- Cargo.lock | 1 + frame/transaction-payment/Cargo.toml | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 97e56ffae21fd..0603e1e8d3b3c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4165,6 +4165,7 @@ dependencies = [ "pallet-balances 2.0.0", "pallet-transaction-payment-rpc-runtime-api 2.0.0", "parity-scale-codec 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core 2.0.0", "sp-io 2.0.0", "sp-runtime 2.0.0", diff --git a/frame/transaction-payment/Cargo.toml b/frame/transaction-payment/Cargo.toml index ac3dbb2c2b16a..144d16a23f10b 100644 --- a/frame/transaction-payment/Cargo.toml +++ b/frame/transaction-payment/Cargo.toml @@ -6,6 +6,7 @@ edition = "2018" license = "GPL-3.0" [dependencies] +serde = { version = "1.0.101", optional = true } codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } sp-std = { version = "2.0.0", default-features = false, path = "../../primitives/std" } sp-runtime = { version = "2.0.0", default-features = false, path = "../../primitives/runtime" } @@ -21,6 +22,7 @@ pallet-balances = { version = "2.0.0", path = "../balances" } [features] default = ["std"] std = [ + "serde", "codec/std", "sp-std/std", "sp-runtime/std", From 774bc9ed2867c46c72505d15d4a7ca6ccc0747d9 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Fri, 28 Feb 2020 02:30:52 +0200 Subject: [PATCH 08/17] Contract -> Contracts --- frame/contracts/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/contracts/src/lib.rs b/frame/contracts/src/lib.rs index 42cbaa3a7c2af..613b00a68b061 100644 --- a/frame/contracts/src/lib.rs +++ b/frame/contracts/src/lib.rs @@ -923,7 +923,7 @@ decl_event! { } decl_storage! { - trait Store for Module as Contract { + trait Store for Module as Contracts { /// Gas spent so far in this block. GasSpent get(fn gas_spent): Gas; /// Current cost schedule for contracts. From 92c6217b1b472243302ce94b10b446e095acc384 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Fri, 28 Feb 2020 02:33:26 +0200 Subject: [PATCH 09/17] Update Cargo.lock --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.lock b/Cargo.lock index 67b3cf7f47ff7..847f3873adbf5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4431,6 +4431,7 @@ dependencies = [ "pallet-balances", "pallet-transaction-payment-rpc-runtime-api", "parity-scale-codec", + "serde", "sp-core", "sp-io", "sp-runtime", From 58f671e645f9301d1ab733dbff3b546c06b7b608 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 5 Mar 2020 16:53:38 +0100 Subject: [PATCH 10/17] bump spec --- bin/node/runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index ae0de952e49fb..daa10596fec18 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -83,7 +83,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // and set impl_version to 0. If only runtime // implementation changes and behavior does not, then leave spec_version as // is and increment impl_version. - spec_version: 230, + spec_version: 231, impl_version: 0, apis: RUNTIME_API_VERSIONS, }; From 916f0a607eadfd27dfe67ec8b04f347a7ba30aab Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 5 Mar 2020 17:34:09 +0100 Subject: [PATCH 11/17] update migration --- frame/balances/src/migration.rs | 20 +++++++- frame/finality-tracker/src/lib.rs | 37 ++------------- frame/finality-tracker/src/migration.rs | 54 ++++++++++++++++++++++ frame/identity/src/lib.rs | 36 ++------------- frame/identity/src/migration.rs | 50 ++++++++++++++++++++ frame/transaction-payment/src/lib.rs | 25 ++-------- frame/transaction-payment/src/migration.rs | 38 +++++++++++++++ 7 files changed, 171 insertions(+), 89 deletions(-) create mode 100644 frame/finality-tracker/src/migration.rs create mode 100644 frame/identity/src/migration.rs create mode 100644 frame/transaction-payment/src/migration.rs diff --git a/frame/balances/src/migration.rs b/frame/balances/src/migration.rs index 16c764d59f1aa..0e98d5656e7b5 100644 --- a/frame/balances/src/migration.rs +++ b/frame/balances/src/migration.rs @@ -1,3 +1,21 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! Migration code to update storage. + use super::*; pub fn on_runtime_upgrade, I: Instance>() { @@ -83,6 +101,4 @@ fn upgrade_v1_to_v2, I: Instance>() { } take_storage_value::(b"Balances", b"IsUpgraded", &[]); - - StorageVersion::::put(Releases::V2_0_0); } diff --git a/frame/finality-tracker/src/lib.rs b/frame/finality-tracker/src/lib.rs index 31c7bedeefda2..3b6de38de8e79 100644 --- a/frame/finality-tracker/src/lib.rs +++ b/frame/finality-tracker/src/lib.rs @@ -26,6 +26,8 @@ use frame_support::traits::Get; use frame_system::{ensure_none, Trait as SystemTrait}; use sp_finality_tracker::{INHERENT_IDENTIFIER, FinalizedInherentData}; +mod migration; + pub const DEFAULT_WINDOW_SIZE: u32 = 101; pub const DEFAULT_REPORT_LATENCY: u32 = 1000; @@ -53,11 +55,6 @@ decl_storage! { // when initialized through config this is set in the beginning. Initialized get(fn initialized) build(|_| false): bool; - - /// True if network has been upgraded to this version. - /// - /// True for new networks. - IsUpgraded build(|_| true): bool; } } @@ -95,38 +92,12 @@ decl_module! { Self::update_hint(::Update::take()) } - fn on_initialize() { - if !IsUpgraded::get() { - IsUpgraded::put(true); - Self::do_upgrade(); - } + fn on_runtime_upgrade() { + migration::on_runtime_upgrade::() } } } -// Migration code to update storage name -use frame_support::storage::migration::{put_storage_value, take_storage_value}; -impl Module { - pub fn do_upgrade() { - sp_runtime::print("Migrating Finality Tracker."); - - let recent_hints = take_storage_value::>(b"Timestamp", b"RecentHints", &[]).unwrap_or_default(); - put_storage_value(b"FinalityTracker", b"RecentHints", &[], recent_hints); - - let ordered_hints = take_storage_value::>(b"Timestamp", b"OrderedHints", &[]).unwrap_or_default(); - put_storage_value(b"FinalityTracker", b"OrderedHints", &[], ordered_hints); - - let median = take_storage_value::(b"Timestamp", b"Median", &[]).unwrap_or_default(); - put_storage_value(b"FinalityTracker", b"Median", &[], median); - - let update = take_storage_value::>(b"Timestamp", b"Update", &[]).unwrap_or_default(); - put_storage_value(b"FinalityTracker", b"Update", &[], update); - - let initialized = take_storage_value::(b"Timestamp", b"Initialized", &[]).unwrap_or_default(); - put_storage_value(b"FinalityTracker", b"Initialized", &[], initialized); - } -} - impl Module { fn update_hint(hint: Option) { if !Self::initialized() { diff --git a/frame/finality-tracker/src/migration.rs b/frame/finality-tracker/src/migration.rs new file mode 100644 index 0000000000000..1fea7855dba08 --- /dev/null +++ b/frame/finality-tracker/src/migration.rs @@ -0,0 +1,54 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +// Migration code to update storage. + +use super::*; +use frame_support::storage::migration::{put_storage_value, take_storage_value}; + +pub fn on_runtime_upgrade() { + change_name_timestamp_to_finality_tracker::() +} + +// Change the storage name used by this pallet from `Timestamp` to `FinalityTracker`. +// +// Since the format of the storage items themselves have not changed, we do not +// need to keep track of a storage version. If the runtime does not need to be +// upgraded, nothing here will happen anyway. + +fn change_name_timestamp_to_finality_tracker() { + sp_runtime::print("Migrating Finality Tracker."); + + if let Some(recent_hints) = take_storage_value::>(b"Timestamp", b"RecentHints", &[]) { + put_storage_value(b"FinalityTracker", b"RecentHints", &[], recent_hints); + } + + if let Some(ordered_hints) = take_storage_value::>(b"Timestamp", b"OrderedHints", &[]) { + put_storage_value(b"FinalityTracker", b"OrderedHints", &[], ordered_hints); + } + + if let Some(median) = take_storage_value::(b"Timestamp", b"Median", &[]) { + put_storage_value(b"FinalityTracker", b"Median", &[], median); + } + + if let Some(update) = take_storage_value::>(b"Timestamp", b"Update", &[]) { + put_storage_value(b"FinalityTracker", b"Update", &[], update); + } + + if let Some(initialized) = take_storage_value::(b"Timestamp", b"Initialized", &[]) { + put_storage_value(b"FinalityTracker", b"Initialized", &[], initialized); + } +} diff --git a/frame/identity/src/lib.rs b/frame/identity/src/lib.rs index 1e7c406fa370d..e993a0bebcdbd 100644 --- a/frame/identity/src/lib.rs +++ b/frame/identity/src/lib.rs @@ -80,6 +80,7 @@ use frame_system::{self as system, ensure_signed, ensure_root}; #[cfg(feature = "runtime-benchmarks")] pub mod benchmarking; +mod migration; type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; type NegativeImbalanceOf = <::Currency as Currency<::AccountId>>::NegativeImbalance; @@ -403,11 +404,6 @@ decl_storage! { /// /// The index into this can be cast to `RegistrarIndex` to get a valid value. pub Registrars get(fn registrars): Vec, T::AccountId>>>; - - /// True if network has been upgraded to this version. - /// - /// True for new networks. - IsUpgraded build(|_| true): bool; } } @@ -879,35 +875,9 @@ decl_module! { Self::deposit_event(RawEvent::IdentityKilled(target, deposit)); } - fn on_initialize() { - if !IsUpgraded::get() { - IsUpgraded::put(true); - Self::do_upgrade(); - } - } - } -} - -// Migration code to update storage name -use frame_support::storage::migration::{put_storage_value, take_storage_value, StorageIterator}; -impl Module { - pub fn do_upgrade() { - sp_runtime::print("Migrating Identity."); - - for (hash, identity_of) in StorageIterator::>>>::new(b"Sudo", b"IdentityOf").drain() { - put_storage_value(b"Identity", b"IdentityOf", &hash, identity_of); - } - - for (hash, super_of) in StorageIterator::>::new(b"Sudo", b"SuperOf").drain() { - put_storage_value(b"Identity", b"SuperOf", &hash, super_of); + fn on_runtime_upgrade() { + migration::on_runtime_upgrade::() } - - for (hash, subs_of) in StorageIterator::>::new(b"Sudo", b"SubsOf").drain() { - put_storage_value(b"Identity", b"SubsOf", &hash, subs_of); - } - - let recent_hints = take_storage_value::, T::AccountId>>>>(b"Sudo", b"Registrars", &[]).unwrap_or_default(); - put_storage_value(b"Identity", b"Registrars", &[], recent_hints); } } diff --git a/frame/identity/src/migration.rs b/frame/identity/src/migration.rs new file mode 100644 index 0000000000000..543d7d9a8e340 --- /dev/null +++ b/frame/identity/src/migration.rs @@ -0,0 +1,50 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! Migration code to update storage. + +use super::*; +use frame_support::storage::migration::{put_storage_value, take_storage_value, StorageIterator}; + +pub fn on_runtime_upgrade() { + change_name_sudo_to_identity::() +} + +// Change the storage name used by this pallet from `Sudo` to `Identity`. +// +// Since the format of the storage items themselves have not changed, we do not +// need to keep track of a storage version. If the runtime does not need to be +// upgraded, nothing here will happen anyway. + +fn change_name_sudo_to_identity() { + sp_runtime::print("Migrating Identity."); + + for (hash, identity_of) in StorageIterator::>>>::new(b"Sudo", b"IdentityOf").drain() { + put_storage_value(b"Identity", b"IdentityOf", &hash, identity_of); + } + + for (hash, super_of) in StorageIterator::>::new(b"Sudo", b"SuperOf").drain() { + put_storage_value(b"Identity", b"SuperOf", &hash, super_of); + } + + for (hash, subs_of) in StorageIterator::>::new(b"Sudo", b"SubsOf").drain() { + put_storage_value(b"Identity", b"SubsOf", &hash, subs_of); + } + + if let Some(recent_hints) = take_storage_value::, T::AccountId>>>>(b"Sudo", b"Registrars", &[]) { + put_storage_value(b"Identity", b"Registrars", &[], recent_hints); + } +} diff --git a/frame/transaction-payment/src/lib.rs b/frame/transaction-payment/src/lib.rs index b7f6ce912c187..2d8eb799917df 100644 --- a/frame/transaction-payment/src/lib.rs +++ b/frame/transaction-payment/src/lib.rs @@ -48,6 +48,8 @@ use sp_runtime::{ }; use pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo; +mod migration; + type Multiplier = Fixed64; type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; @@ -77,11 +79,6 @@ pub trait Trait: frame_system::Trait { decl_storage! { trait Store for Module as TransactionPayment { pub NextFeeMultiplier get(fn next_fee_multiplier): Multiplier = Multiplier::from_parts(0); - - /// True if network has been upgraded to this version. - /// - /// True for new networks. - IsUpgraded build(|_| true): bool; } } @@ -99,26 +96,12 @@ decl_module! { }); } - fn on_initialize() { - if !IsUpgraded::get() { - IsUpgraded::put(true); - Self::do_upgrade(); - } + fn on_runtime_upgrade() { + migration::on_runtime_upgrade() } } } -// Migration code to update storage name -use frame_support::storage::migration::{put_storage_value, take_storage_value}; -impl Module { - pub fn do_upgrade() { - sp_runtime::print("Migrating Transaction Payment."); - - let next_fee_multiplier = take_storage_value::(b"Balances", b"NextFeeMultiplier", &[]).unwrap_or_default(); - put_storage_value(b"TransactionPayment", b"NextFeeMultiplier", &[], next_fee_multiplier); - } -} - impl Module { /// Query the data that we know about the fee of a given `call`. /// diff --git a/frame/transaction-payment/src/migration.rs b/frame/transaction-payment/src/migration.rs new file mode 100644 index 0000000000000..0e44f62b82dbf --- /dev/null +++ b/frame/transaction-payment/src/migration.rs @@ -0,0 +1,38 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! Migration code to update storage. + +use super::*; +use frame_support::storage::migration::{put_storage_value, take_storage_value}; + +pub fn on_runtime_upgrade() { + change_name_balances_to_transaction_payment() +} + +// Change the storage name used by this pallet from `Balances` to `TransactionPayment`. +// +// Since the format of the storage items themselves have not changed, we do not +// need to keep track of a storage version. If the runtime does not need to be +// upgraded, nothing here will happen anyway. + +fn change_name_balances_to_transaction_payment() { + sp_runtime::print("Migrating Transaction Payment."); + + if let Some(next_fee_multiplier) = take_storage_value::(b"Balances", b"NextFeeMultiplier", &[]) { + put_storage_value(b"TransactionPayment", b"NextFeeMultiplier", &[], next_fee_multiplier); + } +} From f6d569369f45c827c721644c835129a86bf3b3d3 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 5 Mar 2020 17:37:24 +0100 Subject: [PATCH 12/17] Fix merge error --- frame/balances/src/migration.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frame/balances/src/migration.rs b/frame/balances/src/migration.rs index 0e98d5656e7b5..fef9256ff3551 100644 --- a/frame/balances/src/migration.rs +++ b/frame/balances/src/migration.rs @@ -101,4 +101,6 @@ fn upgrade_v1_to_v2, I: Instance>() { } take_storage_value::(b"Balances", b"IsUpgraded", &[]); + + StorageVersion::::put(Releases::V2_0_0); } From 7ea6bc696cf015def846eb18b2b28bc4b9dac329 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Tue, 10 Mar 2020 11:49:10 +0100 Subject: [PATCH 13/17] Migration for contracts --- frame/contracts/src/lib.rs | 5 +++ frame/contracts/src/migration.rs | 62 ++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 frame/contracts/src/migration.rs diff --git a/frame/contracts/src/lib.rs b/frame/contracts/src/lib.rs index 8843f0e24187e..e1022859a1956 100644 --- a/frame/contracts/src/lib.rs +++ b/frame/contracts/src/lib.rs @@ -98,6 +98,7 @@ mod rent; #[cfg(test)] mod tests; +mod migration; use crate::exec::ExecutionContext; use crate::account_db::{AccountDb, DirectAccountDb}; @@ -666,6 +667,10 @@ decl_module! { fn on_finalize() { GasSpent::kill(); } + + fn on_runtime_upgrade() { + migration::on_runtime_upgrade::() + } } } diff --git a/frame/contracts/src/migration.rs b/frame/contracts/src/migration.rs new file mode 100644 index 0000000000000..b294425bdaebf --- /dev/null +++ b/frame/contracts/src/migration.rs @@ -0,0 +1,62 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! Migration code to update storage. + +use super::*; +use frame_support::storage::migration::{put_storage_value, take_storage_value, StorageIterator}; + +pub fn on_runtime_upgrade() { + change_name_contract_to_contracts::() +} + +// Change the storage name used by this pallet from `Contract` to `Contracts`. +// +// Since the format of the storage items themselves have not changed, we do not +// need to keep track of a storage version. If the runtime does not need to be +// upgraded, nothing here will happen anyway. + +fn change_name_contract_to_contracts() { + sp_runtime::print("Migrating Contracts."); + + if let Some(gas_spent) = take_storage_value::(b"Contract", b"GasSpent", &[]) { + put_storage_value(b"Contracts", b"GasSpent", &[], gas_spent); + } + + if let Some(current_schedule) = take_storage_value::(b"Contract", b"CurrentSchedule", &[]) { + put_storage_value(b"Contracts", b"CurrentSchedule", &[], current_schedule); + } + + for (hash, pristine_code) in StorageIterator::>>::new(b"Contract", b"PristineCode").drain() { + put_storage_value(b"Contracts", b"PristineCode", &hash, pristine_code); + } + + for (hash, code_storage) in StorageIterator::>::new(b"Contract", b"CodeStorage").drain() { + put_storage_value(b"Contracts", b"CodeStorage", &hash, code_storage); + } + + if let Some(current_schedule) = take_storage_value::(b"Contract", b"AccountCounter", &[]) { + put_storage_value(b"Contracts", b"AccountCounter", &[], current_schedule); + } + + for (hash, contract_info_of) in StorageIterator::>>::new(b"Contract", b"ContractInfoOf").drain() { + put_storage_value(b"Contracts", b"ContractInfoOf", &hash, contract_info_of); + } + + if let Some(get_price) = take_storage_value::>(b"Contract", b"GetPrice", &[]) { + put_storage_value(b"Contracts", b"GetPrice", &[], get_price); + } +} From 0a1a848c4ab3874a07737ea76af382a50cd12cdc Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Thu, 12 Mar 2020 16:35:28 +0100 Subject: [PATCH 14/17] Remove serde --- Cargo.lock | 1 - frame/transaction-payment/Cargo.toml | 2 -- 2 files changed, 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 864dc456bc9b5..32b2d0dc0f20b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4474,7 +4474,6 @@ dependencies = [ "pallet-balances", "pallet-transaction-payment-rpc-runtime-api", "parity-scale-codec", - "serde", "sp-core", "sp-io", "sp-runtime", diff --git a/frame/transaction-payment/Cargo.toml b/frame/transaction-payment/Cargo.toml index ab507e68101bb..3a291dc516312 100644 --- a/frame/transaction-payment/Cargo.toml +++ b/frame/transaction-payment/Cargo.toml @@ -9,7 +9,6 @@ repository = "https://github.com/paritytech/substrate/" description = "FRAME pallet to manage transaction payments" [dependencies] -serde = { version = "1.0.101", optional = true } codec = { package = "parity-scale-codec", version = "1.2.0", default-features = false, features = ["derive"] } sp-std = { version = "2.0.0-alpha.2", default-features = false, path = "../../primitives/std" } sp-runtime = { version = "2.0.0-alpha.2", default-features = false, path = "../../primitives/runtime" } @@ -25,7 +24,6 @@ pallet-balances = { version = "2.0.0-alpha.2", path = "../balances" } [features] default = ["std"] std = [ - "serde", "codec/std", "sp-std/std", "sp-runtime/std", From 504389a482c2a89602f4b1f02a87f43fe8ab2e76 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 13 Mar 2020 18:56:32 +0100 Subject: [PATCH 15/17] Remove some illegal spaces and Options --- frame/contracts/src/migration.rs | 46 +++++++++++----------- frame/finality-tracker/src/migration.rs | 34 ++++++++-------- frame/identity/src/migration.rs | 28 ++++++------- frame/transaction-payment/src/migration.rs | 8 ++-- 4 files changed, 58 insertions(+), 58 deletions(-) diff --git a/frame/contracts/src/migration.rs b/frame/contracts/src/migration.rs index b294425bdaebf..83d3771c83dbb 100644 --- a/frame/contracts/src/migration.rs +++ b/frame/contracts/src/migration.rs @@ -20,7 +20,7 @@ use super::*; use frame_support::storage::migration::{put_storage_value, take_storage_value, StorageIterator}; pub fn on_runtime_upgrade() { - change_name_contract_to_contracts::() + change_name_contract_to_contracts::() } // Change the storage name used by this pallet from `Contract` to `Contracts`. @@ -30,33 +30,33 @@ pub fn on_runtime_upgrade() { // upgraded, nothing here will happen anyway. fn change_name_contract_to_contracts() { - sp_runtime::print("Migrating Contracts."); + sp_runtime::print("Migrating Contracts."); - if let Some(gas_spent) = take_storage_value::(b"Contract", b"GasSpent", &[]) { - put_storage_value(b"Contracts", b"GasSpent", &[], gas_spent); - } + if let Some(gas_spent) = take_storage_value::(b"Contract", b"GasSpent", &[]) { + put_storage_value(b"Contracts", b"GasSpent", &[], gas_spent); + } - if let Some(current_schedule) = take_storage_value::(b"Contract", b"CurrentSchedule", &[]) { - put_storage_value(b"Contracts", b"CurrentSchedule", &[], current_schedule); - } + if let Some(current_schedule) = take_storage_value::(b"Contract", b"CurrentSchedule", &[]) { + put_storage_value(b"Contracts", b"CurrentSchedule", &[], current_schedule); + } - for (hash, pristine_code) in StorageIterator::>>::new(b"Contract", b"PristineCode").drain() { - put_storage_value(b"Contracts", b"PristineCode", &hash, pristine_code); - } + for (hash, pristine_code) in StorageIterator::>::new(b"Contract", b"PristineCode").drain() { + put_storage_value(b"Contracts", b"PristineCode", &hash, pristine_code); + } - for (hash, code_storage) in StorageIterator::>::new(b"Contract", b"CodeStorage").drain() { - put_storage_value(b"Contracts", b"CodeStorage", &hash, code_storage); - } + for (hash, code_storage) in StorageIterator::::new(b"Contract", b"CodeStorage").drain() { + put_storage_value(b"Contracts", b"CodeStorage", &hash, code_storage); + } - if let Some(current_schedule) = take_storage_value::(b"Contract", b"AccountCounter", &[]) { - put_storage_value(b"Contracts", b"AccountCounter", &[], current_schedule); - } + if let Some(current_schedule) = take_storage_value::(b"Contract", b"AccountCounter", &[]) { + put_storage_value(b"Contracts", b"AccountCounter", &[], current_schedule); + } - for (hash, contract_info_of) in StorageIterator::>>::new(b"Contract", b"ContractInfoOf").drain() { - put_storage_value(b"Contracts", b"ContractInfoOf", &hash, contract_info_of); - } + for (hash, contract_info_of) in StorageIterator::>::new(b"Contract", b"ContractInfoOf").drain() { + put_storage_value(b"Contracts", b"ContractInfoOf", &hash, contract_info_of); + } - if let Some(get_price) = take_storage_value::>(b"Contract", b"GetPrice", &[]) { - put_storage_value(b"Contracts", b"GetPrice", &[], get_price); - } + if let Some(get_price) = take_storage_value::>(b"Contract", b"GetPrice", &[]) { + put_storage_value(b"Contracts", b"GetPrice", &[], get_price); + } } diff --git a/frame/finality-tracker/src/migration.rs b/frame/finality-tracker/src/migration.rs index 1fea7855dba08..1eff123db370e 100644 --- a/frame/finality-tracker/src/migration.rs +++ b/frame/finality-tracker/src/migration.rs @@ -20,7 +20,7 @@ use super::*; use frame_support::storage::migration::{put_storage_value, take_storage_value}; pub fn on_runtime_upgrade() { - change_name_timestamp_to_finality_tracker::() + change_name_timestamp_to_finality_tracker::() } // Change the storage name used by this pallet from `Timestamp` to `FinalityTracker`. @@ -30,25 +30,25 @@ pub fn on_runtime_upgrade() { // upgraded, nothing here will happen anyway. fn change_name_timestamp_to_finality_tracker() { - sp_runtime::print("Migrating Finality Tracker."); + sp_runtime::print("Migrating Finality Tracker."); - if let Some(recent_hints) = take_storage_value::>(b"Timestamp", b"RecentHints", &[]) { - put_storage_value(b"FinalityTracker", b"RecentHints", &[], recent_hints); - } + if let Some(recent_hints) = take_storage_value::>(b"Timestamp", b"RecentHints", &[]) { + put_storage_value(b"FinalityTracker", b"RecentHints", &[], recent_hints); + } - if let Some(ordered_hints) = take_storage_value::>(b"Timestamp", b"OrderedHints", &[]) { - put_storage_value(b"FinalityTracker", b"OrderedHints", &[], ordered_hints); - } + if let Some(ordered_hints) = take_storage_value::>(b"Timestamp", b"OrderedHints", &[]) { + put_storage_value(b"FinalityTracker", b"OrderedHints", &[], ordered_hints); + } - if let Some(median) = take_storage_value::(b"Timestamp", b"Median", &[]) { - put_storage_value(b"FinalityTracker", b"Median", &[], median); - } + if let Some(median) = take_storage_value::(b"Timestamp", b"Median", &[]) { + put_storage_value(b"FinalityTracker", b"Median", &[], median); + } - if let Some(update) = take_storage_value::>(b"Timestamp", b"Update", &[]) { - put_storage_value(b"FinalityTracker", b"Update", &[], update); - } + if let Some(update) = take_storage_value::(b"Timestamp", b"Update", &[]) { + put_storage_value(b"FinalityTracker", b"Update", &[], update); + } - if let Some(initialized) = take_storage_value::(b"Timestamp", b"Initialized", &[]) { - put_storage_value(b"FinalityTracker", b"Initialized", &[], initialized); - } + if let Some(initialized) = take_storage_value::(b"Timestamp", b"Initialized", &[]) { + put_storage_value(b"FinalityTracker", b"Initialized", &[], initialized); + } } diff --git a/frame/identity/src/migration.rs b/frame/identity/src/migration.rs index 543d7d9a8e340..b7c46ab3c5018 100644 --- a/frame/identity/src/migration.rs +++ b/frame/identity/src/migration.rs @@ -20,7 +20,7 @@ use super::*; use frame_support::storage::migration::{put_storage_value, take_storage_value, StorageIterator}; pub fn on_runtime_upgrade() { - change_name_sudo_to_identity::() + change_name_sudo_to_identity::() } // Change the storage name used by this pallet from `Sudo` to `Identity`. @@ -30,21 +30,21 @@ pub fn on_runtime_upgrade() { // upgraded, nothing here will happen anyway. fn change_name_sudo_to_identity() { - sp_runtime::print("Migrating Identity."); + sp_runtime::print("Migrating Identity."); - for (hash, identity_of) in StorageIterator::>>>::new(b"Sudo", b"IdentityOf").drain() { - put_storage_value(b"Identity", b"IdentityOf", &hash, identity_of); - } + for (hash, identity_of) in StorageIterator::>>::new(b"Sudo", b"IdentityOf").drain() { + put_storage_value(b"Identity", b"IdentityOf", &hash, identity_of); + } - for (hash, super_of) in StorageIterator::>::new(b"Sudo", b"SuperOf").drain() { - put_storage_value(b"Identity", b"SuperOf", &hash, super_of); - } + for (hash, super_of) in StorageIterator::<(T::AccountId, Data)>::new(b"Sudo", b"SuperOf").drain() { + put_storage_value(b"Identity", b"SuperOf", &hash, super_of); + } - for (hash, subs_of) in StorageIterator::>::new(b"Sudo", b"SubsOf").drain() { - put_storage_value(b"Identity", b"SubsOf", &hash, subs_of); - } + for (hash, subs_of) in StorageIterator::<(T::AccountId, Data)>::new(b"Sudo", b"SubsOf").drain() { + put_storage_value(b"Identity", b"SubsOf", &hash, subs_of); + } - if let Some(recent_hints) = take_storage_value::, T::AccountId>>>>(b"Sudo", b"Registrars", &[]) { - put_storage_value(b"Identity", b"Registrars", &[], recent_hints); - } + if let Some(recent_hints) = take_storage_value::, T::AccountId>>>>(b"Sudo", b"Registrars", &[]) { + put_storage_value(b"Identity", b"Registrars", &[], recent_hints); + } } diff --git a/frame/transaction-payment/src/migration.rs b/frame/transaction-payment/src/migration.rs index 0e44f62b82dbf..6db3cfd0f9b60 100644 --- a/frame/transaction-payment/src/migration.rs +++ b/frame/transaction-payment/src/migration.rs @@ -30,9 +30,9 @@ pub fn on_runtime_upgrade() { // upgraded, nothing here will happen anyway. fn change_name_balances_to_transaction_payment() { - sp_runtime::print("Migrating Transaction Payment."); + sp_runtime::print("Migrating Transaction Payment."); - if let Some(next_fee_multiplier) = take_storage_value::(b"Balances", b"NextFeeMultiplier", &[]) { - put_storage_value(b"TransactionPayment", b"NextFeeMultiplier", &[], next_fee_multiplier); - } + if let Some(next_fee_multiplier) = take_storage_value::(b"Balances", b"NextFeeMultiplier", &[]) { + put_storage_value(b"TransactionPayment", b"NextFeeMultiplier", &[], next_fee_multiplier); + } } From e21c85e5f823ad4c67c49889d6234e7e7b82fbbd Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 13 Mar 2020 19:19:25 +0100 Subject: [PATCH 16/17] Fix types in identity. --- frame/identity/src/migration.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frame/identity/src/migration.rs b/frame/identity/src/migration.rs index b7c46ab3c5018..1038502753fbc 100644 --- a/frame/identity/src/migration.rs +++ b/frame/identity/src/migration.rs @@ -40,11 +40,13 @@ fn change_name_sudo_to_identity() { put_storage_value(b"Identity", b"SuperOf", &hash, super_of); } - for (hash, subs_of) in StorageIterator::<(T::AccountId, Data)>::new(b"Sudo", b"SubsOf").drain() { + for (hash, subs_of) in StorageIterator::<(BalanceOf, Vec)>::new(b"Sudo", b"SubsOf").drain() { put_storage_value(b"Identity", b"SubsOf", &hash, subs_of); } if let Some(recent_hints) = take_storage_value::, T::AccountId>>>>(b"Sudo", b"Registrars", &[]) { put_storage_value(b"Identity", b"Registrars", &[], recent_hints); } + + sp_runtime::print("Done Identity."); } From 066f8ef4826dc87f3cd20ec51536adb18029a2e7 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sat, 14 Mar 2020 12:43:18 +0100 Subject: [PATCH 17/17] Minor variable rename --- frame/identity/src/migration.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frame/identity/src/migration.rs b/frame/identity/src/migration.rs index 1038502753fbc..e312d9e04f239 100644 --- a/frame/identity/src/migration.rs +++ b/frame/identity/src/migration.rs @@ -44,8 +44,8 @@ fn change_name_sudo_to_identity() { put_storage_value(b"Identity", b"SubsOf", &hash, subs_of); } - if let Some(recent_hints) = take_storage_value::, T::AccountId>>>>(b"Sudo", b"Registrars", &[]) { - put_storage_value(b"Identity", b"Registrars", &[], recent_hints); + if let Some(registrars) = take_storage_value::, T::AccountId>>>>(b"Sudo", b"Registrars", &[]) { + put_storage_value(b"Identity", b"Registrars", &[], registrars); } sp_runtime::print("Done Identity.");