This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 371
Add Ability to Add/Remove Invulnerable Collators #2596
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
9c6099e
add add and remove invulnerable dispatchables
joepetrowski 3b8fe1a
add migration
joepetrowski 4af873f
fix benchmarking code
joepetrowski 2fac7d8
add weights
joepetrowski 9d49629
add migration to runtimes
joepetrowski 68a91c3
merge master
joepetrowski de60685
clippy
joepetrowski 5235d44
pass SafeCallFilter
joepetrowski 1332667
make try-runtime work
joepetrowski c89c44d
Merge remote-tracking branch 'origin' into joe-addremove-invulnerable
joepetrowski 37c853c
typos
joepetrowski d5e97ba
better insert and added test
joepetrowski 556e31c
merge master
joepetrowski a526fb4
merge master
joepetrowski 1580296
fix try-runtime update
joepetrowski dfcbd35
Apply suggestions from code review
joepetrowski 7a522fe
Update pallets/collator-selection/src/migration.rs
joepetrowski e4c823e
check events in test
joepetrowski 0a6b072
Merge remote-tracking branch 'origin' into joe-addremove-invulnerable
joepetrowski c415c76
Update pallets/collator-selection/src/migration.rs
joepetrowski fc18345
just dispatchresult
joepetrowski 28bec18
Merge remote-tracking branch 'origin' into joe-addremove-invulnerable
joepetrowski 5bacaaf
only sp_std for try-runtime
joepetrowski 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| [package] | ||
| authors = ["Anonymous"] | ||
| description = "Simple staking pallet with a fixed stake." | ||
| authors = ["Parity Technologies <[email protected]>"] | ||
| description = "Simple pallet to select collators for a parachain." | ||
| edition = "2021" | ||
| homepage = "https://substrate.io" | ||
| license = "Apache-2.0" | ||
|
|
||
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,91 @@ | ||
| // Copyright Parity Technologies (UK) Ltd. | ||
| // This file is part of Polkadot. | ||
|
|
||
| // Polkadot 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. | ||
|
|
||
| // Polkadot 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 Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| //! A module that is responsible for migration of storage for Collator Selection. | ||
|
|
||
| use super::*; | ||
| use frame_support::{log, traits::OnRuntimeUpgrade}; | ||
|
|
||
| /// Version 1 Migration | ||
| /// This migration ensures that any existing `Invulnerables` storage lists are sorted. | ||
| pub mod v1 { | ||
| use super::*; | ||
| use frame_support::pallet_prelude::*; | ||
| #[cfg(feature = "try-runtime")] | ||
| use sp_std::prelude::*; | ||
|
|
||
| pub struct MigrateToV1<T>(sp_std::marker::PhantomData<T>); | ||
| impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> { | ||
| fn on_runtime_upgrade() -> Weight { | ||
| let onchain_version = Pallet::<T>::on_chain_storage_version(); | ||
| if onchain_version == 0 { | ||
| let invulnerables_len = Invulnerables::<T>::get().to_vec().len(); | ||
| <Invulnerables<T>>::mutate(|invulnerables| { | ||
| invulnerables.sort(); | ||
| }); | ||
|
|
||
| StorageVersion::new(1).put::<Pallet<T>>(); | ||
| log::info!( | ||
| target: LOG_TARGET, | ||
| "Sorted {} Invulnerables, upgraded storage to version 1", | ||
| invulnerables_len, | ||
| ); | ||
| // Similar complexity to `set_invulnerables` (put storage value) | ||
| // Plus 1 read for length, 1 read for `onchain_version`, 1 write to put version | ||
| T::WeightInfo::set_invulnerables(invulnerables_len as u32) | ||
| .saturating_add(T::DbWeight::get().reads_writes(2, 1)) | ||
| } else { | ||
| log::info!( | ||
| target: LOG_TARGET, | ||
| "Migration did not execute. This probably should be removed" | ||
| ); | ||
| T::DbWeight::get().reads(1) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "try-runtime")] | ||
| fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::DispatchError> { | ||
| let number_of_invulnerables = Invulnerables::<T>::get().to_vec().len(); | ||
| Ok((number_of_invulnerables as u32).encode()) | ||
| } | ||
|
|
||
| #[cfg(feature = "try-runtime")] | ||
| fn post_upgrade(number_of_invulnerables: Vec<u8>) -> Result<(), sp_runtime::DispatchError> { | ||
| let stored_invulnerables = Invulnerables::<T>::get().to_vec(); | ||
| let mut sorted_invulnerables = stored_invulnerables.clone(); | ||
| sorted_invulnerables.sort(); | ||
| assert_eq!( | ||
| stored_invulnerables, sorted_invulnerables, | ||
| "after migration, the stored invulnerables should be sorted" | ||
| ); | ||
|
|
||
| let number_of_invulnerables: u32 = Decode::decode( | ||
| &mut number_of_invulnerables.as_slice(), | ||
| ) | ||
| .expect("the state parameter should be something that was generated by pre_upgrade"); | ||
| let stored_invulnerables_len = stored_invulnerables.len() as u32; | ||
| assert_eq!( | ||
| number_of_invulnerables, stored_invulnerables_len, | ||
| "after migration, there should be the same number of invulnerables" | ||
| ); | ||
|
|
||
| let onchain_version = Pallet::<T>::on_chain_storage_version(); | ||
joepetrowski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| frame_support::ensure!(onchain_version >= 1, "must_upgrade"); | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.