Skip to content

[FRAME] Simplify pallet config definition: remove RuntimeEvent associated type#7229

Merged
bkchr merged 19 commits intoparitytech:masterfrom
dastansam:feat/runtime-event-associated-type-bound
Apr 16, 2025
Merged

[FRAME] Simplify pallet config definition: remove RuntimeEvent associated type#7229
bkchr merged 19 commits intoparitytech:masterfrom
dastansam:feat/runtime-event-associated-type-bound

Conversation

@dastansam
Copy link
Copy Markdown
Contributor

@dastansam dastansam commented Jan 17, 2025

part of #3743

Motivation

This PR removes the need for defining RuntimeEvent in the Config trait of a pallet. It uses associated type bound feature under the hood to make sure that Event of the pallet is convertible to the aggregated runtime event type frame_system::RuntimeEvent.

This is an initial PR for RuntimeEvent type and will be followed with other types, e.g RuntimeCall. As a demo, example pallets' config definition is updated to use this feature.

With this change, we can do this (and have support for events):

#[pallet::config]
pub trait Config: frame_system::Config {
}

instead of this:

#[pallet::config]
pub trait Config: frame_system::Config {
        /// Overarching event type.
       type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}

The latter will emit deprecation warnings and is redundant.

polkadot address: 16FqwPZ8GRC5U5D4Fu7W33nA55ZXzXGWHwmbnE1eT6pxuqcT

@dastansam dastansam marked this pull request as ready for review January 17, 2025 15:57
@dastansam dastansam requested a review from a team as a code owner January 17, 2025 15:57
Copy link
Copy Markdown
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

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

Ty for doing this!

@paritytech-review-bot paritytech-review-bot bot requested a review from a team January 24, 2025 12:27
@dastansam dastansam requested review from bkchr and gui1117 January 24, 2025 12:36
@dastansam dastansam changed the title [FRAME] Simplify pallet config definition: RuntimeEvent as an associated type bound [FRAME] Simplify pallet config definition: remove RuntimeEvent associated type Jan 24, 2025
@dastansam
Copy link
Copy Markdown
Contributor Author

@bkchr bunch of CI is failing because they treat the RuntimeEvent deprecation warnings as error. Do you think it's worth fixing all those deprecation warnings in this PR? I thought it would be a lot of changes and also would feel more comfortable doing it once this change is carefully reviewed.

@paritytech-review-bot paritytech-review-bot bot requested a review from a team January 25, 2025 09:05
Copy link
Copy Markdown
Contributor

@gui1117 gui1117 left a comment

Choose a reason for hiding this comment

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

Looks good to me, after the suggestion, and also a few comments

///
/// ```rs
/// pub trait Config: frame_system::Config {
/// ```
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.

As a note personally I would always bound the supertrait: frame_system::Config<RuntimeEvent: From<Event>>, always, except if there is the flag is_frame_system.
If user wants to write it, he can do, then it will still compile fine.
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7cfad8342293e593a0c8041cd4b5a958

But this is also ok.

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.

thanks for this tip, really helpful)

@dastansam
Copy link
Copy Markdown
Contributor Author

dastansam commented Jan 27, 2025

@bkchr I replaced with proc macro warning but now I have to put the #[allow(deprecated)] above the mod pallet:

#[frame_support::pallet]
#[allow(deprecated)]
pub mod pallet {

but this way it would take a big span and we could ignore other deprecation warnings as well. Putting #[allow(deprecated)] above pallet config implementations is not ignoring the warning. what would you suggest? am I missing sth?

@bkchr
Copy link
Copy Markdown
Member

bkchr commented Jan 28, 2025

Putting #[allow(deprecated)] above pallet config implementations is not ignoring the warning. what would you suggest? am I missing sth?

You need to detect the allow(deprecated) in the macro and then forward this to the usage of this item.

@dastansam dastansam requested review from a team and cheme as code owners February 15, 2025 12:16
@paritytech-review-bot paritytech-review-bot bot requested a review from a team February 15, 2025 12:16
@dastansam dastansam force-pushed the feat/runtime-event-associated-type-bound branch from 85171bc to cf1d716 Compare February 16, 2025 07:23
@bkchr
Copy link
Copy Markdown
Member

bkchr commented Apr 17, 2025

And sometimes they have to define their own copy of it, since they want to assert more bounds on it.

Yeah and that is was this feature brings you! You can also extend and add more bounds. Most of the time RuntimeCall is only added if you need to add the From<LocalCall> bound.

@bkchr
Copy link
Copy Markdown
Member

bkchr commented Apr 17, 2025

Also noting that for pallets that use #[pallet::disable_frame_system_supertrait_check] This won't work

Why will this not work? EVERY pallet needs to have the frame_system::Config as a super trait. This attribute is only if you don't have it as a direct super trait, but you for example require pallet_balances::Config as super trait. Still, frame_system::Config is reachable.

@kianenigma
Copy link
Copy Markdown
Contributor

Yeah and that is was this feature brings you! You can also extend and add more bounds. Most of the time RuntimeCall is only added if you need to add the From bound.

Okay so I didn't fully understand how this was meant to be implemented for RuntimeCall.

Also noting that for pallets that use #[pallet::disable_frame_system_supertrait_check] This won't work

Yeah, I was wrong about this, sorry, it works now!

@dastansam
Copy link
Copy Markdown
Contributor Author

Yeah and that is was this feature brings you! You can also extend and add more bounds. Most of the time RuntimeCall is only added if you need to add the From bound.

Okay so I didn't fully understand how this was meant to be implemented for RuntimeCall.

Also noting that for pallets that use #[pallet::disable_frame_system_supertrait_check] This won't work

Yeah, I was wrong about this, sorry, it works now!

yeah, it is more about automatically adding common RuntimeCall bounds to system supertrait to avoid having to declare them in the pallet's Config. I am still clarifying some things, but should open the PR with draft version soon

Krayt78 pushed a commit to Krayt78/polkadot-sdk that referenced this pull request Apr 18, 2025
…ciated type (paritytech#7229)

part of paritytech#3743

## Motivation

This PR removes the need for defining `RuntimeEvent` in the `Config`
trait of a pallet. It uses associated type bound feature under the hood
to make sure that `Event` of the pallet is convertible to the aggregated
runtime event type `frame_system::RuntimeEvent`.

This is an initial PR for `RuntimeEvent` type and will be followed with
other types, e.g `RuntimeCall`. As a demo, example pallets' config
definition is updated to use this feature.

With this change, we can do this (and have support for events):

```rs
#[pallet::config]
pub trait Config: frame_system::Config {
}
```

instead of this:

```rs
#[pallet::config]
pub trait Config: frame_system::Config {
        /// Overarching event type.
       type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}
```

The latter will emit deprecation warnings and is redundant.

polkadot address: 16FqwPZ8GRC5U5D4Fu7W33nA55ZXzXGWHwmbnE1eT6pxuqcT

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
@dastansam dastansam deleted the feat/runtime-event-associated-type-bound branch May 2, 2025 08:21
castillax pushed a commit that referenced this pull request May 12, 2025
…ciated type (#7229)

part of #3743

## Motivation

This PR removes the need for defining `RuntimeEvent` in the `Config`
trait of a pallet. It uses associated type bound feature under the hood
to make sure that `Event` of the pallet is convertible to the aggregated
runtime event type `frame_system::RuntimeEvent`.

This is an initial PR for `RuntimeEvent` type and will be followed with
other types, e.g `RuntimeCall`. As a demo, example pallets' config
definition is updated to use this feature.

With this change, we can do this (and have support for events):

```rs
#[pallet::config]
pub trait Config: frame_system::Config {
}
```

instead of this:

```rs
#[pallet::config]
pub trait Config: frame_system::Config {
        /// Overarching event type.
       type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}
```

The latter will emit deprecation warnings and is redundant.

polkadot address: 16FqwPZ8GRC5U5D4Fu7W33nA55ZXzXGWHwmbnE1eT6pxuqcT

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
saraswatpuneet added a commit to frequency-chain/frequency that referenced this pull request Aug 14, 2025
immae pushed a commit to duniter/duniter-v2s that referenced this pull request Oct 3, 2025
Upgrade polkadot v1.19.1 (nodes/rust/duniter-v2s!341)

* regenerate metadata

* update srtool

* fix ci

* upgrade doc-gen

* fix clippy

* update subxt

* regenerate metadata

* regenerate weights

* fix benchmarks

* fix deprecation from paritytech/polkadot-sdk#7229

* fix binding modifier not allowed under ref

* upgrade SDK and Rust
manuelmauro added a commit to moonbeam-foundation/moonbeam that referenced this pull request Oct 29, 2025
RomarQ added a commit to moonbeam-foundation/moonbeam that referenced this pull request Nov 26, 2025
* chore: ⬆️ upgrade dependencies to 2506

* refactor: 🚨 use workspace dependencies in pallet crowdloan rewards

* chore: 📌 depend on crates.io ethereum (similarly to frontier)

* fix: 🐛 remove PassByCodec

PassByCodec was replaced by PassFatPointerAndDecode in paritytech/polkadot-sdk@1cb22ca

* fix: 🐛 use Weight::MAX instead of Weight::max_value()

* fix: 🐛 add TrieCacheContext parameter to state_at

* fix: 🐛 add missing relay_parent_descendants and collator_peer_id fields to ParachainInherentData

* fix: 🐛 remove deprecated AssetHubMigrationStarted config

* fix: 🐛 update ExecuteXcm::prepare() to accept weight_limit parameter

* fix: 🐛 add generic parameters to Sha3FIPS256<Runtime, ()>

* fix: 🐛 add metrics field to BuildNetworkParams

* chore: 📌 upgrade pins

* fix: 🐛 add OnNewHead to bridge parachain configs

This adds the required OnNewHead configuration parameter introduced in paritytech/polkadot-sdk#8531

* fix: 🐛 add relay chain slot duration to FixedVelocityConsensusHook

* fix: 🐛 add SlotDuration trait items

Upstream PR: Moonsong-Labs/moonkit#83 - "Use PostInherents to validate timestamp"   - Author: Rodrigo Quelhas (RomarQ)   - Merged: September 30, 2025    Details: This trait item is used in the PostInherents validation to ensure that the configured block time in the node and runtime is compatible with Nimbus's consensus mechanism.   The value is set to MILLISECS_PER_BLOCK (12000ms for Moonbeam), matching the parachain's block production time. This change prepares for Polkadot SDK updates that deprecated the   CheckInherents parameter in favor of PostInherents validation.

* fix: 🐛 add RelayParentOffset trait item

Upstream PR: paritytech/polkadot-sdk#8299 - "Allow building on older relay parents"   - Author: Sebastian Kunert (skunert)   - Merged: May 29, 2025    Details: With an offset of 0, blocks are built on the current relay chain tip. Non-zero values allow building on older relay parents (e.g., offset of 2 means building 2 blocks   behind the tip) to avoid building on short-lived relay chain forks. The runtime enforces this offset by requiring multiple relay parent descendants to be present in the   set_validation_data inherent.

* fix: 🐛 refactor build_relay_chain_interface to return only required tuple elements

* fix: 🐛 fixed RuntimeOrigin trait bounds by removing From<Option<AccountId>> bound

Fixed RuntimeOrigin trait bounds - Removed From<Option<AccountId>> bound and updated all precompiles to use frame_system::RawOrigin::Signed().into()

* fix: 🐛 update cumulus_pallet_xcmp_queue WeightInfo methods

* fix: 🐛 fix AccountId ambiguity

Added proper type qualifications and EncodeLike trait bound in crowdloan-rewards precompile

* fix: 🐛 use QueueFootprintQuery trait for message queue footprint method

paritytech/polkadot-sdk#8021

* fix: 🐛 remove deprecated RuntimeEvent

* fix: 🐛 update the runtime interface to use explicit marshalling strategies

PR #7375 - Host/Runtime Interface Refactoring   🔗 paritytech/polkadot-sdk#7375

* fix: 🐛 do not enable SharedTrieCache

* fix: 🐛 implement BenchmarkHelper

* fix: 🐛 remove PalletTransactionPaymentBenchmark

* fix: 🐛 add missing crate in Cargo feature

* fix: 🐛 remove RuntimeEvent associated type

Polkadot SDK changes: paritytech/polkadot-sdk#7229

* fix: 🐛 remove unused imports

* fix: 🐛 remove RuntimeEvent associated type

* fix: 🐛 remove AssetHubMigrationStarted associated type

* fix: 🐛 add RelayParentOffset associated type

* fix: 🐛 add metrics_registry: None to database configuration

* fix: 🐛 add warm_up_trie_cache: None to service configuration

* fix: 🐛 fix reference to deprecated RuntimeEvent associated type

* fix: 🐛 update WeightBounds trait API

* fix: 🐛 add missing fields to ParachainInherentData

* fix: 🐛 add missing associated types to Runtime

* fix: 🐛 replace `Fail(Option<T::Hash>, XcmError)` with `Fail(Option<T::Hash>, InstructionError)`

* style: 🎨 format code

* fix: 🐛 fix `XcmExecutor::prepare` args

* fix: 🐛 impl create_bare from CreateInherent trait

* fix: 🐛 mock BenchmarkHelper

* fix: ⬆️ upgrade frame-metadata

* chore: ⬆️ upgrade polkadot-sdk

* fix: 🐛 silence warning

* style: 🚨 mark args as unused

* fix: 🐛 fix deprecation warning

* style: 🎨 format code

* test: 🐛 update snapshot

* chore: 📌 update pins

* refactor: ♻️ move lint directive to root Cargo.toml

* chore: ⚡ run benchmarks

* chore: ⚡ run benchmarks

* test: ✅ assert specific error type

* test: ✅ use proper assert_noop!

* test: ✅ use new extrinsic for asset transfers using explicit XCM transfer types

paritytech/polkadot-sdk#3695

* fix: 🐛 pin udeps Rust nightly version

* Revert "fix: 🐛 pin udeps Rust nightly version"

This reverts commit 09e6d03.

* fix: 🐛 fix some Cargo.toml features

* revert: 🔥 remove AssetHubMigrationStarted storage flag

* refactor: 🔥 remove unused import

* fix: 🐛 add missing feature flags for pallet-assets dependency

* refactor: 🚨 remove duplicated feature flags

* revert: 🔥 delete file committed by mistake

* fix: 📌 properly pin polkadot-sdk version

* test: ✅ initialize ParachainSystem HostConfiguration in runtime tests

The ParentAsUmp XCM router now validates upward messages by checking   HostConfiguration, which was previously uninitialized in test environments,   causing ErrorValidating and SendFailure errors.

* update polkadot-sdk pin

* update polkadot-sdk pin

* fix unit tests

* update polkadot-sdk pin

* fix check-unused-dependencies

* fix test

* refactor: ♻️ remove IdentityBenchmarkHelper

* Revert "refactor: ♻️ remove IdentityBenchmarkHelper"

This reverts commit b872ee4.

* revert: ⏪ restore pallet_transaction_payment

* test: ✅ update tests call_pallet_xcm_with_fee

* refactor: ♻️ add mock_abridged_host_config function

* fix pallet-identity benchmarks

* fix: 🐛 add helper function to set up XCM router for benchmarks

* fix: 🐛 add custom delivery helper for Moonbeam

* chore: 🔧 update weights

* style: 🎨 keep original name TestDeliveryHelper

* fix pallet-randomness benchmarks

* Revert "chore: 🔧 update weights"

This reverts commit ea91959.

* test: ✅ update snapshots

---------

Co-authored-by: Rodrigo Quelhas <22591718+RomarQ@users.noreply.github.com>
Co-authored-by: Rodrigo Quelhas <rodrigo_quelhas@outlook.pt>
snowmead added a commit to Moonsong-Labs/storage-hub that referenced this pull request Mar 16, 2026
Upgrade all polkadot-sdk git dependencies from branch `stable2503` to
`stable2506`. Upgrade all Frontier EVM dependencies from branch
`stable2503` to tag `frontier-stable2506`.

Fix all compilation errors and test failures caused by upstream breaking
API changes in polkadot-sdk stable2506 (134 PRs) and 9 patch releases.

Upstream breaking changes addressed:
- Remove local `AccountIdFor` alias, now provided by
  `frame_system::pallet_prelude` (paritytech/polkadot-sdk#7229)
- Add `RelayParentOffset = ConstU32<0>` to parachain system config
  (paritytech/polkadot-sdk#8299)
- Fix `Outcome` enum pattern matching: `Error` is now tuple variant
  wrapping `InstructionError` (paritytech/polkadot-sdk#8535)
- Remove `RuntimeEvent` from `pallet_evm::Config` and
  `pallet_ethereum::Config` (frontier stable2506)
- Add `RuntimeEvent` to `pallet_session::historical::Config`
- Remove `PassByInner` import, use `.0` for `H256` inner access
  (paritytech/polkadot-sdk#7375)
- Destructure 4 return values from `build_relay_chain_interface`
  (paritytech/polkadot-sdk#8072)
- Add `metrics` field to `BuildNetworkParams`
  (paritytech/polkadot-sdk#8332)
- Add `prometheus_registry` to `StartRelayChainTasksParams`
  (paritytech/polkadot-sdk#8332)

Release: https://github.com/paritytech/polkadot-sdk/releases/tag/polkadot-stable2506

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
snowmead added a commit to Moonsong-Labs/storage-hub that referenced this pull request Mar 16, 2026
FRAME now auto-derives the RuntimeEvent conversion using associated
type bounds on frame_system::Config when a #[pallet::event] block is
present, making the explicit `type RuntimeEvent` in pallet Config
traits redundant.

Removed from 7 StorageHub pallets (bucket-nfts, file-system,
payment-streams, proofs-dealer, providers, randomness,
provider-randomness), the mock_message_queue pallet, and all
corresponding mock/runtime/xcm-simulator Config implementations.

Events themselves are unchanged — only the redundant associated type
declaration was removed.

Ref: paritytech/polkadot-sdk#7229

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
snowmead added a commit to Moonsong-Labs/storage-hub that referenced this pull request Mar 17, 2026
Regenerate api-augment metadata and TypeScript type definitions from
fresh stable2506 runtime binaries built via cargo build --release,
crossbuild:mac, and docker:build.

Reflects all runtime API and pallet changes from the polkadot-sdk
stable2506 upgrade including V16 metadata stabilization
(paritytech/polkadot-sdk#8443) and RuntimeEvent removal from pallet
Config traits (paritytech/polkadot-sdk#7229).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
snowmead added a commit to Moonsong-Labs/storage-hub that referenced this pull request Mar 17, 2026
- Remove unused `pallet_prelude::*` import in pallet-bucket-nfts
  (leftover from RuntimeEvent removal in paritytech/polkadot-sdk#7229)
- Prefix unused `relay_network_service` and `relay_req_receiver`
  variables with underscore (new return values from
  build_relay_chain_interface in paritytech/polkadot-sdk#8072)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
snowmead added a commit to Moonsong-Labs/storage-hub that referenced this pull request Mar 17, 2026
- Replace `<T as pallet::Config>::RuntimeEvent` with
  `<T as frame_system::Config>::RuntimeEvent` in all benchmark files,
  since RuntimeEvent was removed from pallet Config traits
  (paritytech/polkadot-sdk#7229)
- Add missing 5th argument (SharedTrieCache) to storage benchmark
  `cmd.run()` calls in node/src/command.rs
  (paritytech/polkadot-sdk#7556)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T1-FRAME This PR/Issue is related to core FRAME, the framework.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

7 participants