-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Allow pallet in construct_runtime to have fixed index #6969
Conversation
Just make sure to bump the metadata version to v12 (have not looked yet if it is done), without it there is going to be absolute chaos in the ecosystem, JS, Python, ... ... EDIT: And it is bumped, so yes, can be done by all. |
cc @emielvanderhoek cc @arjanz |
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 like the = Something
syntax for setting the index! :)
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
I have just seen this PR and looked over it very quickly, but I think it would be a fair requirement that to use the I think it would avoid future footguns, and adds little overhead. So either they all have it, or none have it. |
ok it seems we agree on breaking call and origin (and event but it is not important), then we can just force At the same time we can change encoding of origin: origin: OriginCaller::System variant will have the given index. (for me the only reason to keep this implicit syntax was to not have a breaking change for the encoding of Call and Origin) |
@thiolliere I would also include a breaking change that if a user does not include |
+1 for having consistent indices over Call, Event, etc. |
So I updated PR description:
|
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.
LGTM, some language nitpicks
frame/support/test/tests/construct_runtime_ui/conflicting_index.stderr
Outdated
Show resolved
Hide resolved
frame/support/test/tests/construct_runtime_ui/conflicting_index.stderr
Outdated
Show resolved
Hide resolved
frame/support/test/tests/construct_runtime_ui/conflicting_index_2.stderr
Outdated
Show resolved
Hide resolved
frame/support/test/tests/construct_runtime_ui/conflicting_index_2.stderr
Outdated
Show resolved
Hide resolved
Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
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.
looks good to me (only very high level review of macro changes)
fn find_part(&self, name: &str) -> Option<&ModulePart> { | ||
self.module_parts.iter().find(|part| part.name() == name) | ||
} | ||
|
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.
given assumption that System
is always there, maybe you can maybe simplify a thing or two by fn get_system() -> Option<&ModulePart>
or fn is_system() -> bool
but just an idea.
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.
indeed, for now system is only queried one time and filtered out only one time too, but if I would refactor such functions looks more readable.
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.
Brief view looks good!
bot merge |
Waiting for commit status. |
Does not include a runtime migration itself, but runtimes including this will need to migrate. |
Fix #6855
companion: paritytech/polkadot#1692
BREAKING CHANGE:
the encoding of Event, Call and Origin is changed:
Each variant of these enums are now encoded at the index of the pallet, the index of the pallet is defined similarly to rust fieldless
enum:
This breaking change result in the bump of metadata to version 12 which now provides for each module its index.
Note: Origin system variant is also encoded using this index, contrary to previously where it was fixed at index 0.
Note: to help migration, user should make use of indices in order not to break Call, and make use of scheduler::migrate_origin to update the usage of OriginCaller.
Context
This PR makes pallet having a fixed index. This avoid breaking call, event or origin when pallet definition changes. And ease adding/removing pallets.
So each pallet is now defined a fixed index either implicitly or using
= $index
syntax similarly to rust fieldless enum.Syntax:
(syntax is as followed as suggested by Gav but I can do as suggested by Basti in issue, it's only a matter of 10 lines of code)
The index must be a integer literal strictly less than 256, it is not allowed to be an expression as parity-scale-codec doesn't allow expression.
Metadata change
So the metadata has now this new information with a new field in module_metadata:
index: u8
. this index must be used when decoding call variant for corresponding module.cc @jacogr
TODO
Event
encoding, change some pallets error index polkadot#1692