-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Metadata V15: Expose types for the overarching Call, Event, Error enums #14143
Conversation
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
…untimeCall Signed-off-by: Alexandru Vasile <[email protected]>
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.
seems good to me, apart from comments below
frame/support/procedural/src/construct_runtime/expand/outer_enums.rs
Outdated
Show resolved
Hide resolved
frame/support/procedural/src/construct_runtime/expand/outer_enums.rs
Outdated
Show resolved
Hide resolved
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
After having a discussion with @bkchr, it is possible to have the That being said, this PR changes a bit the The implicit state of pallets: The explicit part was previously the final state. Now, explicit parts Please let me know what you think of it considering it is touching a bit more places of code now @bkchr, @jsdw , @sam0x17 🙏 |
frame/support/procedural/src/construct_runtime/expand/outer_enums.rs
Outdated
Show resolved
Hide resolved
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.
Reviewed most of it, will hopefully do the rest this evening!
frame/support/test/tests/construct_runtime_ui/invalid_module_details.stderr
Outdated
Show resolved
Hide resolved
@@ -52,8 +52,8 @@ construct_runtime! { | |||
NodeBlock = Block, | |||
UncheckedExtrinsic = UncheckedExtrinsic | |||
{ | |||
System: frame_system::{Pallet, Call, Storage, Config, Event<T>}, | |||
Pallet: pallet::{Pallet, ValidateUnsigned}, | |||
System: frame_system expanded::{}::{Pallet, Call, Storage, Config, Event<T>}, |
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.
Why do you provide here expanded
?
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.
This would be the "final state" of the construct_runtime!
, without this the macro will try to get expanded one more time. And the expansions require the pallets to expose tt_extra_parts
macro, and for dummy pallets that's not the case (not sure here if this is constructed with only valid pallets 🤔 )
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.
Sounds like a bug?
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've reverted this to remove the expanded
word, the output looks similar to before.
Some small differences in how the compiler reports the error, most probably related to the extra expansion
Example
missing_event_generic_on_module_with_instance.rs (this is the entire file)
use frame_support::construct_runtime;
construct_runtime! {
pub struct Runtime where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Pallet},
Balance: balances::<Instance1>::{Event},
}
}
fn main() {}
If we don't add the expanded
keyword this would produce:
error[E0433]: failed to resolve: use of undeclared crate or module `balances`
--> tests/construct_runtime_ui/missing_event_generic_on_module_with_instance.rs:10:12
|
10 | Balance: balances::<Instance1> ::{Event},
| ^^^^^^^^ use of undeclared crate or module `balances`
When we would actually expect:
error: Instantiable pallet with no generic `Event` cannot be constructed: pallet `Balance` must have generic `Event`
--> $DIR/missing_event_generic_on_module_with_instance.rs:10:3
|
10 | Balance: balances::<Instance1> ::{Event},
| ^^^^^^^
I'm presuming that because the construct_runtime!
is not in it's final expression (does not contain the expanded), the macro tries to expand the pallet one more time. In doing so it calls balances::tt_extra_parts!
, which does not exist (ie theres no balances
module).
The "Instantiable pallet with no generic Event
cannot be constructed: pallet Balance
must have generic" compile error should be coming from the final step of the construct_runtime! macro. And I think it's not outputted/detected because the missing module error has priority for the compiler 🤔
Let me know if this sounds right :D
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.
@bkchr would love to get your feedback on the above 🙏
Co-authored-by: Bastian Köcher <[email protected]>
Co-authored-by: Bastian Köcher <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
…r_enums Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
@gupnik I suggest you taking a look at the |
frame/support/procedural/src/construct_runtime/expand/outer_enums.rs
Outdated
Show resolved
Hide resolved
frame/support/procedural/src/construct_runtime/expand/outer_enums.rs
Outdated
Show resolved
Hide resolved
frame/support/procedural/src/construct_runtime/expand/outer_enums.rs
Outdated
Show resolved
Hide resolved
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
bot merge |
…ms (paritytech#14143) * frame-metadata: Point to unreleased branch Signed-off-by: Alexandru Vasile <[email protected]> * frame: Generalize outer enum generation for events and errors Signed-off-by: Alexandru Vasile <[email protected]> * frame: Remove individual generation of outer enum events Signed-off-by: Alexandru Vasile <[email protected]> * primitives/traits: Add marker trait for outer runtime enums Signed-off-by: Alexandru Vasile <[email protected]> * frame: Derive Clone, PartialEq, Eq for RuntimeEvents only Signed-off-by: Alexandru Vasile <[email protected]> * frame/pallet: Include `#[pallet::error]` enum into pallet parts Signed-off-by: Alexandru Vasile <[email protected]> * metadata-ir: Include call, event, error types Signed-off-by: Alexandru Vasile <[email protected]> * frame/metadata: Include outer enum types in V15 metadata Signed-off-by: Alexandru Vasile <[email protected]> * frame/tests: Ensure `RuntimeError` includes `#[pallet::error]` parts Signed-off-by: Alexandru Vasile <[email protected]> * frame/support: Document the reserved name for `RuntimeError` Signed-off-by: Alexandru Vasile <[email protected]> * frame: Use self-generated `RuntimeEvent` for `GetRuntimeOuterEnumTypes` Signed-off-by: Alexandru Vasile <[email protected]> * frame/ui: Fix UI tests Signed-off-by: Alexandru Vasile <[email protected]> * frame/support: Remove unused system path Signed-off-by: Alexandru Vasile <[email protected]> * frame/ui: Unexpected field and reintroduce frame_system::Config for RuntimeCall Signed-off-by: Alexandru Vasile <[email protected]> * frame/support: Remove `GetRuntimeOuterEnumTypes` marker trait Signed-off-by: Alexandru Vasile <[email protected]> * frame/support: Remove `;` from macro Signed-off-by: Alexandru Vasile <[email protected]> * Update frame-metadata to point to unreleased branch Signed-off-by: Alexandru Vasile <[email protected]> * Rename error_enum_ty to module_error_enum_ty Signed-off-by: Alexandru Vasile <[email protected]> * Update module_error_ty documentation Signed-off-by: Alexandru Vasile <[email protected]> * frame: Implement from_dispatch_error Signed-off-by: Alexandru Vasile <[email protected]> * frame/support: Adjust test to ModuleErrorType Signed-off-by: Alexandru Vasile <[email protected]> * Fix clippy Signed-off-by: Alexandru Vasile <[email protected]> * Improve documentation Signed-off-by: Alexandru Vasile <[email protected]> * frame/tests: Check `from_dispatch_error` impl Signed-off-by: Alexandru Vasile <[email protected]> * Update frame-metadata Signed-off-by: Alexandru Vasile <[email protected]> * Remove the module_error_ty Signed-off-by: Alexandru Vasile <[email protected]> * Apply fmt Signed-off-by: Alexandru Vasile <[email protected]> * Revert unneeded parts Signed-off-by: Alexandru Vasile <[email protected]> * Revert "Revert unneeded parts" This reverts commit b94bbd1. Revert "Apply fmt" This reverts commit 9b1c3e7. Revert "Remove the module_error_ty" This reverts commit 98de5b2. * Update frame-metadata to origin/master Signed-off-by: Alexandru Vasile <[email protected]> * Add outerEnums to the metadata Signed-off-by: Alexandru Vasile <[email protected]> * Add tests Signed-off-by: Alexandru Vasile <[email protected]> * Keep backwards compatibility for explicit pallet parts Signed-off-by: Alexandru Vasile <[email protected]> * Rename tt_error_part to be more generic Signed-off-by: Alexandru Vasile <[email protected]> * Increase recursion_limit to 1k Signed-off-by: Alexandru Vasile <[email protected]> * Rename `fully_expanded` to `expanded` Signed-off-by: Alexandru Vasile <[email protected]> * Improve documentation Signed-off-by: Alexandru Vasile <[email protected]> * Adjust UI tests Signed-off-by: Alexandru Vasile <[email protected]> * Update UI tests Signed-off-by: Alexandru Vasile <[email protected]> * Update undefined_validate_unsigned_part.stderr UI test Signed-off-by: Alexandru Vasile <[email protected]> * Adjust yet again Signed-off-by: Alexandru Vasile <[email protected]> * Optimise macro expansions Signed-off-by: Alexandru Vasile <[email protected]> * Use latest frame-metadata and rename `moduleErrorType` to `RuntimeError` Signed-off-by: Alexandru Vasile <[email protected]> * Fix comment Signed-off-by: Alexandru Vasile <[email protected]> * Apply fmt Signed-off-by: Alexandru Vasile <[email protected]> * Update frame/support/procedural/src/construct_runtime/parse.rs Co-authored-by: Bastian Köcher <[email protected]> * Update frame/support/procedural/src/construct_runtime/parse.rs Co-authored-by: Bastian Köcher <[email protected]> * Update frame-metadata PR Signed-off-by: Alexandru Vasile <[email protected]> * Remove `expanded` from error messages and fix typo Signed-off-by: Alexandru Vasile <[email protected]> * Move docs to the function Signed-off-by: Alexandru Vasile <[email protected]> * ui: Use the intermed syntax for pallet parts Signed-off-by: Alexandru Vasile <[email protected]> * Update frame-metadata with latest release Signed-off-by: Alexandru Vasile <[email protected]> * frame: Address feedback for `from_dispatch_error` Signed-off-by: Alexandru Vasile <[email protected]> --------- Signed-off-by: Alexandru Vasile <[email protected]> Co-authored-by: Bastian Köcher <[email protected]>
This PR exposes the overarching types for
RuntimeEvent
andRuntimeCall
andRuntimeError
for the V15 metadata.The
RuntimeEvent
andRuntimeCall
are represented as is.The code that previously generate the
RuntimeEvent
is extended to now generate theRuntimeError
enum since they share almost 95% of the functionality.Construct Runtime Changes
Runtimes can be constructed implicitly or explicitly.
To ensure that the
Error
enum is propagated to the metadata for each pallet that declares one with#[pallet::error]
macro the construction of the runtime is changed:State Machine
The
construct_runtime
transitioned from an implicit to an explicit state.For explicit declarations, we are now including the
Error<T>
part if defined.This introduces a new state
explicit expanded
which transforms theconstruct_runtime
in a similar manner.For optimization purposes, any implicit declaration is transformed into an explicit expanded form (ie if all pallets are declared implicit, then we'll expand the macro only once as before).
The
tt_extra_parts
is added to each pallet definition and is responsible for creating a token stream of expanded pallet parts:This effectively transforms:
For explicit declarations:
polkadot companion: paritytech/polkadot#7401
Depends on: paritytech/frame-metadata#57
Closes paritytech/frame-metadata#43.
// @paritytech/subxt-team