-
Notifications
You must be signed in to change notification settings - Fork 47
feat: staking v5 migrations #249
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e89d937
wip: initialize v5 migrations
weichweich 9c97a70
fix: try-runtime
weichweich deee4c0
wip: staking migrations
weichweich 4848664
tests: add tests
weichweich d77927b
fix tests
weichweich e75f792
chore: 🧹
weichweich f0d7131
add benchmarks
8e27436
fix weights
weichweich 617152b
Merge branch 'develop' into aw-staking-migrations
weichweich 760d813
Merge remote-tracking branch 'origin/develop' into aw-staking-migrations
weichweich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // KILT Blockchain – https://botlabs.org | ||
| // Copyright (C) 2019-2021 BOTLabs GmbH | ||
|
|
||
| // The KILT Blockchain 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. | ||
|
|
||
| // The KILT Blockchain 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 this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| // If you feel like getting in touch with us, you can do so at info@botlabs.org | ||
|
|
||
| use crate::{migrations::StakingStorageVersion, CandidateCount, CandidatePool, Config, StorageVersion}; | ||
| use frame_support::{dispatch::Weight, storage::StorageValue, traits::Get}; | ||
|
|
||
| #[cfg(feature = "try-runtime")] | ||
| pub(crate) fn pre_migrate<T: Config>() -> Result<(), &'static str> { | ||
| assert_eq!(StorageVersion::<T>::get(), StakingStorageVersion::V4); | ||
| Ok(()) | ||
| } | ||
|
|
||
| pub(crate) fn migrate<T: Config>() -> Weight { | ||
| log::info!("Migrating staking to StakingStorageVersion::V5"); | ||
|
|
||
| // Kill selected candidates list | ||
| old::SelectedCandidates::<T>::kill(); | ||
|
|
||
| // count candidates | ||
| let counter: u32 = CandidatePool::<T>::iter().fold(0, |acc, _| acc.saturating_add(1)); | ||
| CandidateCount::<T>::put(counter); | ||
|
|
||
| // update storage version | ||
| StorageVersion::<T>::put(StakingStorageVersion::V5); | ||
| log::info!("Completed staking migration to StakingStorageVersion::V5"); | ||
|
|
||
| T::DbWeight::get().reads_writes(counter.saturating_add(2).into(), 3) | ||
| } | ||
|
|
||
| #[cfg(feature = "try-runtime")] | ||
| pub(crate) fn post_migrate<T: Config>() -> Result<(), &'static str> { | ||
| assert_eq!(StorageVersion::<T>::get(), StakingStorageVersion::V5); | ||
| assert!(CandidateCount::<T>::get() > T::MinCollators::get()); | ||
| Ok(()) | ||
| } | ||
|
|
||
| pub(crate) mod old { | ||
| use super::*; | ||
| use frame_support::{decl_module, decl_storage}; | ||
| use sp_std::prelude::*; | ||
|
|
||
| decl_module! { | ||
| pub struct OldPallet<T: Config> for enum Call where origin: T::Origin {} | ||
| } | ||
|
|
||
| decl_storage! { | ||
| trait Store for OldPallet<T: Config> as ParachainStaking { | ||
| pub(crate) SelectedCandidates: Vec<T::AccountId>; | ||
wischli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.