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

Fix order of hook execution #10043

Merged
merged 16 commits into from
Dec 1, 2021
Merged

Conversation

gui1117
Copy link
Contributor

@gui1117 gui1117 commented Oct 18, 2021

Fix #6280
Fix #9105

polkadot companion: paritytech/polkadot#4181
cumulus companion: paritytech/cumulus#711

Breaking Change:

  • AllPallets is deprecated in favor of explicit: AllPalletsWithSystem, AllPalletsWithoutSystem, AllPalletsWithSystemReversed, AllPalletsWithoutSystemReversed. Before this PR AllPallets represented all pallets without system in reversed order (i.e. same as AllPalletsWithoutSystemReversed, it now represent AllPalletsWithSystem as it is a more sane expectation.
  • frame_executive::Executive requires as generic all pallets with system. Before this PR the type required as generic all pallets without system and always executed system pallet hook before all pallets hook. But this requires duplicate works and error prone implementation thus it now requires all pallets with system. The previous order was to execute the hook on system pallet first and then AllPallets. It is recomended to use one of AllPalletsWithSystem or AllPalletsWithSystemReversed or AllPalletsReversedWithSystemFirst.

Because before the PR all pallets represented all pallets in reversed, and system was executed first then if someone want to keep the same behavior as before they should use the type AllPalletsReversedWithSystemFirst when using the type frame_executive::Executive.
Though it is recommended to be careful about the order of definition of the pallet in construct_runtime. and probably reorganize and use AllPalletsWithSystem, so the order is the expected normal order and not in reversed (as before this PR).

NOTE: frame_executive::Executive will execute the hooks on_initialize, on_idle, on_runtime_upgrade, on_finalize, offchain_worker on the generic AllPallets, so the order should be reviewed for those execution.

Upgrade guide:

  1. use AllPalletsReversedWithSystemFirst when instancing executive type, that mean the execution order is not changed from before this PR, thus no need to change anything in construct_runtime.

  2. Use the new AllPalletsWithSystem, but this would mean that they might need to reorder some stuff in construct_runtime.

  3. review other usage of AllPallets and change to AllPalletsWithoutSystemReversed in case the old order must be kept, or change to AllPalletsWithoutSystem to get the new definition with pallets defined in the order of their declaration in construct_runtime.

@gui1117 gui1117 added A3-in_progress Pull request is in progress. No review needed at this stage. B3-apinoteworthy C1-low PR touches the given topic and has a low impact on builders. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed. labels Oct 18, 2021
@github-actions github-actions bot 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 Oct 18, 2021
gui1117 and others added 2 commits October 18, 2021 11:05
Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
@gui1117
Copy link
Contributor Author

gui1117 commented Oct 18, 2021

for the polkadot It seems we don't need any changes:
maybe scheduler should be put last instead of 2nd. So that the execution of scheduled call happens after other pallet initialization ?

@gui1117 gui1117 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 Oct 19, 2021
OnRuntimeUpgrade
>::pre_upgrade().unwrap();

<(COnRuntimeUpgrade, AllPallets) as OnRuntimeUpgrade>::pre_upgrade().unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

I think this is also a noteworthy change. Here system pallet upgrades after the runtime upgrades.

Dunno actually if this can cause issues?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think for pre_upgrade/post_upgrade the order wasn't so important as it is just checks.
But the order of on_runtime_upgrade is important. That said the order was: custom, then system then pallets.
I will precise this in the note

Copy link
Contributor

Choose a reason for hiding this comment

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

try_on_runtime_upgrade should always imitate what the real on_runtime_upgrade would do, which is respected here, so no issues.

brenzi pushed a commit to integritee-network/integritee-node that referenced this pull request Jan 6, 2022
- The substrate verion for sp-core was updated to 4.1.0-dev.
- The toolchain was updated to nightly-2021-12-10 due to incompatibilities with the toolchain nightly-2021-12-22
- "AllPallets" was replaces by AllPalletsReversedWithSystemFirst according to paritytech/substrate#10043

Co-authored-by: Gaudenz Kessler <gaudenz.kessler@scs.ch>
brenzi pushed a commit to integritee-network/sgx-runtime that referenced this pull request Jan 6, 2022
- The substrate verion for sp-core was updated to 4.1.0-dev.
- "AllPallets" was replaces by AllPalletsReversedWithSystemFirst according to Fix order of hook execution paritytech/substrate#10043

Co-authored-by: Gaudenz Kessler <gaudenz.kessler@scs.ch>
chevdor pushed a commit that referenced this pull request Jan 11, 2022
* fix order

* Update frame/support/procedural/src/construct_runtime/mod.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* format

* more accurate description

* format

* better explicit types

* fix tests

* address feedback

* add a type to ease non breaking implementation

* add comment about constraint

* fix test

* add test for generated types

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
chevdor added a commit that referenced this pull request Jan 14, 2022
@chevdor chevdor mentioned this pull request Jan 14, 2022
chevdor added a commit that referenced this pull request Jan 15, 2022
jasl added a commit to Phala-Network/khala-parachain that referenced this pull request Jan 17, 2022
grishasobol pushed a commit to gear-tech/substrate that referenced this pull request Mar 28, 2022
* fix order

* Update frame/support/procedural/src/construct_runtime/mod.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* format

* more accurate description

* format

* better explicit types

* fix tests

* address feedback

* add a type to ease non breaking implementation

* add comment about constraint

* fix test

* add test for generated types

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
haerdib added a commit to ajuna-network/sgx-runtime that referenced this pull request May 6, 2022
* Add secp256k1 ecdsa recover (integritee-network#42)

* implement secp256k1_ecdsa_recover

* fix sgx compilation error

* reorder libsecp256k1 in .toml

Co-authored-by: suinuj <junius@litentry.com>

* Update substrate to b9cafba (integritee-network#44)

- The substrate verion for sp-core was updated to 4.1.0-dev.
- "AllPallets" was replaces by AllPalletsReversedWithSystemFirst according to Fix order of hook execution paritytech/substrate#10043

Co-authored-by: Gaudenz Kessler <gaudenz.kessler@scs.ch>

* Add runtime-api `get_metadata` (integritee-network#47)

Co-authored-by: echevrier <edith.chevrier@scs.ch>

* Bump substrate to commit 7c63420  (integritee-network#48)

* update .tomls to match new substrate version

* update rust toolchain

* cargo update

* revert unnecessary cargo update..

* updae sp-io version

* redo toolchain bump - teaclave..

* fix version changes

* add missing sp-io functions (integritee-network#49)

* update sp-io trie

* add root version 2

* add storage::root version2

* Bump substrate to commit f5f286db0da99761792b69bf4a997535dcc8f260 (integritee-network#50)

Co-authored-by: echevrier <edith.chevrier@scs.ch>

* Bump to polkadot 0.9.19 and switch to polkadot branches (integritee-network#53)

Remove TransactionByteFee
Apply WeightToFeePolynomials to pallet_transaction_payment

Co-authored-by: echevrier <edith.chevrier@scs.ch>

* fix cargo.lock

* add some pubs

* add one more pub

Co-authored-by: suinuj <junius@litentry.com>
Co-authored-by: gaudenzkessler <92718752+gaudenzkessler@users.noreply.github.com>
Co-authored-by: Gaudenz Kessler <gaudenz.kessler@scs.ch>
Co-authored-by: echevrier <84318241+echevrier@users.noreply.github.com>
Co-authored-by: echevrier <edith.chevrier@scs.ch>
AurevoirXavier added a commit to darwinia-network/darwinia-common that referenced this pull request Sep 8, 2022
ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
* fix order

* Update frame/support/procedural/src/construct_runtime/mod.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* format

* more accurate description

* format

* better explicit types

* fix tests

* address feedback

* add a type to ease non breaking implementation

* add comment about constraint

* fix test

* add test for generated types

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
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. C1-low PR touches the given topic and has a low impact on builders. D2-breaksapi D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed.
Projects
None yet
5 participants