Skip to content

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

Merged
kianenigma merged 23 commits into
masterfrom
kiz-variant-count
Oct 24, 2023
Merged

Ensure correct variant count in Runtime[Hold/Freeze]Reason#1900
kianenigma merged 23 commits into
masterfrom
kiz-variant-count

Conversation

@kianenigma

@kianenigma kianenigma commented Oct 17, 2023

Copy link
Copy Markdown
Contributor

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>

@ggwpez ggwpez left a comment

Copy link
Copy Markdown
Member

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.

Comment thread substrate/frame/support/src/traits/misc.rs Outdated
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
@ggwpez ggwpez requested a review from a team October 17, 2023 10:21
Comment thread substrate/frame/balances/src/lib.rs
type ReserveIdentifier = TestId;
type WeightInfo = ();
type RuntimeHoldReason = TestId;
type RuntimeFreezeReason = RuntimeFreezeReason;

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@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
Copy Markdown

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

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

wischli commented May 15, 2024

Copy link
Copy Markdown
Contributor

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

bkchr commented May 15, 2024

Copy link
Copy Markdown
Member

Yes that is the correct thing to do.

@wischli

wischli commented May 16, 2024

Copy link
Copy Markdown
Contributor

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

bkontur commented May 16, 2024

Copy link
Copy Markdown
Contributor

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

bkontur commented May 16, 2024

Copy link
Copy Markdown
Contributor

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

bkchr commented May 16, 2024

Copy link
Copy Markdown
Member

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

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

aurexav added a commit to darwinia-network/darwinia that referenced this pull request Jun 21, 2024
Signed-off-by: Xavier Lau <xavier@inv.cafe>
aurexav 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>
Patrick8rz added a commit to Patrick8rz/darwinia that referenced this pull request Sep 6, 2025
* 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>
jacksonLewis88 added a commit to jacksonLewis88/darwinia that referenced this pull request Sep 25, 2025
* 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>
kinetic-smith803tr added a commit to kinetic-smith803tr/darwinia that referenced this pull request Sep 26, 2025
* 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