-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Fix elections-phragmen and proxy issue #7040
Changes from 1 commit
dd4607b
6bd6221
57de14e
684802e
70852fa
4b7d0a6
77caa5c
06a0aa0
9943042
f9bd4a3
f9ea73a
24c416b
10e3687
4495ead
3c1a2ef
1b95224
2c677c2
d2ec181
a628850
f6189d5
e812815
498376c
d9b2204
4691703
88db61d
b4e2a7c
c871c81
12c18d5
f900b68
6c942b4
8e3c2eb
e674a60
a99bebc
f5700cf
0564e59
60d7d38
1b48d0d
960a474
19e9436
76cb36f
820d76f
4caea9f
0c1043f
df267fa
1621131
c79b522
50fa257
8bd074f
29880e4
d78f6bb
5d09983
6668ac1
3dd01d8
694e42a
cf94f49
ea69a54
b2f36bd
1fd2b08
585e599
4b9b207
ea17535
4b34e72
ecb0e4e
e810cc7
e650c02
8742865
d6de615
6cae3da
3c0d341
3ca1590
9c9819b
68ff142
797d04c
73a3537
98f349e
9454a68
c750f74
e11a216
1e2c8e9
583aa82
dca4bd5
c90d25a
586c61c
0a0ef71
a205401
63a4c56
ec067c9
5dab8bc
32cb6c1
38881e0
e4d7464
79d1d5b
7d95b15
ba12aec
673aed7
99f5fd2
92dbabe
c688a6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Changelog | ||
| All notable changes to this crate will be documented in this file. | ||
|
|
||
| The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
| and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
|
||
| ## [Unreleased] | ||
|
|
||
| ### Added | ||
| [Add slashing events to elections-phragmen](https://github.com/paritytech/substrate/pull/7543) | ||
|
|
||
| ### Changed | ||
|
|
||
| ### Fixed | ||
| [Don't slash all outgoing members](https://github.com/paritytech/substrate/pull/7394) | ||
| [Fix wrong outgoing calculation in election](https://github.com/paritytech/substrate/pull/7384) | ||
|
|
||
| ### Security | ||
| \[**Needs Migration**\] [Fix elections-phragmen and proxy issue + Record deposits on-chain](https://github.com/paritytech/substrate/pull/7040) | ||
|
|
||
| ## [2.0.0] - 2020-09-2020 | ||
|
|
||
| Initial version from which version tracking has begun. | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| [package] | ||
| name = "pallet-elections-phragmen" | ||
| version = "2.0.0" | ||
| version = "3.0.0" | ||
| authors = ["Parity Technologies <[email protected]>"] | ||
| edition = "2018" | ||
| license = "Apache-2.0" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,95 +127,88 @@ type NegativeImbalanceOf<T> = | |
| /// Helper functions for migrations of this module. | ||
| pub mod migrations { | ||
| use super::*; | ||
| use frame_support::{migration::StorageKeyIterator, Twox64Concat}; | ||
|
|
||
| /// Migrate from the old legacy voting bond (fixed) to the new one (per-vote dynamic). | ||
| /// | ||
| /// Will only be triggered if storage version is V1. | ||
| pub fn migrate_voters_to_recorded_deposit<T: Trait>(old_deposit: BalanceOf<T>) -> Weight { | ||
| if <Module<T>>::pallet_storage_version() == StorageVersion::V1 { | ||
| let mut count = 0; | ||
| <StorageKeyIterator<T::AccountId, (BalanceOf<T>, Vec<T::AccountId>), Twox64Concat>>::new( | ||
| <Voting<T>>::module_prefix(), | ||
| b"Voting", | ||
| ) | ||
| .for_each(|(who, (stake, votes))| { | ||
| // Insert a new value into the same location, thus no need to do `.drain()`. | ||
| let deposit = old_deposit; | ||
| let voter = Voter { votes, stake, deposit }; | ||
| <Voting<T>>::insert(who, voter); | ||
| count += 1; | ||
| }); | ||
| use frame_support::{ | ||
| traits::{PalletVersion, GetPalletVersion}, | ||
| Twox64Concat, | ||
| migration::StorageKeyIterator, | ||
| }; | ||
|
|
||
| PalletStorageVersion::put(StorageVersion::V2RecordedDeposit); | ||
| frame_support::debug::info!( | ||
| "🏛 pallet-elections-phragmen: {} voters migrated to V2PerVoterDeposit.", | ||
| count, | ||
| ); | ||
| Weight::max_value() | ||
| pub fn migrate_to_3_0_0<T: Trait>(old_voter_bond: BalanceOf<T>, old_candidacy_bond: BalanceOf<T>) -> Weight { | ||
| let current_version = <Module<T> as GetPalletVersion>::current_version(); | ||
| let maybe_storage_version = <Module<T> as GetPalletVersion>::storage_version(); | ||
|
|
||
| if current_version == PalletVersion::new(3, 0, 0) { | ||
|
||
| match maybe_storage_version { | ||
| Some(storage_version) if storage_version == PalletVersion::new(2, 0, 0) => { | ||
kianenigma marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| migrate_voters_to_recorded_deposit::<T>(old_voter_bond); | ||
| migrate_candidates_to_recorded_deposit::<T>(old_candidacy_bond); | ||
| migrate_runners_up_to_recorded_deposit::<T>(old_candidacy_bond); | ||
| migrate_members_to_recorded_deposit::<T>(old_candidacy_bond); | ||
| Weight::max_value() | ||
| }, | ||
| _ => { | ||
| 0 | ||
| } | ||
| } | ||
| } else { | ||
| frame_support::debug::warn!( | ||
| "🏛 pallet-elections-phragmen: Tried to run migration but PalletStorageVersion is \ | ||
| updated to V2. This code probably needs to be removed now.", | ||
| ); | ||
| 0 | ||
| } | ||
| } | ||
|
|
||
| /// Migrate from the old legacy voting bond (fixed) to the new one (per-vote dynamic). | ||
| /// | ||
| /// Will only be triggered if storage version is V1. | ||
| pub fn migrate_voters_to_recorded_deposit<T: Trait>(old_deposit: BalanceOf<T>) { | ||
| let mut count = 0; | ||
| <StorageKeyIterator<T::AccountId, (BalanceOf<T>, Vec<T::AccountId>), Twox64Concat>>::new( | ||
| <Voting<T>>::module_prefix(), | ||
| b"Voting", | ||
| ) | ||
| .for_each(|(who, (stake, votes))| { | ||
| // Insert a new value into the same location, thus no need to do `.drain()`. | ||
| let deposit = old_deposit; | ||
| let voter = Voter { votes, stake, deposit }; | ||
| <Voting<T>>::insert(who, voter); | ||
| count += 1; | ||
| }); | ||
| } | ||
|
|
||
| /// Migrate all candidates to recorded deposit. | ||
| /// | ||
| /// Will only be triggered if storage version is V1. | ||
| pub fn migrate_candidates_to_recorded_deposit<T: Trait>(old_deposit: BalanceOf<T>) -> Weight { | ||
| if <Module<T>>::pallet_storage_version() == StorageVersion::V1 { | ||
| let old_candidates = frame_support::migration::take_storage_value::<Vec<T::AccountId>>( | ||
| <Voting<T>>::module_prefix(), | ||
| b"Candidates", | ||
| &[], | ||
| ) | ||
| .unwrap_or_default(); | ||
| let new_candidates = old_candidates | ||
| .into_iter() | ||
| .map(|c| (c, old_deposit)) | ||
| .collect::<Vec<_>>(); | ||
| <Candidates<T>>::put(new_candidates); | ||
| Weight::max_value() | ||
| } else { | ||
| frame_support::debug::warn!( | ||
| "🏛 pallet-elections-phragmen: Tried to run migration but PalletStorageVersion is \ | ||
| updated. This code probably needs to be removed now.", | ||
| ); | ||
| 0 | ||
| } | ||
| pub fn migrate_candidates_to_recorded_deposit<T: Trait>(old_deposit: BalanceOf<T>) { | ||
| let old_candidates = frame_support::migration::take_storage_value::<Vec<T::AccountId>>( | ||
| <Voting<T>>::module_prefix(), | ||
| b"Candidates", | ||
| &[], | ||
| ) | ||
| .unwrap_or_default(); | ||
| let new_candidates = old_candidates | ||
| .into_iter() | ||
| .map(|c| (c, old_deposit)) | ||
| .collect::<Vec<_>>(); | ||
| <Candidates<T>>::put(new_candidates); | ||
| } | ||
|
|
||
| pub fn migrate_members_to_recorded_deposit<T: Trait>(deposit: BalanceOf<T>) -> Weight { | ||
| if <Module<T>>::pallet_storage_version() == StorageVersion::V1 { | ||
| let _ = <Members<T>>::translate::<Vec<(T::AccountId, BalanceOf<T>)>, _>( | ||
| |maybe_old_members| { | ||
| maybe_old_members.map(|old_members| { | ||
| frame_support::debug::info!( | ||
| "migrated {} member accounts.", | ||
| old_members.len() | ||
| ); | ||
| old_members | ||
| .into_iter() | ||
| .map(|(who, stake)| SeatHolder { | ||
| who, | ||
| stake, | ||
| deposit, | ||
| }) | ||
| .collect::<Vec<_>>() | ||
| }) | ||
| }, | ||
| ); | ||
| Weight::max_value() | ||
| } else { | ||
| frame_support::debug::warn!( | ||
| "🏛 pallet-elections-phragmen: Tried to run migration but PalletStorageVersion is \ | ||
| updated. This code probably needs to be removed now.", | ||
| ); | ||
| 0 | ||
| } | ||
| pub fn migrate_members_to_recorded_deposit<T: Trait>(deposit: BalanceOf<T>) { | ||
| let _ = <Members<T>>::translate::<Vec<(T::AccountId, BalanceOf<T>)>, _>( | ||
| |maybe_old_members| { | ||
| maybe_old_members.map(|old_members| { | ||
| frame_support::debug::info!( | ||
| "migrated {} member accounts.", | ||
| old_members.len() | ||
| ); | ||
| old_members | ||
| .into_iter() | ||
| .map(|(who, stake)| SeatHolder { | ||
| who, | ||
| stake, | ||
| deposit, | ||
| }) | ||
| .collect::<Vec<_>>() | ||
| }) | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| pub fn migrate_runners_up_to_recorded_deposit<T: Trait>(deposit: BalanceOf<T>) -> Weight { | ||
|
|
@@ -2705,7 +2698,7 @@ mod tests { | |
| assert_err_with_weight!( | ||
| Elections::remove_member(Origin::root(), 4, false), | ||
| Error::<Test>::InvalidReplacement, | ||
| Some(33489000) // only thing that matters for now is that it is NOT the full block. | ||
| Some(34042000) // only thing that matters for now is that it is NOT the full block. | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.