-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Adds MaxRank Config in pallet-core-fellowship
#3393
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
45 commits
Select commit
Hold shift + click to select a range
2e527a3
adds max_rank()
28cdd10
modify original test cases
277345e
includes prdoc
696aafb
add higher rank
5a6a64f
fix benchmark
6f78f77
Merge branch 'master' into ddc-max-rank
4117b94
xcm & salary
26e9a15
Merge branch 'master' into ddc-max-rank
1352159
benchmaek: set_params
d72a5bd
adjust promote benchmark
1cd019b
Merge branch 'master' into ddc-max-rank
72ecddb
revised implementation
083669a
Merge branch 'master' into ddc-max-rank
8a5c550
westend + fmt
abc2092
fix benchmarks
6d77c6c
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
dd0e5a9
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
afe16a5
init migration
4e53b70
Merge branch 'ddc-max-rank' of https://github.com/Doordashcon/polkado…
a746913
remove migration test
23a0d06
no truncate
e4fc2a1
remove nesting
548b0f7
Merge branch 'master' into ddc-max-rank
11c73be
adds header
9eb769f
Merge branch 'master' into ddc-max-rank
a93fdca
MigrateToV1>>>
7da28ff
doc update Migration to MigrateToV1
252d152
westend core pallet migration
fb1a240
Merge branch 'master' into ddc-max-rank
137b5f4
Merge branch 'master' into ddc-max-rank
2aca81a
doc add westend-collective
8cebd55
Merge branch 'master' into ddc-max-rank
4d798a4
nit
fc72258
max_rank in Ranked Member not needed
093232f
remove Config salary pallet test
3f21602
ranked remove MaxRank in test
6c76c06
Merge branch 'master' into ddc-max-rank
f9724a2
clippy
105109c
Merge branch 'master' into ddc-max-rank
25f0d06
similar import for benchmarks
2afaa8f
sp_runtime::bounded_vec
ee9f047
sp_core
4a31d0a
back to BoundedVec::try_from..
5071cb9
Update substrate/frame/core-fellowship/src/lib.rs
bkchr 9af1d88
Merge branch 'master' into ddc-max-rank
bkchr 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 | ||
| # See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json | ||
|
|
||
| title: Add `MaxRank` Config to `pallet-core-fellowship` | ||
|
|
||
| doc: | ||
| - audience: Runtime User | ||
| description: | | ||
| This PR adds a new Config `MaxRank` to the core fellowship pallet. Initially, the maximum rank was set to IX (Grand Master) on the core-fellowship pallet, corresponding to the establishment of the Technical Fellowship and setting the default member count to nine. However, with the introduction of new collectives, this maximum rank is expected to evolve. | ||
|
|
||
| crates: | ||
| - name: pallet-core-fellowship |
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,111 @@ | ||
| // This file is part of Substrate. | ||
|
|
||
| // Copyright (C) Parity Technologies (UK) Ltd. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| //! Storage migrations for the core-fellowship pallet. | ||
| use super::*; | ||
Doordashcon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| use frame_support::{ | ||
| pallet_prelude::*, | ||
| storage_alias, | ||
| traits::{DefensiveTruncateFrom, UncheckedOnRuntimeUpgrade}, | ||
| BoundedVec, | ||
| }; | ||
|
|
||
| #[cfg(feature = "try-runtime")] | ||
| use sp_runtime::TryRuntimeError; | ||
|
|
||
| mod v0 { | ||
| use frame_system::pallet_prelude::BlockNumberFor; | ||
|
|
||
| use super::*; | ||
|
|
||
| #[derive(Encode, Decode, Eq, PartialEq, Clone, TypeInfo, MaxEncodedLen, RuntimeDebug)] | ||
| pub struct ParamsType<Balance, BlockNumber, const RANKS: usize> { | ||
| pub active_salary: [Balance; RANKS], | ||
| pub passive_salary: [Balance; RANKS], | ||
| pub demotion_period: [BlockNumber; RANKS], | ||
| pub min_promotion_period: [BlockNumber; RANKS], | ||
| pub offboard_timeout: BlockNumber, | ||
| } | ||
|
|
||
| impl<Balance: Default + Copy, BlockNumber: Default + Copy, const RANKS: usize> Default | ||
| for ParamsType<Balance, BlockNumber, RANKS> | ||
| { | ||
| fn default() -> Self { | ||
| Self { | ||
| active_salary: [Balance::default(); RANKS], | ||
| passive_salary: [Balance::default(); RANKS], | ||
| demotion_period: [BlockNumber::default(); RANKS], | ||
| min_promotion_period: [BlockNumber::default(); RANKS], | ||
| offboard_timeout: BlockNumber::default(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Number of available ranks from old version. | ||
| pub(crate) const RANK_COUNT: usize = 9; | ||
|
|
||
| pub type ParamsOf<T, I> = ParamsType<<T as Config<I>>::Balance, BlockNumberFor<T>, RANK_COUNT>; | ||
|
|
||
| /// V0 type for [`crate::Params`]. | ||
| #[storage_alias] | ||
| pub type Params<T: Config<I>, I: 'static> = | ||
| StorageValue<Pallet<T, I>, ParamsOf<T, I>, ValueQuery>; | ||
| } | ||
|
|
||
| pub struct MigrateToV1<T, I = ()>(PhantomData<(T, I)>); | ||
| impl<T: Config<I>, I: 'static> UncheckedOnRuntimeUpgrade for MigrateToV1<T, I> { | ||
| #[cfg(feature = "try-runtime")] | ||
| fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> { | ||
| ensure!( | ||
| T::MaxRank::get() >= v0::RANK_COUNT as u32, | ||
| "pallet-core-fellowship: new bound should not truncate" | ||
| ); | ||
| Ok(Default::default()) | ||
| } | ||
|
|
||
| fn on_runtime_upgrade() -> frame_support::weights::Weight { | ||
| // Read the old value from storage | ||
| let old_value = v0::Params::<T, I>::take(); | ||
| // Write the new value to storage | ||
| let new = crate::ParamsType { | ||
| active_salary: BoundedVec::defensive_truncate_from(old_value.active_salary.to_vec()), | ||
| passive_salary: BoundedVec::defensive_truncate_from(old_value.passive_salary.to_vec()), | ||
| demotion_period: BoundedVec::defensive_truncate_from( | ||
| old_value.demotion_period.to_vec(), | ||
| ), | ||
| min_promotion_period: BoundedVec::defensive_truncate_from( | ||
| old_value.min_promotion_period.to_vec(), | ||
| ), | ||
| offboard_timeout: old_value.offboard_timeout, | ||
| }; | ||
| crate::Params::<T, I>::put(new); | ||
| T::DbWeight::get().reads_writes(1, 1) | ||
| } | ||
| } | ||
|
|
||
| /// [`UncheckedOnRuntimeUpgrade`] implementation [`MigrateToV1`] wrapped in a | ||
| /// [`VersionedMigration`](frame_support::migrations::VersionedMigration), which ensures that: | ||
| /// - The migration only runs once when the on-chain storage version is 0 | ||
| /// - The on-chain storage version is updated to `1` after the migration executes | ||
| /// - Reads/Writes from checking/settings the on-chain storage version are accounted for | ||
| pub type MigrateV0ToV1<T, I> = frame_support::migrations::VersionedMigration< | ||
| 0, // The migration will only execute when the on-chain storage version is 0 | ||
| 1, // The on-chain storage version will be set to 1 after the migration is complete | ||
| MigrateToV1<T, I>, | ||
| crate::pallet::Pallet<T, I>, | ||
| <T as frame_system::Config>::DbWeight, | ||
| >; | ||
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.