Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Assign unique storage names to pallets. #5010

Merged
merged 23 commits into from
Mar 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d217526
Assign unique storage names to pallets.
shawntabrizi Feb 20, 2020
e6cb251
Bump spec
shawntabrizi Feb 20, 2020
e4da049
Upgrade logic for finality tracker (untested)
shawntabrizi Feb 20, 2020
48da9c8
Logic for migrating Identity (untested)
shawntabrizi Feb 20, 2020
a6033e9
Logic for migrating transaction-payment
shawntabrizi Feb 20, 2020
24225b7
Fix tests
shawntabrizi Feb 20, 2020
cec4172
Fix `decl_storage` build
shawntabrizi Feb 20, 2020
774bc9e
Contract -> Contracts
shawntabrizi Feb 28, 2020
da77c17
Merge remote-tracking branch 'upstream/master' into shawntabrizi-fix-…
shawntabrizi Feb 28, 2020
92c6217
Update Cargo.lock
shawntabrizi Feb 28, 2020
6f732fc
Merge branch 'master' into shawntabrizi-fix-storage-names
gavofyork Mar 5, 2020
9a554f2
Merge remote-tracking branch 'upstream/master' into shawntabrizi-fix-…
shawntabrizi Mar 5, 2020
58f671e
bump spec
shawntabrizi Mar 5, 2020
916f0a6
update migration
shawntabrizi Mar 5, 2020
f6d5693
Fix merge error
shawntabrizi Mar 5, 2020
7ea6bc6
Migration for contracts
shawntabrizi Mar 10, 2020
93b26ce
Merge branch 'master' into shawntabrizi-fix-storage-names
shawntabrizi Mar 10, 2020
0a1a848
Remove serde
shawntabrizi Mar 12, 2020
8016be2
Merge remote-tracking branch 'upstream/master' into shawntabrizi-fix-…
shawntabrizi Mar 12, 2020
abb90d4
Merge branch 'master' into shawntabrizi-fix-storage-names
gavofyork Mar 13, 2020
504389a
Remove some illegal spaces and Options
gavofyork Mar 13, 2020
e21c85e
Fix types in identity.
gavofyork Mar 13, 2020
066f8ef
Minor variable rename
gavofyork Mar 14, 2020
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
Prev Previous commit
Next Next commit
Migration for contracts
  • Loading branch information
shawntabrizi committed Mar 10, 2020
commit 7ea6bc696cf015def846eb18b2b28bc4b9dac329
5 changes: 5 additions & 0 deletions frame/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ mod rent;

#[cfg(test)]
mod tests;
mod migration;

use crate::exec::ExecutionContext;
use crate::account_db::{AccountDb, DirectAccountDb};
Expand Down Expand Up @@ -666,6 +667,10 @@ decl_module! {
fn on_finalize() {
GasSpent::kill();
}

fn on_runtime_upgrade() {
migration::on_runtime_upgrade::<T>()
}
}
}

Expand Down
62 changes: 62 additions & 0 deletions frame/contracts/src/migration.rs
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

//! Migration code to update storage.

use super::*;
use frame_support::storage::migration::{put_storage_value, take_storage_value, StorageIterator};

pub fn on_runtime_upgrade<T: Trait>() {
change_name_contract_to_contracts::<T>()
}

// 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<T: Trait>() {
sp_runtime::print("Migrating Contracts.");

if let Some(gas_spent) = take_storage_value::<Gas>(b"Contract", b"GasSpent", &[]) {
put_storage_value(b"Contracts", b"GasSpent", &[], gas_spent);
}

if let Some(current_schedule) = take_storage_value::<Schedule>(b"Contract", b"CurrentSchedule", &[]) {
put_storage_value(b"Contracts", b"CurrentSchedule", &[], current_schedule);
}

for (hash, pristine_code) in StorageIterator::<Option<Vec<u8>>>::new(b"Contract", b"PristineCode").drain() {
put_storage_value(b"Contracts", b"PristineCode", &hash, pristine_code);
}

for (hash, code_storage) in StorageIterator::<Option<wasm::PrefabWasmModule>>::new(b"Contract", b"CodeStorage").drain() {
put_storage_value(b"Contracts", b"CodeStorage", &hash, code_storage);
}

if let Some(current_schedule) = take_storage_value::<u64>(b"Contract", b"AccountCounter", &[]) {
put_storage_value(b"Contracts", b"AccountCounter", &[], current_schedule);
}

for (hash, contract_info_of) in StorageIterator::<Option<ContractInfo<T>>>::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::<BalanceOf<T>>(b"Contract", b"GetPrice", &[]) {
put_storage_value(b"Contracts", b"GetPrice", &[], get_price);
}
}