FRAME: inherited call weight syntax (#13932)

* First approach on pallet::call_weight

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use attr on pallet::call instead

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Ui tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Rename to weight(prefix = ...))

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Simplify to #[pallet::call(weight(T))]

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add stray token error

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Cleanup

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Migrate remaining pallets

Using script from https://github.com/ggwpez/substrate-scripts/blob/e1b5ea5b5b4018867f3e869fce6f448b4ba9d71f/frame-code-migration/src/call_weight.rs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Try to add some docs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Revert "Migrate remaining pallets"

Lets do this as a follow-up, I dont want to bloat this small MR.

This reverts commit 331d4b42d72de1dacaed714d69166fa1bc9c92dd.

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Renames

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Review fixes

Co-authored-by: Sam Johnson <sam@durosoft.com>

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Test weights

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update UI tests

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update frame/support/procedural/src/pallet/parse/mod.rs

Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com>

* Remove old code

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update docs

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: parity-processbot <>
Co-authored-by: Muharem Ismailov <ismailov.m.h@gmail.com>
This commit is contained in:
Oliver Tale-Yazdi
2023-04-27 16:08:08 +02:00
committed by GitHub
parent 6e5141fc23
commit b5201fa0ec
30 changed files with 698 additions and 92 deletions
+1 -4
View File
@@ -441,7 +441,7 @@ pub mod pallet {
// against them as the first thing you do in your function. There are three convenience calls
// in system that do the matching for you and return a convenient result: `ensure_signed`,
// `ensure_root` and `ensure_none`.
#[pallet::call]
#[pallet::call(weight(<T as Config>::WeightInfo))]
impl<T: Config> Pallet<T> {
/// This is your public interface. Be extremely careful.
/// This is just a simple example of how to interact with the pallet from the external
@@ -497,9 +497,6 @@ pub mod pallet {
// The weight for this extrinsic we rely on the auto-generated `WeightInfo` from the
// benchmark toolchain.
#[pallet::call_index(0)]
#[pallet::weight(
<T as pallet::Config>::WeightInfo::accumulate_dummy()
)]
pub fn accumulate_dummy(origin: OriginFor<T>, increase_by: T::Balance) -> DispatchResult {
// This is a public call, so we ensure that the origin is some signed account.
let _sender = ensure_signed(origin)?;
@@ -192,6 +192,7 @@ fn weights_work() {
// aka. `let info = <Call<Test> as GetDispatchInfo>::get_dispatch_info(&default_call);`
// TODO: account for proof size weight
assert!(info1.weight.ref_time() > 0);
assert_eq!(info1.weight, <Test as Config>::WeightInfo::accumulate_dummy());
// `set_dummy` is simpler than `accumulate_dummy`, and the weight
// should be less.