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

pallet-migrations Initial Implementation #527

Merged
merged 84 commits into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
9ecdc74
Add initial migrations pallet sketch
notlesh Jun 21, 2021
e4f15ce
Sketch out Migration impls
notlesh Jun 25, 2021
ca3620e
Make it build
notlesh Jun 25, 2021
cdc042a
Squelch warnings
notlesh Jun 25, 2021
c4204b4
Sketch out process_runtime_upgrades
notlesh Jun 25, 2021
0cc885d
Leave note for reviewers
notlesh Jun 25, 2021
95308a1
Add &self to Migrations trait fns
notlesh Jun 28, 2021
93b96ce
Make it compile
notlesh Jun 28, 2021
275531c
Refactor migrations design to use stepping instead of one-shot
notlesh Jun 28, 2021
d5abf1f
Fix typo/bug
notlesh Jun 28, 2021
d25ffc1
Track overall migration doneness
notlesh Jun 28, 2021
0c9ce74
Optimize when progress remains unchanged
notlesh Jun 28, 2021
23837f8
Resolve compiler warnings
notlesh Jun 29, 2021
85ecaa1
Incremental progress on mock
notlesh Jun 29, 2021
f22ce8d
Mock is getting close
notlesh Jun 29, 2021
d8d2c3c
Make mock build
notlesh Jun 29, 2021
bfd24f6
Plumb genesis building in mock
notlesh Jun 30, 2021
9404fbe
Baby's first tests
notlesh Jun 30, 2021
edee830
Fix events
notlesh Jun 30, 2021
d13a471
Use Vec<u8> instead of String
notlesh Jun 30, 2021
986433e
Make MigrationsList part of pallet config; plumb through Moonbase run…
notlesh Jul 1, 2021
92047ee
Appease the compiler
notlesh Jul 1, 2021
b885fc5
Fix up CommonMigrations list
notlesh Jul 1, 2021
aefb302
Remove comment
notlesh Jul 1, 2021
f9f8a2a
Cargo fmt
notlesh Jul 1, 2021
bc2e538
Per-test MigrationsList
notlesh Jul 1, 2021
19a9912
Attempt at a glue
notlesh Jul 3, 2021
1f70d01
Fix FIXME
notlesh Jul 3, 2021
6e581f3
Getting close
notlesh Jul 3, 2021
2ea1e3b
Sort out lifetimes
notlesh Jul 3, 2021
4afc532
Simplify FnMut arguments/storage
notlesh Jul 6, 2021
85ed484
Clean up, fix FIXMEs
notlesh Jul 6, 2021
e377caf
It works
notlesh Jul 7, 2021
95d6b95
Implement Migrations::on_initialize
notlesh Jul 7, 2021
d5da28a
Resolve compilation warnings, add comments about how mock glue works
notlesh Jul 7, 2021
2c0bfe5
Move migration event impl
notlesh Jul 7, 2021
67bede2
Let tests manage ExtBuilder ... execute_with()
notlesh Jul 8, 2021
f924112
Test that migrations are only run once
notlesh Jul 8, 2021
5022dcc
Remove TODO/comment; events are not cheap and should be used conserva…
notlesh Jul 8, 2021
8a925ac
Merge branch 'master' into notlesh-migration-sketch
notlesh Jul 19, 2021
a2177dd
Post merge-master fixes
notlesh Jul 19, 2021
01727f8
Remove cruft
notlesh Jul 19, 2021
8ed861f
Track some db reads and writes and charge accordingly
notlesh Jul 19, 2021
0785e48
cargo fmt
notlesh Jul 20, 2021
8c444e7
Add failing test about one-migration-at-a-time
notlesh Jul 21, 2021
2e12fd2
Don't start next migration until current is done
notlesh Jul 21, 2021
9a9bfd4
Add notes from meeting
notlesh Jul 22, 2021
2744571
Allow multi-block migrations to be disabled
notlesh Jul 22, 2021
e1f49c6
Add failing test about overweight migrations
notlesh Jul 22, 2021
0684874
Explicitly embrace allowing overweight migrations
notlesh Jul 22, 2021
c19a4a1
cargo fmt
notlesh Jul 22, 2021
7d57a4e
Clean up / add comments
notlesh Jul 26, 2021
3f87f79
Derive block weight from Config (still needs improvement)
notlesh Jul 26, 2021
595e865
Merge branch 'master' into notlesh-migration-sketch
notlesh Jul 26, 2021
8f6e9e5
cargo fmt
notlesh Jul 26, 2021
a4e2acc
Configure all runtimes to include pallet-migrations
notlesh Jul 26, 2021
41e9d0b
Add pallet-migrations genesis to specs
notlesh Jul 26, 2021
0a3ae7e
Update pallets/migrations/src/lib.rs
notlesh Jul 29, 2021
26ef7db
Update pallets/migrations/src/lib.rs
notlesh Jul 29, 2021
e6543e6
First pass at ripping out multi-block migration support
notlesh Aug 13, 2021
01bc09f
Incremental work @ removing multi-block migration support
notlesh Aug 13, 2021
d2e5759
Make migration tests compile (not passing yet)
notlesh Aug 13, 2021
38ee3a4
Clean up runtime to reflect removal of multi-block migrations
notlesh Aug 17, 2021
30033ee
You know your tests are good when they catch a critical refactor mistake
notlesh Aug 17, 2021
dfb6f42
Fix test logic to reflect no multi-block migrations
notlesh Aug 17, 2021
f691977
cargo fmt
notlesh Aug 17, 2021
dc42819
Remove phantomdata field from pallet_migrations::GenesisConfig (#701)
4meta5 Aug 18, 2021
f31807a
Better log statement
notlesh Aug 18, 2021
607e0ee
Use ValueQuery instead of OptionQuery
notlesh Aug 18, 2021
3e9c26b
Merge branch 'master' into notlesh-migration-sketch
notlesh Aug 18, 2021
91f92f7
Update Cargo.lock
notlesh Aug 18, 2021
c0e6167
Manually add back version = 3
notlesh Aug 18, 2021
d9e561b
Make some deps dev-dependencies
notlesh Aug 18, 2021
3722eaf
Merge branch 'master' into notlesh-migration-sketch
notlesh Sep 8, 2021
a585e3c
Fix branch
notlesh Sep 8, 2021
bdafb76
Use hotfix branch in Migrations
notlesh Sep 8, 2021
9d27292
Clean up from merge
notlesh Sep 8, 2021
e346883
cargo fmt
notlesh Sep 8, 2021
3cb8bb4
Remove prior hack in test
notlesh Sep 8, 2021
99ca061
cargo.lock
JoshOrndorff Sep 16, 2021
62eb821
Merge branch 'master' into notlesh-migration-sketch
JoshOrndorff Sep 16, 2021
cf735f9
fix warning
JoshOrndorff Sep 16, 2021
fd0a165
minor cleaning in cargo.toml
JoshOrndorff Sep 16, 2021
3bcfce5
clean up cargo.ttoml
JoshOrndorff Sep 20, 2021
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
13 changes: 10 additions & 3 deletions pallets/migrations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>.

//! # Migrations
//! # Migration Pallet

#![cfg_attr(not(feature = "std"), no_std)]

use frame_support::pallet;
pub mod migrations;

#[pallet]
pub mod pallet {
Expand All @@ -31,13 +32,19 @@ pub mod pallet {

#[derive(Copy, Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug)]
/// A Migration that must happen on-chain upon a runtime-upgrade
pub struct Migration {
pub trait Migration {
notlesh marked this conversation as resolved.
Show resolved Hide resolved
// TODO: this would involve some metadata about the migration as well as a means of calling
// the actual migration function

fn friendly_name() -> str;
}

/// Our list of migrations. Any ordering considerations can be specified here (?).
// const MIGRATIONS: // TODO: this would be a constant vec (or similar) of individual migrations
static MIGRATIONS: [Migration] = [
MM_001_AuthorMappingAddDeposit,
MM_002_StakingFixTotalBalance,
MM_003_StakingTransitionBoundedSet,
];
notlesh marked this conversation as resolved.
Show resolved Hide resolved

/// Configuration trait of this pallet.
#[pallet::config]
Expand Down
43 changes: 43 additions & 0 deletions pallets/migrations/src/migrations.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2019-2020 PureStake Inc.
// This file is part of Moonbeam.

// Moonbeam 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.

// Moonbeam 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 Moonbeam. If not, see <http://www.gnu.org/licenses/>.

//! # Migrations

use crate::*;

/// This module acts as a registry where each migration is defined. Each migration should implement
/// the "Migration" trait declared in this crate.

struct MM_001_AuthorMappingAddDeposit;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

MM stands for Moonbeam Migration here. I'm giving these monotonically increasing numbers, something along the lines of how EIPs are named.

impl Migration for MM_001_AuthorMappingAddDeposit {
fn friendly_name() -> str {
"AuthorMappingAddDeposit"
}
}

struct MM_002_StakingFixTotalBalance;
4meta5 marked this conversation as resolved.
Show resolved Hide resolved
impl Migration for StakingFixTotalBalance {
fn friendly_name() -> str {
"StakingFixTotalBalance"
}
}

struct MM_003_StakingTransitionBoundedSet; // TODO: better name
notlesh marked this conversation as resolved.
Show resolved Hide resolved
impl Migration for MM_003_StakingTransitionBoundedSet {
fn friendly_name() -> str {
"StakingTransitionBoundedSet"
}
}