-
Notifications
You must be signed in to change notification settings - Fork 2.6k
migration(elections-phragmen): unreserve deposits and clear locks #14218
migration(elections-phragmen): unreserve deposits and clear locks #14218
Conversation
…ections-phragmen-unlock-and-unreserve-funds-migration
…ections-phragmen-unlock-and-unreserve-funds-migration
I just found a way to handle the Balances types cleaner. Switching this to a draft while I improve that, also going to add some unit tests. |
frame/elections-phragmen/src/migrations/unlock_and_unreserve_all_funds.rs
Outdated
Show resolved
Hide resolved
…ections-phragmen-unlock-and-unreserve-funds-migration
…ections-phragmen-unlock-and-unreserve-funds-migration
.len() | ||
.saturating_add(runner_ups.len()) | ||
.saturating_add(candidates.len()) | ||
.saturating_add(voters_len.saturating_mul(T::MaxVotesPerVoter::get() as usize)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why you multiply T::MaxVotesPerVoter
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each Voter
contains a Vec
called votes
up to size MaxVotesPerVoter
.
I guessed that the weight of the read scales with the size of the Vec, but maybe that's incorrect if it can all be loaded into memory in one read regardless?
|
||
// Get the total amount deposited (Members, RunnerUps, Candidates and Voters all can have | ||
// deposits). | ||
let account_deposited_sums: BTreeMap<T::AccountId, BalanceOf<T>> = members |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be pedantic about the variable name, we are voting here, not staking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's referred to as a stake in the pallet:
//! update the vote's stake ([`Voter::stake`]). After a round, votes are kept and might still be |
substrate/frame/elections-phragmen/src/lib.rs
Lines 152 to 153 in a57508e
/// The amount of stake placed on this vote. | |
pub stake: Balance, |
Still happy to change it to locked
though if you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to merge this for now in the interests of trying to get the migrations ready for 1.0, but let me know if you'd still like me to change it and I will open another pr :)
frame/elections-phragmen/src/migrations/unlock_and_unreserve_all_funds.rs
Outdated
Show resolved
Hide resolved
frame/elections-phragmen/src/migrations/unlock_and_unreserve_all_funds.rs
Show resolved
Hide resolved
frame/elections-phragmen/src/migrations/unlock_and_unreserve_all_funds.rs
Outdated
Show resolved
Hide resolved
frame/elections-phragmen/src/migrations/unlock_and_unreserve_all_funds.rs
Outdated
Show resolved
Hide resolved
frame/elections-phragmen/src/migrations/unlock_and_unreserve_all_funds.rs
Outdated
Show resolved
Hide resolved
frame/elections-phragmen/src/migrations/unlock_and_unreserve_all_funds.rs
Show resolved
Hide resolved
…ll_funds.rs Co-authored-by: Oliver Tale-Yazdi <[email protected]>
…ll_funds.rs Co-authored-by: Oliver Tale-Yazdi <[email protected]>
…gration' and 'liam-elections-phragmen-unlock-and-unreserve-funds-migration' of github.com:paritytech/substrate into liam-elections-phragmen-unlock-and-unreserve-funds-migration
…ections-phragmen-unlock-and-unreserve-funds-migration
…ll_funds.rs Co-authored-by: Oliver Tale-Yazdi <[email protected]>
bot merge |
Waiting for commit status. |
Merge cancelled due to error. Error: Github API says #14218 is not mergeable |
bot merge |
…ritytech#14218) * pre_upgrade hook wip * working pre_upgrade * simplify code * cleanup and document * return reads from get_account_deposited_and_staked_sums * improve comment * on_runtime_upgrade comment * post upgrade comment * use saturating_add * clippy * clean up balances * add tests * fix comment * oops * actually fix comment * fix std build * address pr comments * remove redundant comment * update comment * add comment * oliver comments from tips pallet pr * lint * remove need for do_pre/do_post runtime functions * generic dbweight * Update frame/elections-phragmen/src/migrations/unlock_and_unreserve_all_funds.rs Co-authored-by: Oliver Tale-Yazdi <[email protected]> * Update frame/elections-phragmen/src/migrations/unlock_and_unreserve_all_funds.rs Co-authored-by: Oliver Tale-Yazdi <[email protected]> * pr comments * remove useless check * feature gate log target * lint * Update frame/elections-phragmen/src/migrations/unlock_and_unreserve_all_funds.rs Co-authored-by: Oliver Tale-Yazdi <[email protected]> * add log for unexpected amounts --------- Co-authored-by: Oliver Tale-Yazdi <[email protected]>
Partial paritytech/polkadot-sdk#485
Overview
Adds a migration that unreserves all deposits and unlocks all stake held by the elections-phragmen pallet.
I've verified this works using
try-runtime-cli
and the latest Polkadot state (testing with Kusama state blocked by my last Q below).Details
elections-phragmen
contains 4 storage items containing information about balances to unreserve and unlock:Members
,RunnerUps
,Candidates
, andVoters
.Every storage item stores a deposit to unreserve, and just
Voters
contains a stake to unlock.pre_upgrade
collects pre-migration data useful for validating the migration was successful, and also checks the integrity of deposited and reserved balances.on_runtime_upgrade
unreserves and unlocks the balances.post_upgrade
checks that all expected locks were removed, and reserved balances were reduced by the expected amount.try-runtime-cli on-runtime-upgrade output
Questions for reviewers / todos:
This currently assumes that theelection_phragmen
pallet is part of the runtime. We need to run it for Kusama where it has already been removed from the runtime. What's the cleanest way to go about this?How do I calculate the weight of theremove_lock
andunreserve
calls?remove_lock
triggers someERROR main runtime::system: Logic error: Unexpected underflow in reducing consumer
error logs. I have verified that a non-zero lock always exists beforeremove_lock
is called, even when it results in this log. Are they safe to ignore?