-
Notifications
You must be signed in to change notification settings - Fork 938
FRAME: Simplify and extend pallets config definition by using the stabilized feature: associated type bounds #3743
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
Comments
This looks like a good issue to tackle and get crazy on rust types and traits. |
I think a good start would be to use it for one or two pallets as a proof-of-concept. For example as gui pointed out, in the |
I opened an initial PoC PR for |
…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 <[email protected]>
…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 <[email protected]>
…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 <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.
Associated type bounds is stabilized: rust-lang/rust#122055
So we can do code like this:
Instead of doing this:
1: simplify
Config
definitionSo for pallets other than
frame_system
we no longer need the associated types:RuntimeEvent
,RuntimeOrigin
,RuntimeCall
, etc...Instead we should be able to modify the pallet
Config
trait definition like this:2: extend
Config
definitionWe should be able to add constraint on pallet dependencies way more easily without having to write
where ...
for each implementation block.To illustrate we could have a pallet which depends on
pallet_balances
but requires at least u128 as currency typeThe text was updated successfully, but these errors were encountered: