Skip to content
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

Fungibles: migrate Democracy pallet #1861

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open

Conversation

pgherveou
Copy link
Contributor

@pgherveou pgherveou commented Oct 12, 2023

Partial for #226

The (Reservable/Lockable)Currency traits are deprecated after this paritytech/substrate#12951 in favour of the fungible traits.

A few things have changed:

  • ReservableCurrency::(reserve/unreserve) becomes fungible::MutateHold::(hold/release)
  • LockableCurrency::(extend_lock/remove_lock/set_lock) becomes fungible::MutateFreeze::(extend_freeze/thaw/set_freeze)

Holds and Freezes

Holds are roughly analagous to reserves, but are now explicitly designed to be infallibly slashed. They do not contribute to the ED but do require a provider reference, removing any possibility of account reference counting from being problematic for a slash. They are also always named, ensuring different holds do not accidentally slash each other's balances.

Freezes are essentially the same as locks, except that they overlap with Holds. Since Holds are designed to be infallibly slashed, this means that any logic using a Freeze must handle the possibility of the frozen amount being reduced, potentially to zero. A permissionless function should be provided in order to allow bookkeeping to be updated in this instance.

Both Holds and Freezes require an identifier which is configurable and is expected to be an enum aggregated across all pallet instances of the runtime.

In the Pallet Democracy context we define HoldReason::Proposal and FreezeReason::Proposal.

/// A reason for this pallet placing a hold on funds.
#[pallet::composite_enum]
pub enum HoldReason {
  /// Funds are held when a proposal is submitted and are released when the proposal is
  /// tabled. If the proposal is vetoed and blacklisted, the deposit is slashed.
  Proposal,
}

/// A reason for this pallet placing a freeze on funds.
#[pallet::composite_enum]
pub enum FreezeReason {
  /// Funds are frozen upon casting a vote. They are subsequently unfrozen either
  /// when the vote is cancelled or after the specified lock period has elapsed (see
  /// [`conviction::Conviction`]).
  Vote,
}

Upgrade notes

The pallet_democracy::Config trait now requires new type RuntimeHoldReason and RuntimeFreezeReason:

impl pallet_democracy::Config for Runtime {
-  type Currency = pallet_balances::Pallet<Self>;
+  type Fungible = Balances;
+  type RuntimeHoldReason = RuntimeHoldReason;
+  type RuntimeFreezeReason = RuntimeFreezeReason;
}

Also, construct_runtime needs pallet_democracy::HoldReason and : pallet_democracy::FreezeReason:

construct_runtime!(
	pub enum Runtime
	{
		...
		Democracy: pallet_democracy::{Pallet, Call, Storage, Config<T>, Event<T>, HoldReason, FreezeReason },
		...
	}
)

Migration

A (multi-block) migration is provided with this PR, which will convert all existing locks to holds and freezes.

@pgherveou pgherveou added T1-FRAME This PR/Issue is related to core FRAME, the framework. D0-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder. labels Oct 18, 2023
@@ -1065,7 +1067,7 @@ impl pallet_democracy::Config for Runtime {
// only do it once and it lasts only for the cool-off period.
type VetoOrigin = pallet_collective::EnsureMember<AccountId, TechnicalCollective>;
type CooloffPeriod = CooloffPeriod;
type Slash = Treasury;
type Slash = ();
Copy link
Contributor Author

@pgherveou pgherveou Oct 19, 2023

Choose a reason for hiding this comment

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

We may want to adapt treasury to accept slashes from pallet_democracy here...

@pgherveou pgherveou marked this pull request as ready for review October 19, 2023 13:39
@pgherveou pgherveou requested a review from a team October 19, 2023 13:39
@ggwpez
Copy link
Member

ggwpez commented Mar 20, 2024

Could be something you encode in the MigrationIdentifier type somehow?

Yea, we can make wrapper structs. I wrote these interfaces to act as lowers building blocks, so adding convenience ontop should be fine.

Btw what docs did you find? Just asking to see where people look for docs.

@pgherveou
Copy link
Contributor Author

I used @juangirini example mbm PR

serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Mar 26, 2024
…tech#1861)

* MaxValues limit for storage maps in the pallet-bridge-grandpa

* remove use from the future PR
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Mar 27, 2024
…tech#1861)

* MaxValues limit for storage maps in the pallet-bridge-grandpa

* remove use from the future PR
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 8, 2024
…tech#1861)

* MaxValues limit for storage maps in the pallet-bridge-grandpa

* remove use from the future PR
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 8, 2024
…tech#1861)

* MaxValues limit for storage maps in the pallet-bridge-grandpa

* remove use from the future PR
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 8, 2024
…tech#1861)

* MaxValues limit for storage maps in the pallet-bridge-grandpa

* remove use from the future PR
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 8, 2024
…tech#1861)

* MaxValues limit for storage maps in the pallet-bridge-grandpa

* remove use from the future PR
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 8, 2024
…tech#1861)

* MaxValues limit for storage maps in the pallet-bridge-grandpa

* remove use from the future PR
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
…tech#1861)

* MaxValues limit for storage maps in the pallet-bridge-grandpa

* remove use from the future PR
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
…tech#1861)

* MaxValues limit for storage maps in the pallet-bridge-grandpa

* remove use from the future PR
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
…tech#1861)

* MaxValues limit for storage maps in the pallet-bridge-grandpa

* remove use from the future PR
@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: test-linux-stable 1/3
Logs: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/5841995

serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
…tech#1861)

* MaxValues limit for storage maps in the pallet-bridge-grandpa

* remove use from the future PR
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
…tech#1861)

* MaxValues limit for storage maps in the pallet-bridge-grandpa

* remove use from the future PR
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
…tech#1861)

* MaxValues limit for storage maps in the pallet-bridge-grandpa

* remove use from the future PR
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 10, 2024
…tech#1861)

* MaxValues limit for storage maps in the pallet-bridge-grandpa

* remove use from the future PR
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 10, 2024
…tech#1861)

* MaxValues limit for storage maps in the pallet-bridge-grandpa

* remove use from the future PR
bkchr pushed a commit that referenced this pull request Apr 10, 2024
* MaxValues limit for storage maps in the pallet-bridge-grandpa

* remove use from the future PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D0-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder. T1-FRAME This PR/Issue is related to core FRAME, the framework.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants