Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

migration(democracy): unreserve deposits and clear locks #14226

Merged
merged 35 commits into from
Jun 13, 2023

Conversation

liamaharon
Copy link
Contributor

@liamaharon liamaharon commented May 25, 2023

Partial paritytech/polkadot-sdk#485

Overview

Adds a migration that unreserves all deposits and clears locks held by the democracy 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

democracy contains a DepositOf storage item containing all the amounts reserved by this pallet, and a Voters storage item containing all the accounts that have locks held in the context of this pallet.

pre_upgrade collects pre-migration data useful for validating the migration was successful, and also checks the integrity of deposited balances.

on_runtime_upgrade unreserves and unlocks the balances.

post_upgrade checks that no more locks exist for the pallet, and reserved balances were reduced by the expected amount.

try-runtime-cli on-runtime-upgrade logs

2023-06-13 16:54:30.693  INFO main runtime::democracy::migrations::unlock_and_unreserve_all_funds: Total accounts: 5364
2023-06-13 16:54:30.693  INFO main runtime::democracy::migrations::unlock_and_unreserve_all_funds: Total stake to unlock: 1179551847104532862
2023-06-13 16:54:30.693  INFO main runtime::democracy::migrations::unlock_and_unreserve_all_funds: Total deposit to unreserve: 25000000000000
2023-06-13 16:54:30.693  INFO main runtime::democracy::migrations::unlock_and_unreserve_all_funds: Bugged deposits: 1/21

Questions for reviewers / todos:

  • This currently assumes that the democracy 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 the remove_lock and unreserve calls?
  • remove_lock triggers some ERROR main runtime::system: Logic error: Unexpected underflow in reducing consumer error logs. I have verified that a non-zero lock always exists before remove_lock is called, even when it results in this log. Are they safe to ignore?

@liamaharon liamaharon requested a review from a team May 25, 2023 11:23
@liamaharon liamaharon changed the title migration(democracy): unreserve all deposits and unlock all stake migration(democracy): unreserve all deposits and clear locks May 25, 2023
@liamaharon liamaharon changed the title migration(democracy): unreserve all deposits and clear locks migration(democracy): unreserve deposits and clear locks May 25, 2023
@liamaharon liamaharon added A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit B1-note_worthy Changes should be noted in the release notes T1-runtime This PR/Issue is related to the topic “runtime”. labels May 25, 2023
@kianenigma kianenigma requested a review from a team May 25, 2023 14:42
@liamaharon
Copy link
Contributor Author

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.

@liamaharon liamaharon marked this pull request as draft May 26, 2023 11:31
@liamaharon liamaharon added A3-in_progress Pull request is in progress. No review needed at this stage. and removed A0-please_review Pull request needs code review. labels May 26, 2023
@liamaharon liamaharon added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels May 29, 2023
@liamaharon liamaharon marked this pull request as ready for review May 29, 2023 07:48
Copy link
Member

@ggwpez ggwpez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not super familiar with the pallet but LGTM.
Going to approve after checking on DotSama myself.

@paritytech-ci paritytech-ci requested a review from a team June 13, 2023 12:48
@paritytech-ci paritytech-ci requested a review from a team June 13, 2023 12:49
Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to post an example output of try-runtime prior to final ask for review.

liamaharon and others added 12 commits June 13, 2023 23:12
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
…h/substrate into liam-democracy-unreserve-funds
@liamaharon
Copy link
Contributor Author

bot merge

@paritytech-processbot paritytech-processbot bot merged commit 1c0204c into master Jun 13, 2023
@paritytech-processbot paritytech-processbot bot deleted the liam-democracy-unreserve-funds branch June 13, 2023 16:06
nathanwhit pushed a commit to nathanwhit/substrate that referenced this pull request Jul 19, 2023
…14226)

* unlock and unreserve all migration

* log total amount to unlock

* clippy

* clippy

* simplify balance types

* add tests

* fix comment

* fix std features

* remove redundant dev-dep

* address comments

* remove redundant std

* estimate weights

* fix comments

* fix tests

* clippy

* track democracy bugged deposits

* improve pre_migration logs

* oliver comments from tips pr

* run pre and post hooks in tests

* flexible dbweight type

* Update frame/democracy/src/migrations/unlock_and_unreserve_all_funds.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/democracy/src/migrations/unlock_and_unreserve_all_funds.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Update frame/democracy/src/migrations/unlock_and_unreserve_all_funds.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* docs

* Update frame/democracy/src/lib.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/democracy/src/migrations/unlock_and_unreserve_all_funds.rs

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* add log target

* fix visibility

* lint

* use log target

---------

Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B1-note_worthy Changes should be noted in the release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit T1-runtime This PR/Issue is related to the topic “runtime”.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants