-
Notifications
You must be signed in to change notification settings - Fork 799
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
[FRAME] Simplify pallet config definition: remove RuntimeEvent
associated type
#7229
base: master
Are you sure you want to change the base?
[FRAME] Simplify pallet config definition: remove RuntimeEvent
associated type
#7229
Conversation
There was a problem hiding this 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!
pub trait Config: frame_system::Config { | ||
/// Because this pallet emits events, it depends on the runtime's definition of an event. | ||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; | ||
pub trait Config: frame_system::Config<RuntimeEvent: From<Event<Self>>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it would be much "cooler" 👀 if the pallet::config
macro would auto generate all of these. And then we could put a deprecation warning over RuntimeEvent
, RuntimeCall
etc inclusion in the Config
trait later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, for the implementation all pallets except frame-system can bound this From<Event>
automatically.
For frame-system pallet, I guess we need something so that the macro can know that the pallet is frame-system
, I suggest a new attribute somewhere (maybe on pallet::config
) like #[pallet::is_frame_system]
.
But if you find a better way, please do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I have made the changes to automatically append the type bound to system supertrait. I did this on the macro expansion level instead of parsing, since we need to know if the pallet Event
struct is actually defined.
For frame-system pallet, I guess we need something so that the macro can know that the pallet is frame-system, I suggest a new attribute somewhere (maybe on pallet::config) like #[pallet::is_frame_system].
But if you find a better way, please do.
For this, I simply opted for checking if the pallet config contains a system supertrait, i.e frame_system::Config
. If it doesn't, it's a system
pallet.
RuntimeEvent
as an associated type boundRuntimeEvent
associated type
@bkchr bunch of CI is failing because they treat the |
type_event | ||
.attrs | ||
.push(syn::parse_quote!(#[deprecated(note = "`RuntimeEvent` associated type is deprecated, there is no need to define it in the pallet config.")])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use proc_macro_warning
for issuing the warning to the pallet builder. Besides that we should provide an "allow(deprecated)" above the type to not print the warning.
Then we basically need to update all pallets in the repo to accept the deprecated RuntimeEvent
. At some later point we then need to remove it. There is sadly no real better way for downstream as removing them at some point.
let (has_frame_system_supertrait, has_event_bound) = item | ||
.supertraits | ||
.iter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should do what @gui1117 proposed and introduce a frame_system_pallet
attribute macro that we will use in frame_system
. Every other pallet will then be assumed to not be frame-system
.
/// In general, `Runtime*`-oriented types cannot have a sensible default. | ||
#[pallet::no_default] // optional. `RuntimeEvent` is automatically excluded as well. | ||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; | ||
|
||
/// The overarching task type. | ||
#[pallet::no_default] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[pallet::no_default] | |
#[pallet::no_default] // optional. `RuntimeEvent` is automatically excluded as well. |
/// In general, `Runtime*`-oriented types cannot have a sensible default. | ||
#[pallet::no_default] // optional. `RuntimeEvent` is automatically excluded as well. | ||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; | ||
|
||
/// The overarching task type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// The overarching task type. | |
/// The overarching task type. This is coming from the runtime, and cannot have a default. | |
/// In general, `Runtime*`-oriented types cannot have a sensible default. |
part of #3743
Motivation
This PR removes the need for defining
RuntimeEvent
in theConfig
trait of a pallet. It uses associated type bound feature under the hood to make sure thatEvent
of the pallet is convertible to the aggregated runtime event typeframe_system::RuntimeEvent
.This is an initial PR for
RuntimeEvent
type and will be followed with other types, e.gRuntimeCall
. As a demo, example pallets' config definition is updated to use this feature.With this change, we can do this:
instead of this:
or alternatively, it is possible to explicitly define the type bound:
polkadot address: 16FqwPZ8GRC5U5D4Fu7W33nA55ZXzXGWHwmbnE1eT6pxuqcT