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

Ensure correct variant count in Runtime[Hold/Freeze]Reason #1900

Merged
merged 23 commits into from
Oct 24, 2023

Conversation

kianenigma
Copy link
Contributor

@kianenigma kianenigma commented Oct 17, 2023

closes #1882

Breaking Changes

This PR introduces a new item to pallet_balances::Config:

trait Config {
++    type RuntimeFreezeReasons;
}

This value is only used to check it against type MaxFreeze. A similar check has been added for MaxHolds against RuntimeHoldReasons, which is already given to pallet_balances.

In all contexts, you should pass the real RuntimeFreezeReasons generated by construct_runtime to type RuntimeFreezeReasons. Passing () would also work, but it would imply that the runtime uses no freezes at all.

@kianenigma kianenigma added the T1-FRAME This PR/Issue is related to core FRAME, the framework. label Oct 17, 2023
@kianenigma kianenigma requested review from a team October 17, 2023 07:21
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
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.

If we have many of these lines up to migrate to DefaultConfig, it might be best to wait for that. Thoughts?

I think we would wait forever... i did some replacements and it seems to compile. Will push in a minute.

substrate/frame/support/src/traits/misc.rs Outdated Show resolved Hide resolved
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
@ggwpez ggwpez requested a review from a team October 17, 2023 10:21
substrate/frame/balances/src/lib.rs Show resolved Hide resolved
@@ -132,9 +138,10 @@ impl Config for Test {
type ReserveIdentifier = TestId;
type WeightInfo = ();
type RuntimeHoldReason = TestId;
type RuntimeFreezeReason = RuntimeFreezeReason;
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be TestId?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

probably me or oliver did too much copy pasta :D I will double check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually probably not, it should be the default one.

kianenigma and others added 7 commits October 18, 2023 10:13
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
@paritytech-ci paritytech-ci requested review from a team October 18, 2023 09:51
ggwpez and others added 2 commits October 18, 2023 12:16
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
@kianenigma kianenigma enabled auto-merge (squash) October 24, 2023 09:29
@kianenigma kianenigma merged commit 35eb133 into master Oct 24, 2023
12 checks passed
@kianenigma kianenigma deleted the kiz-variant-count branch October 24, 2023 10:01
ordian added a commit that referenced this pull request Oct 26, 2023
* tsv-disabling: (36 commits)
  Removed TODO from test-case for hard-coded delivery fee estimation (#2042)
  Expose collection attributes from `Inspect` trait (#1914)
  `polkadot-parachain-primitives` should not depend on `frame-support`. (#1897)
  [testnet] Align testnet system parachain runtimes using `RelayTreasuryLocation` and `SystemParachains` in the same way (#2023)
  Sort the benchmarks before listing them (#2026)
  publish pallet-root-testing (#2017)
  Contracts: Add benchmarks to include files (#2022)
  Small optimisation to `--profile dev` wasm builds (#1851)
  basic-authorship: Improve time recording and logging (#2010)
  Application Crypto and BEEFY Support for paired (ECDSA,BLS) crypto (#1815)
  [ci] Run check-rust-feature-propagation in pr and master (#2012)
  Improve features dev-ex (#1831)
  Remove obsolete comment. (#2008)
  Refactor candidates test in paras_inherent (#2004)
  PVF: Add worker check during tests and benches (#1771)
  Bump actions/setup-node from 3.8.1 to 4.0.0 (#1997)
  polkadot: enable tikv-jemallocator/unprefixed_malloc_on_supported_platforms (#2002)
  Make `IdentityInfo` generic in `pallet-identity` (#1661)
  Ensure correct variant count in `Runtime[Hold/Freeze]Reason` (#1900)
  `CheckWeight`: Add more logging (#1996)
  ...
s0me0ne-unkn0wn pushed a commit that referenced this pull request Oct 29, 2023
closes #1882

## Breaking Changes

This PR introduces a new item to `pallet_balances::Config`:

```diff
trait Config {
++    type RuntimeFreezeReasons;
}
```

This value is only used to check it against `type MaxFreeze`. A similar
check has been added for `MaxHolds` against `RuntimeHoldReasons`, which
is already given to `pallet_balances`.

In all contexts, you should pass the real `RuntimeFreezeReasons`
generated by `construct_runtime` to `type RuntimeFreezeReasons`. Passing
`()` would also work, but it would imply that the runtime uses no
freezes at all.

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
svyatonik added a commit to svyatonik/runtimes that referenced this pull request Nov 3, 2023
@Polkadot-Forum
Copy link

This pull request has been mentioned on Polkadot Forum. There might be relevant details there:

https://forum.polkadot.network/t/polkadot-release-analysis-v1-3-0/4614/1

HCastano added a commit to entropyxyz/entropy-core that referenced this pull request Jan 19, 2024
HCastano added a commit to entropyxyz/entropy-core that referenced this pull request Jan 23, 2024
* Get `entropy-shared` compiling with updated deps

* Fix `entropy-shared` build for `wasm-no-std`

* Make `pallet-staking-extension` compile

Starts introducing some of the changes brought in by
paritytech/polkadot-sdk#1484.

* Introduce staking changes from paritytech/substrate#12970

* Add RuntimeFreezeReason from paritytech/polkadot-sdk#1900

* Re-map errors in staking extension pallet

* Bump `pallet-programs`

* Missed a crate dep for staking extension

* Remove commented out code

* Get `pallet-relayer` compiling

* Fix relayer test compilation

* Fix `pallet-free-tx`'s tests

* Reorder config types

* Bump `pallet-propagation` dependencies

* Bump `pallet-slashing` dependencies

* Bump `pallet-transaction-pause`

This includes the deprecation of `Balances::transfer` from
paritytech/polkadot-sdk#1226.

* TaploFmt

* Use `StakingAccount` instead of `.into()`

* Import `vec` macro in `pallet-slashing`

* Import `vec` in other pallets

* Bump TOML dependencies for runtime

Haven't fixed the Rust code yet though

* Self define types instead of using `node-primitives`

* Update staking related configs

Values were mostly taken from the Polkadot runtime config

* Update `pallet-preimage` config

Changes introduced in paritytech/polkadot-sdk#1363

* Add `MaxNominators` to `pallet_babe`

Introduced in paritytech/substrate#14471

* Add `MaxNominators` to `pallet_grandpa`

Also introduced in paritytech/substrate#14471

* Add `RuntimeFreezeReason` to `pallet_nomination_pools`

* Add `MaxTipAmount` to `pallet_tips`

Introduced in paritytech/polkadot-sdk#1709

* Add `IdentityInformation` to `pallet_identity`

Introduced in paritytech/polkadot-sdk#1661

* finish runtime

* Use `crates.io` packages in `entropy` TOML

This doesn't compile yet

* Remove reference to `node_primitives`

* Move imports under correct dependency section

These shouldn't be built-deps, my bad

* Change `WarpSyncParams` import to come from `sc_network_sync`

Change introduced here: paritytech/polkadot-sdk#1912

* Add missing `sc-consensus-babe` package

* Remove second generic from `DefaultImportQueue`

This was removed in paritytech/substrate#14612

* Add temporary cursed RPC bounds

* Switch `sp-consensus-grandpa` to be from Crates

* Add Grandpa justification period to service

* Rename `justification_period to` `justification_generation_period`

* Add missing `block_relay` param

Introduced in paritytech/polkadot-sdk#1524

* Try to clean up runtime types

* Add `opaque` types to runtime

These match what was in `node-primitives`. In particular we're interested in the `Block` type which
we were using in a lot of places, and I incorrectly changed to be `Unchechecked` instead of
`Opaque`.

* Use opaque block type in service

* Add full session key impls

* Remove cursed trait bounds for RPC

* Convert some tabs to spaces

Sorry, I had to

* Import `Vec` from `sp_std` in benchmarks

Turns out the issue responsible for this change is this:
paritytech/polkadot-sdk#172

* Pull `TrackedStorageKey` from `sp_storage`

From here: paritytech/substrate#14787

* Add `BenchmarkHelper` to treasury pallet

* TaploFmt

* change max freezes

* Sort TOML imports in runtime manifest

* Move `version` field to be first in runtime manifest

* Organize imports in pallet manifests

* Sort and organize imports for client

* Address TODOs in `entropy-shared`

* Remove TODOs related to `node-primitives`

* Pull `substrate-wasm-builder` from crates.io

* TaploFmt

* Fix benchmarking import post-merge

* Fix another program import port-merge

* Import `Vec` to programs benches

* Wrong vec import 🙃

* Poke CI

* Bump node metadata

---------

Co-authored-by: Jesse Abramowitz <jesse@entropy.xyz>
bgallois pushed a commit to duniter/duniter-polkadot-sdk that referenced this pull request Mar 25, 2024
…ech#1900)

closes paritytech#1882

## Breaking Changes

This PR introduces a new item to `pallet_balances::Config`:

```diff
trait Config {
++    type RuntimeFreezeReasons;
}
```

This value is only used to check it against `type MaxFreeze`. A similar
check has been added for `MaxHolds` against `RuntimeHoldReasons`, which
is already given to `pallet_balances`.

In all contexts, you should pass the real `RuntimeFreezeReasons`
generated by `construct_runtime` to `type RuntimeFreezeReasons`. Passing
`()` would also work, but it would imply that the runtime uses no
freezes at all.

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
@kianenigma kianenigma mentioned this pull request Mar 25, 2024
6 tasks
bkchr pushed a commit that referenced this pull request Apr 10, 2024
@wischli
Copy link

wischli commented May 15, 2024

IIUC, there is no migration required for teams which introduce RuntimeFreezeReason and/or switch from the () hold reason to the macro generated one?

- type RuntimeHoldReason = ();
+ type RuntimeHoldReason = RuntimeHoldReason;

I would really appreciate a comment on this and apologize for the minor comment creep.

@bkchr
Copy link
Member

bkchr commented May 15, 2024

Yes that is the correct thing to do.

@wischli
Copy link

wischli commented May 16, 2024

Yes that is the correct thing to do.

Really appreciate the quick response. Does your statement include the "no migration required" part as well?

Let me elaborate: Say some pallet has used the () hold reason and now introduces some enum HoldEnum as reason. Then it appears to me that all accounts with reserved funds for the () reason need to be migrated to some HoldEnum variant, independent of the number of variants of HoldEnum (e.g. one vs multiple).

Same for the freezes.

@bkontur
Copy link
Contributor

bkontur commented May 16, 2024

Yes that is the correct thing to do.

Really appreciate the quick response. Does your statement include the "no migration required" part as well?

Let me elaborate: Say some pallet has used the () hold reason and now introduces some enum HoldEnum as reason. Then it appears to me that all accounts with reserved funds for the () reason need to be migrated to some HoldEnum variant, independent of the number of variants of HoldEnum (e.g. one vs multiple).

Same for the freezes.

iirc, VariantCount impl for () returns 0 here: https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame/support/src/traits/misc.rs#L46-L48, so with type RuntimeHoldReason = (); you shouldn't be able to store any holds: https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame/balances/src/lib.rs#L476-L485. But this change was introduced here: #2657, so I am not sure what is your current polkadot-sdk version.

@bkontur
Copy link
Contributor

bkontur commented May 16, 2024

Yes that is the correct thing to do.

Really appreciate the quick response. Does your statement include the "no migration required" part as well?
Let me elaborate: Say some pallet has used the () hold reason and now introduces some enum HoldEnum as reason. Then it appears to me that all accounts with reserved funds for the () reason need to be migrated to some HoldEnum variant, independent of the number of variants of HoldEnum (e.g. one vs multiple).
Same for the freezes.

iirc, VariantCount impl for () returns 0 here: https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame/support/src/traits/misc.rs#L46-L48, so with type RuntimeHoldReason = (); you shouldn't be able to store any holds: https://github.com/paritytech/polkadot-sdk/blob/master/substrate/frame/balances/src/lib.rs#L476-L485. But this change was introduced here: #2657, so I am not sure what is your current polkadot-sdk version.

@wischli I just wanted to say that this change shouldn't require migration. However, it could depend on the version of pallet-balances. If your version doesn't include #2657 and you have type MaxHolds = ConstU32<1>;, then you probably need to check the actual stored Holds, for example:
image
Based on that, you might need to perform some migrations, which should be pretty straightforward.

Also, we have check-migrations CI jobs for runtimes. These jobs check storage or other aspects before and after runtime upgrades. For example, in your case, if you stored holds for a () reason and then a new runtime upgrade changes the reason type from () to RuntimeHoldReason, then without any migration, these CI jobs should fail with an error like "undecodable keys" or something similar. This failure occurs because it won't be able to decode Holds with () to Holds with RuntimeHoldReason. Thus, we will know that we need to add a migration.

@bkchr
Copy link
Member

bkchr commented May 16, 2024

Also, we have check-migrations CI jobs for runtimes.

This is basically just try-runtime with all the checks enabled.

AurevoirXavier added a commit to darwinia-network/darwinia that referenced this pull request Jun 21, 2024
Signed-off-by: Xavier Lau <xavier@inv.cafe>
AurevoirXavier added a commit to darwinia-network/darwinia that referenced this pull request Jun 28, 2024
* Setup deps

* Remove Koi from account migration test

* paritytech/polkadot-sdk#1495

* Bump

* paritytech/polkadot-sdk#1524

* !! paritytech/polkadot-sdk#1363

* paritytech/polkadot-sdk#1492

* paritytech/polkadot-sdk#1911

* paritytech/polkadot-sdk#1900

Signed-off-by: Xavier Lau <xavier@inv.cafe>

* paritytech/polkadot-sdk#1661

* paritytech/polkadot-sdk#2144

* paritytech/polkadot-sdk#2048

* paritytech/polkadot-sdk#1672

* paritytech/polkadot-sdk#2303

* paritytech/polkadot-sdk#1256

* Remove identity and vesting

* Fixes

* paritytech/polkadot-sdk#2657

* paritytech/polkadot-sdk#1313

* paritytech/polkadot-sdk#2331

* paritytech/polkadot-sdk#2409 part.1

* paritytech/polkadot-sdk#2767

* paritytech/polkadot-sdk#2521

Signed-off-by: Xavier Lau <xavier@inv.cafe>

* paritytech/polkadot-sdk#1222

* paritytech/polkadot-sdk#1234 part.1

* Satisfy compiler

* XCM V4 part.1

* paritytech/polkadot-sdk#1246

* Remove pallet-democracy part.1

* paritytech/polkadot-sdk#2142

* paritytech/polkadot-sdk#2428

* paritytech/polkadot-sdk#3228

* XCM V4 part.2

* Bump

* Build all runtimes

* Build node

* Remove pallet-democracy

Signed-off-by: Xavier Lau <xavier@inv.cafe>

* Format

* Fix pallet tests

* Fix precompile tests

* Format

* Fixes

* Async, remove council, common pallet config

* Fix `ethtx-forward` test case (#1519)

* Fix ethtx-forward tests

* Format

* Fix following the review

* Fixes

* Fixes

* Use default impl

* Benchmark helper

* Bench part.1

* Bench part.2

* Bench part.3

* Fix all tests

* Typo

* Feat

* Fix EVM tracing build

* Reuse upstream `proof_size_base_cost()` (#1521)

* Format issue

* Fixes

* Fix CI

---------

Signed-off-by: Xavier Lau <xavier@inv.cafe>
Co-authored-by: Bear Wang <boundless.forest@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R1-breaking_change This PR introduces a breaking change and should be highlighted in the upcoming release. 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.

Add integrity test for MaxHolds and MaxFreezes