-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Used CountedStorageMap in pallet-staking #10233
Changes from all commits
662fffe
48a4825
da2d7ec
31f7bd7
a8c2f16
01a605d
2c192d8
c2f7577
b332858
d771e4a
e449fe5
65d7d02
b9d0a88
9b21bef
d79d380
16d6a44
190ec8e
41f8dae
3a0500f
fac8882
bf1bc0a
36115cb
de685ff
d07414f
256ac95
fa56998
a437c17
b7e8047
da0f59f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,10 +70,22 @@ pub mod v8 { | |
|
|
||
| pub mod v7 { | ||
| use super::*; | ||
| use frame_support::generate_storage_alias; | ||
|
|
||
| generate_storage_alias!(Staking, CounterForValidators => Value<u32>); | ||
gui1117 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| generate_storage_alias!(Staking, CounterForNominators => Value<u32>); | ||
|
|
||
| pub fn pre_migrate<T: Config>() -> Result<(), &'static str> { | ||
| assert!(CounterForValidators::<T>::get().is_zero(), "CounterForValidators already set."); | ||
| assert!(CounterForNominators::<T>::get().is_zero(), "CounterForNominators already set."); | ||
| assert!( | ||
| CounterForValidators::get().unwrap().is_zero(), | ||
| "CounterForValidators already set." | ||
| ); | ||
| assert!( | ||
| CounterForNominators::get().unwrap().is_zero(), | ||
| "CounterForNominators already set." | ||
| ); | ||
| assert!(Validators::<T>::count().is_zero(), "Validators already set."); | ||
| assert!(Nominators::<T>::count().is_zero(), "Nominators already set."); | ||
ayevbeosa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert!(StorageVersion::<T>::get() == Releases::V6_0_0); | ||
| Ok(()) | ||
| } | ||
|
|
@@ -83,8 +95,8 @@ pub mod v7 { | |
| let validator_count = Validators::<T>::iter().count() as u32; | ||
| let nominator_count = Nominators::<T>::iter().count() as u32; | ||
|
|
||
| CounterForValidators::<T>::put(validator_count); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is technically making this migration code WRONG. Either remove it completely, or make sure it is correct. we don't enforce this now, but a correct way would be to make sure this migration code stays correct over time. That is, it should have its own storage items and not depend on the pallet types. In this case, you need to create (mock) storage types via Or, we need some special If all of this is too much, with despair and sadness, I am also fine with just removing the migration code altogether. But the long term correct thing to do is as I said above.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you help with the correct implementation details on how to write the migration code, I am still new to the Substrate repo.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can look into other use cases of and now you have
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is staking pallet using the pallet macro in v7 ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this question for me or @kianenigma
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah it was already migrated. Then the very pedantic course of action would be to accept the prefix as the argument of the migration function, but I will be fine with skipping it since the migration code is already at risk to becoming outdated (since it depends on |
||
| CounterForNominators::<T>::put(nominator_count); | ||
| CounterForValidators::put(validator_count); | ||
| CounterForNominators::put(nominator_count); | ||
|
|
||
| StorageVersion::<T>::put(Releases::V7_0_0); | ||
| log!(info, "Completed staking migration to Releases::V7_0_0"); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.