Assign unique storage names to pallets. (#5010)

* Assign unique storage names to pallets.

* Bump spec

* Upgrade logic for finality tracker (untested)

* Logic for migrating Identity (untested)

* Logic for migrating transaction-payment

* Fix tests

* Fix `decl_storage` build

* Contract -> Contracts

* Update Cargo.lock

* bump spec

* update migration

* Fix merge error

* Migration for contracts

* Remove serde

* Remove some illegal spaces and Options

* Fix types in identity.

* Minor variable rename

Co-authored-by: Gavin Wood <gavin@parity.io>
This commit is contained in:
Shawn Tabrizi
2020-03-14 13:44:48 +02:00
committed by GitHub
parent 7285cbc801
commit 74f8db5def
16 changed files with 246 additions and 11 deletions
+7 -1
View File
@@ -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;
@@ -40,7 +42,7 @@ pub trait Trait: SystemTrait {
}
decl_storage! {
trait Store for Module<T: Trait> as Timestamp {
trait Store for Module<T: Trait> as FinalityTracker {
/// Recent hints.
RecentHints get(fn recent_hints) build(|_| vec![T::BlockNumber::zero()]): Vec<T::BlockNumber>;
/// Ordered recent hints.
@@ -89,6 +91,10 @@ decl_module! {
fn on_finalize() {
Self::update_hint(<Self as Store>::Update::take())
}
fn on_runtime_upgrade() {
migration::on_runtime_upgrade::<T>()
}
}
}
@@ -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 <http://www.gnu.org/licenses/>.
// Migration code to update storage.
use super::*;
use frame_support::storage::migration::{put_storage_value, take_storage_value};
pub fn on_runtime_upgrade<T: Trait>() {
change_name_timestamp_to_finality_tracker::<T>()
}
// 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<T:Trait>() {
sp_runtime::print("Migrating Finality Tracker.");
if let Some(recent_hints) = take_storage_value::<Vec<T::BlockNumber>>(b"Timestamp", b"RecentHints", &[]) {
put_storage_value(b"FinalityTracker", b"RecentHints", &[], recent_hints);
}
if let Some(ordered_hints) = take_storage_value::<Vec<T::BlockNumber>>(b"Timestamp", b"OrderedHints", &[]) {
put_storage_value(b"FinalityTracker", b"OrderedHints", &[], ordered_hints);
}
if let Some(median) = take_storage_value::<T::BlockNumber>(b"Timestamp", b"Median", &[]) {
put_storage_value(b"FinalityTracker", b"Median", &[], median);
}
if let Some(update) = take_storage_value::<T::BlockNumber>(b"Timestamp", b"Update", &[]) {
put_storage_value(b"FinalityTracker", b"Update", &[], update);
}
if let Some(initialized) = take_storage_value::<bool>(b"Timestamp", b"Initialized", &[]) {
put_storage_value(b"FinalityTracker", b"Initialized", &[], initialized);
}
}