Introduce #[pallet::call_index] attribute to dispatchables (#11381)

* Introduce #[pallet::call_index] attribute to dispatchables

* cargo fmt

* Add more docs and prevent duplicates of call indices

* Add UI test for conflicting call indices

* cargo fmt

Co-authored-by: parity-processbot <>
This commit is contained in:
Keith Yeung
2022-05-23 17:47:36 +01:00
committed by GitHub
parent 3122c4fb3c
commit 8d3f692e0c
11 changed files with 207 additions and 17 deletions
+15 -4
View File
@@ -1553,6 +1553,15 @@ pub mod pallet_prelude {
/// used using `#[pallet::compact]`, function must return `DispatchResultWithPostInfo` or
/// `DispatchResult`.
///
/// Each dispatchable may also be annotated with the `#[pallet::call_index($idx)]` attribute,
/// which defines and sets the codec index for the dispatchable function in the `Call` enum.
///
/// All call indexes start from 0, until it encounters a dispatchable function with a defined
/// call index. The dispatchable function that lexically follows the function with a defined
/// call index will have that call index, but incremented by 1, e.g. if there are 3
/// dispatchable functions `fn foo`, `fn bar` and `fn qux` in that order, and only `fn bar` has
/// a call index of 10, then `fn qux` will have an index of 11, instead of 1.
///
/// All arguments must implement `Debug`, `PartialEq`, `Eq`, `Decode`, `Encode`, `Clone`. For
/// ease of use, bound the trait `Member` available in frame_support::pallet_prelude.
///
@@ -1566,16 +1575,18 @@ pub mod pallet_prelude {
/// **WARNING**: modifying dispatchables, changing their order, removing some must be done with
/// care. Indeed this will change the outer runtime call type (which is an enum with one
/// variant per pallet), this outer runtime call can be stored on-chain (e.g. in
/// pallet-scheduler). Thus migration might be needed.
/// pallet-scheduler). Thus migration might be needed. To mitigate against some of this, the
/// `#[pallet::call_index($idx)]` attribute can be used to fix the order of the dispatchable so
/// that the `Call` enum encoding does not change after modification.
///
/// ### Macro expansion
///
/// The macro create an enum `Call` with one variant per dispatchable. This enum implements:
/// The macro creates an enum `Call` with one variant per dispatchable. This enum implements:
/// `Clone`, `Eq`, `PartialEq`, `Debug` (with stripped implementation in `not("std")`),
/// `Encode`, `Decode`, `GetDispatchInfo`, `GetCallName`, `UnfilteredDispatchable`.
///
/// The macro implement on `Pallet`, the `Callable` trait and a function `call_functions` which
/// returns the dispatchable metadatas.
/// The macro implement the `Callable` trait on `Pallet` and a function `call_functions` which
/// returns the dispatchable metadata.
///
/// # Extra constants: `#[pallet::extra_constants]` optional
///