From 8d931cba6a9cdefa31a810d558927d23282905ad Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 17 Apr 2023 14:14:47 +0200 Subject: [PATCH 01/17] First approach on pallet::call_weight Signed-off-by: Oliver Tale-Yazdi --- frame/alliance/src/lib.rs | 11 +---- frame/assets/src/lib.rs | 24 +---------- frame/balances/src/lib.rs | 6 +-- frame/examples/basic/src/lib.rs | 5 +-- frame/examples/basic/src/tests.rs | 1 + frame/support/procedural/src/lib.rs | 6 +++ .../procedural/src/pallet/expand/call.rs | 42 ++++++++++++++----- .../procedural/src/pallet/parse/call.rs | 36 +++++++++++----- .../src/pallet/parse/pallet_struct.rs | 31 ++++++++++++-- frame/support/src/lib.rs | 2 +- 10 files changed, 98 insertions(+), 66 deletions(-) diff --git a/frame/alliance/src/lib.rs b/frame/alliance/src/lib.rs index d50e20ba00c07..a415b0510005b 100644 --- a/frame/alliance/src/lib.rs +++ b/frame/alliance/src/lib.rs @@ -223,6 +223,7 @@ pub mod pallet { #[pallet::pallet] #[pallet::storage_version(migration::STORAGE_VERSION)] + //#[pallet::call_weight(trait >::WeightInfo)] pub struct Pallet(PhantomData<(T, I)>); #[pallet::config] @@ -649,7 +650,6 @@ pub mod pallet { /// Set a new IPFS CID to the alliance rule. #[pallet::call_index(5)] - #[pallet::weight(T::WeightInfo::set_rule())] pub fn set_rule(origin: OriginFor, rule: Cid) -> DispatchResult { T::AdminOrigin::ensure_origin(origin)?; @@ -661,7 +661,6 @@ pub mod pallet { /// Make an announcement of a new IPFS CID about alliance issues. #[pallet::call_index(6)] - #[pallet::weight(T::WeightInfo::announce())] pub fn announce(origin: OriginFor, announcement: Cid) -> DispatchResult { T::AnnouncementOrigin::ensure_origin(origin)?; @@ -677,7 +676,6 @@ pub mod pallet { /// Remove an announcement. #[pallet::call_index(7)] - #[pallet::weight(T::WeightInfo::remove_announcement())] pub fn remove_announcement(origin: OriginFor, announcement: Cid) -> DispatchResult { T::AnnouncementOrigin::ensure_origin(origin)?; @@ -695,7 +693,6 @@ pub mod pallet { /// Submit oneself for candidacy. A fixed deposit is reserved. #[pallet::call_index(8)] - #[pallet::weight(T::WeightInfo::join_alliance())] pub fn join_alliance(origin: OriginFor) -> DispatchResult { let who = ensure_signed(origin)?; @@ -732,7 +729,6 @@ pub mod pallet { /// A Fellow can nominate someone to join the alliance as an Ally. There is no deposit /// required from the nominator or nominee. #[pallet::call_index(9)] - #[pallet::weight(T::WeightInfo::nominate_ally())] pub fn nominate_ally(origin: OriginFor, who: AccountIdLookupOf) -> DispatchResult { let nominator = ensure_signed(origin)?; ensure!(Self::has_voting_rights(&nominator), Error::::NoVotingRights); @@ -757,7 +753,6 @@ pub mod pallet { /// Elevate an Ally to Fellow. #[pallet::call_index(10)] - #[pallet::weight(T::WeightInfo::elevate_ally())] pub fn elevate_ally(origin: OriginFor, ally: AccountIdLookupOf) -> DispatchResult { T::MembershipManager::ensure_origin(origin)?; let ally = T::Lookup::lookup(ally)?; @@ -774,7 +769,6 @@ pub mod pallet { /// As a member, give a retirement notice and start a retirement period required to pass in /// order to retire. #[pallet::call_index(11)] - #[pallet::weight(T::WeightInfo::give_retirement_notice())] pub fn give_retirement_notice(origin: OriginFor) -> DispatchResult { let who = ensure_signed(origin)?; let role = Self::member_role_of(&who).ok_or(Error::::NotMember)?; @@ -797,7 +791,6 @@ pub mod pallet { /// This can only be done once you have called `give_retirement_notice` and the /// `RetirementPeriod` has passed. #[pallet::call_index(12)] - #[pallet::weight(T::WeightInfo::retire())] pub fn retire(origin: OriginFor) -> DispatchResult { let who = ensure_signed(origin)?; let retirement_period_end = RetiringMembers::::get(&who) @@ -820,7 +813,6 @@ pub mod pallet { /// Kick a member from the Alliance and slash its deposit. #[pallet::call_index(13)] - #[pallet::weight(T::WeightInfo::kick_member())] pub fn kick_member(origin: OriginFor, who: AccountIdLookupOf) -> DispatchResult { T::MembershipManager::ensure_origin(origin)?; let member = T::Lookup::lookup(who)?; @@ -922,7 +914,6 @@ pub mod pallet { /// who do not want to leave the Alliance but do not have the capacity to participate /// operationally for some time. #[pallet::call_index(17)] - #[pallet::weight(T::WeightInfo::abdicate_fellow_status())] pub fn abdicate_fellow_status(origin: OriginFor) -> DispatchResult { let who = ensure_signed(origin)?; let role = Self::member_role_of(&who).ok_or(Error::::NotMember)?; diff --git a/frame/assets/src/lib.rs b/frame/assets/src/lib.rs index 859a13243d509..086c2b272180b 100644 --- a/frame/assets/src/lib.rs +++ b/frame/assets/src/lib.rs @@ -202,6 +202,7 @@ pub mod pallet { #[pallet::pallet] #[pallet::storage_version(STORAGE_VERSION)] + #[pallet::call_weight(trait >::WeightInfo)] pub struct Pallet(_); #[cfg(feature = "runtime-benchmarks")] @@ -590,7 +591,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(0)] - #[pallet::weight(T::WeightInfo::create())] pub fn create( origin: OriginFor, id: T::AssetIdParameter, @@ -654,7 +654,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::force_create())] pub fn force_create( origin: OriginFor, id: T::AssetIdParameter, @@ -680,7 +679,6 @@ pub mod pallet { /// /// The asset class must be frozen before calling `start_destroy`. #[pallet::call_index(2)] - #[pallet::weight(T::WeightInfo::start_destroy())] pub fn start_destroy(origin: OriginFor, id: T::AssetIdParameter) -> DispatchResult { let maybe_check_owner = match T::ForceOrigin::try_origin(origin) { Ok(_) => None, @@ -749,7 +747,6 @@ pub mod pallet { /// /// Each successful call emits the `Event::Destroyed` event. #[pallet::call_index(5)] - #[pallet::weight(T::WeightInfo::finish_destroy())] pub fn finish_destroy(origin: OriginFor, id: T::AssetIdParameter) -> DispatchResult { let _ = ensure_signed(origin)?; let id: T::AssetId = id.into(); @@ -769,7 +766,6 @@ pub mod pallet { /// Weight: `O(1)` /// Modes: Pre-existing balance of `beneficiary`; Account pre-existence of `beneficiary`. #[pallet::call_index(6)] - #[pallet::weight(T::WeightInfo::mint())] pub fn mint( origin: OriginFor, id: T::AssetIdParameter, @@ -799,7 +795,6 @@ pub mod pallet { /// Weight: `O(1)` /// Modes: Post-existence of `who`; Pre & post Zombie-status of `who`. #[pallet::call_index(7)] - #[pallet::weight(T::WeightInfo::burn())] pub fn burn( origin: OriginFor, id: T::AssetIdParameter, @@ -834,7 +829,6 @@ pub mod pallet { /// Modes: Pre-existence of `target`; Post-existence of sender; Account pre-existence of /// `target`. #[pallet::call_index(8)] - #[pallet::weight(T::WeightInfo::transfer())] pub fn transfer( origin: OriginFor, id: T::AssetIdParameter, @@ -868,7 +862,6 @@ pub mod pallet { /// Modes: Pre-existence of `target`; Post-existence of sender; Account pre-existence of /// `target`. #[pallet::call_index(9)] - #[pallet::weight(T::WeightInfo::transfer_keep_alive())] pub fn transfer_keep_alive( origin: OriginFor, id: T::AssetIdParameter, @@ -903,7 +896,6 @@ pub mod pallet { /// Modes: Pre-existence of `dest`; Post-existence of `source`; Account pre-existence of /// `dest`. #[pallet::call_index(10)] - #[pallet::weight(T::WeightInfo::force_transfer())] pub fn force_transfer( origin: OriginFor, id: T::AssetIdParameter, @@ -931,7 +923,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(11)] - #[pallet::weight(T::WeightInfo::freeze())] pub fn freeze( origin: OriginFor, id: T::AssetIdParameter, @@ -968,7 +959,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(12)] - #[pallet::weight(T::WeightInfo::thaw())] pub fn thaw( origin: OriginFor, id: T::AssetIdParameter, @@ -1004,7 +994,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(13)] - #[pallet::weight(T::WeightInfo::freeze_asset())] pub fn freeze_asset(origin: OriginFor, id: T::AssetIdParameter) -> DispatchResult { let origin = ensure_signed(origin)?; let id: T::AssetId = id.into(); @@ -1031,7 +1020,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(14)] - #[pallet::weight(T::WeightInfo::thaw_asset())] pub fn thaw_asset(origin: OriginFor, id: T::AssetIdParameter) -> DispatchResult { let origin = ensure_signed(origin)?; let id: T::AssetId = id.into(); @@ -1059,7 +1047,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(15)] - #[pallet::weight(T::WeightInfo::transfer_ownership())] pub fn transfer_ownership( origin: OriginFor, id: T::AssetIdParameter, @@ -1103,7 +1090,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(16)] - #[pallet::weight(T::WeightInfo::set_team())] pub fn set_team( origin: OriginFor, id: T::AssetIdParameter, @@ -1173,7 +1159,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(18)] - #[pallet::weight(T::WeightInfo::clear_metadata())] pub fn clear_metadata(origin: OriginFor, id: T::AssetIdParameter) -> DispatchResult { let origin = ensure_signed(origin)?; let id: T::AssetId = id.into(); @@ -1257,7 +1242,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(20)] - #[pallet::weight(T::WeightInfo::force_clear_metadata())] pub fn force_clear_metadata( origin: OriginFor, id: T::AssetIdParameter, @@ -1297,7 +1281,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(21)] - #[pallet::weight(T::WeightInfo::force_asset_status())] pub fn force_asset_status( origin: OriginFor, id: T::AssetIdParameter, @@ -1354,7 +1337,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(22)] - #[pallet::weight(T::WeightInfo::approve_transfer())] pub fn approve_transfer( origin: OriginFor, id: T::AssetIdParameter, @@ -1381,7 +1363,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(23)] - #[pallet::weight(T::WeightInfo::cancel_approval())] pub fn cancel_approval( origin: OriginFor, id: T::AssetIdParameter, @@ -1418,7 +1399,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(24)] - #[pallet::weight(T::WeightInfo::force_cancel_approval())] pub fn force_cancel_approval( origin: OriginFor, id: T::AssetIdParameter, @@ -1468,7 +1448,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(25)] - #[pallet::weight(T::WeightInfo::transfer_approved())] pub fn transfer_approved( origin: OriginFor, id: T::AssetIdParameter, @@ -1531,7 +1510,6 @@ pub mod pallet { /// /// Emits `AssetMinBalanceChanged` event when successful. #[pallet::call_index(28)] - #[pallet::weight(T::WeightInfo::set_min_balance())] pub fn set_min_balance( origin: OriginFor, id: T::AssetIdParameter, diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index 029a170535a10..4c1dcf008fe91 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -284,6 +284,7 @@ pub mod pallet { #[pallet::pallet] #[pallet::storage_version(STORAGE_VERSION)] + #[pallet::call_weight(trait >::WeightInfo)] pub struct Pallet(PhantomData<(T, I)>); #[pallet::event] @@ -529,7 +530,6 @@ pub mod pallet { /// /// The dispatch origin for this call must be `Signed` by the transactor. #[pallet::call_index(0)] - #[pallet::weight(T::WeightInfo::transfer_allow_death())] pub fn transfer_allow_death( origin: OriginFor, dest: AccountIdLookupOf, @@ -591,7 +591,6 @@ pub mod pallet { /// Exactly as `transfer_allow_death`, except the origin must be root and the source account /// may be specified. #[pallet::call_index(2)] - #[pallet::weight(T::WeightInfo::force_transfer())] pub fn force_transfer( origin: OriginFor, source: AccountIdLookupOf, @@ -612,7 +611,6 @@ pub mod pallet { /// /// [`transfer_allow_death`]: struct.Pallet.html#method.transfer #[pallet::call_index(3)] - #[pallet::weight(T::WeightInfo::transfer_keep_alive())] pub fn transfer_keep_alive( origin: OriginFor, dest: AccountIdLookupOf, @@ -640,7 +638,6 @@ pub mod pallet { /// transfer everything except at least the existential deposit, which will guarantee to /// keep the sender account alive (true). #[pallet::call_index(4)] - #[pallet::weight(T::WeightInfo::transfer_all())] pub fn transfer_all( origin: OriginFor, dest: AccountIdLookupOf, @@ -667,7 +664,6 @@ pub mod pallet { /// /// Can only be called by ROOT. #[pallet::call_index(5)] - #[pallet::weight(T::WeightInfo::force_unreserve())] pub fn force_unreserve( origin: OriginFor, who: AccountIdLookupOf, diff --git a/frame/examples/basic/src/lib.rs b/frame/examples/basic/src/lib.rs index 6665c3b78b024..ff743e4438c3f 100644 --- a/frame/examples/basic/src/lib.rs +++ b/frame/examples/basic/src/lib.rs @@ -379,6 +379,7 @@ pub mod pallet { // Simple declaration of the `Pallet` type. It is placeholder we use to implement traits and // method. #[pallet::pallet] + #[pallet::call_weight(trait ::WeightInfo)] pub struct Pallet(_); // Pallet implements [`Hooks`] trait to define some logic to execute in some context. @@ -497,9 +498,7 @@ 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( - ::WeightInfo::accumulate_dummy() - )] + // The weight is calculated from the `#[pallet::call_weight]` attribute. pub fn accumulate_dummy(origin: OriginFor, 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)?; diff --git a/frame/examples/basic/src/tests.rs b/frame/examples/basic/src/tests.rs index d9a8a4e8e1cdc..1d9cf81a5074c 100644 --- a/frame/examples/basic/src/tests.rs +++ b/frame/examples/basic/src/tests.rs @@ -192,6 +192,7 @@ fn weights_work() { // aka. `let info = as GetDispatchInfo>::get_dispatch_info(&default_call);` // TODO: account for proof size weight assert!(info1.weight.ref_time() > 0); + assert_eq!(info1.weight, ::WeightInfo::accumulate_dummy()); // `set_dummy` is simpler than `accumulate_dummy`, and the weight // should be less. diff --git a/frame/support/procedural/src/lib.rs b/frame/support/procedural/src/lib.rs index ea997752c3a53..82f5f13f51b82 100644 --- a/frame/support/procedural/src/lib.rs +++ b/frame/support/procedural/src/lib.rs @@ -865,6 +865,12 @@ pub fn generate_store(_: TokenStream, _: TokenStream) -> TokenStream { pallet_macro_stub() } +// FAIL-CI doc +#[proc_macro_attribute] +pub fn call_weight(_: TokenStream, _: TokenStream) -> TokenStream { + pallet_macro_stub() +} + /// To generate the full storage info (used for PoV calculation) use the attribute /// `#[pallet::generate_storage_info]`, e.g.: /// diff --git a/frame/support/procedural/src/pallet/expand/call.rs b/frame/support/procedural/src/pallet/expand/call.rs index aa5af9d54882f..2c395400e69ff 100644 --- a/frame/support/procedural/src/pallet/expand/call.rs +++ b/frame/support/procedural/src/pallet/expand/call.rs @@ -15,7 +15,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::{pallet::Def, COUNTER}; +use crate::{ + pallet::{parse::call::CallWeightDef, Def}, + COUNTER, +}; use quote::ToTokens; use syn::spanned::Spanned; @@ -74,15 +77,11 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream { call_index_warnings.push(warning); } - let fn_weight = methods.iter().map(|method| &method.weight); + let mut fn_weight = Vec::::new(); let mut weight_warnings = Vec::new(); - for weight in fn_weight.clone() { - if def.dev_mode { - continue - } - - match weight { - syn::Expr::Lit(lit) => { + for method in methods.iter() { + match &method.weight { + CallWeightDef::Immediate(e @ syn::Expr::Lit(lit)) if !def.dev_mode => { let warning = proc_macro_warning::Warning::new_deprecated("ConstantWeight") .index(weight_warnings.len()) .old("use hard-coded constant as call weight") @@ -91,10 +90,33 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream { .span(lit.span()) .build(); weight_warnings.push(warning); + fn_weight.push(e.clone()); + }, + CallWeightDef::Immediate(e) => fn_weight.push(e.clone()), + CallWeightDef::PalletInherited => { + // FAIL-CI check this already in the parsing step. + if let Some(ref pallet_weight) = def.pallet_struct.call_weight { + let t = &pallet_weight.weight_info; + let n = &method.name; + + fn_weight.push( + syn::parse::( + quote::quote!({ + #t :: #n () + }) + .into(), + ) + .expect("FAIL-CI"), + ); + } else { + panic!( + "Pallet call weight must be defined when using `#[pallet::call_weight]`" + ); + } }, - _ => {}, } } + debug_assert_eq!(fn_weight.len(), methods.len()); let fn_doc = methods.iter().map(|method| &method.docs).collect::>(); diff --git a/frame/support/procedural/src/pallet/parse/call.rs b/frame/support/procedural/src/pallet/parse/call.rs index ae1c039c9ddde..b785f789601f5 100644 --- a/frame/support/procedural/src/pallet/parse/call.rs +++ b/frame/support/procedural/src/pallet/parse/call.rs @@ -48,6 +48,17 @@ pub struct CallDef { pub docs: Vec, } +#[derive(Clone)] +pub enum CallWeightDef { + /// Explicitly set on the call itself. This value is used. + Immediate(syn::Expr), + + /// Inherits whatever value is configured on the pallet level. + /// + /// The concrete value is not known at this point. + PalletInherited, +} + /// Definition of dispatchable typically: `#[weight...] fn foo(origin .., param1: ...) -> ..` #[derive(Clone)] pub struct CallVariantDef { @@ -55,8 +66,8 @@ pub struct CallVariantDef { pub name: syn::Ident, /// Information on args: `(is_compact, name, type)` pub args: Vec<(bool, syn::Ident, Box)>, - /// Weight formula. - pub weight: syn::Expr, + /// Weight for the call. + pub weight: CallWeightDef, /// Call index of the dispatchable. pub call_index: u8, /// Whether an explicit call index was specified. @@ -228,18 +239,21 @@ impl CallDef { weight_attrs.push(FunctionAttr::Weight(empty_weight)); } - if weight_attrs.len() != 1 { + let weight = if weight_attrs.len() == 1 { + match weight_attrs.pop().unwrap() { + FunctionAttr::Weight(w) => CallWeightDef::Immediate(w), + _ => unreachable!("checked during creation of the let binding"), + } + } else if weight_attrs.len() == 0 { // FAIL-CI check that pallet defines + CallWeightDef::PalletInherited + /*} else { let msg = if weight_attrs.is_empty() { - "Invalid pallet::call, requires weight attribute i.e. `#[pallet::weight($expr)]`" - } else { - "Invalid pallet::call, too many weight attributes given" - }; + "Invalid pallet::call, requires weight attribute i.e. `#[pallet::weight($expr)]` or a pallet-wide weight info i.e. `#[pallet::call_weight(T::WeightInfo)]`"*/ + } else { + let msg = "Invalid pallet::call, too many weight attributes given"; return Err(syn::Error::new(method.sig.span(), msg)) - } - let weight = match weight_attrs.pop().unwrap() { - FunctionAttr::Weight(w) => w, - _ => unreachable!("checked during creation of the let binding"), }; + if call_idx_attrs.len() > 1 { let msg = "Invalid pallet::call, too many call_index attributes given"; diff --git a/frame/support/procedural/src/pallet/parse/pallet_struct.rs b/frame/support/procedural/src/pallet/parse/pallet_struct.rs index 98312d0652d8e..686e522feabdb 100644 --- a/frame/support/procedural/src/pallet/parse/pallet_struct.rs +++ b/frame/support/procedural/src/pallet/parse/pallet_struct.rs @@ -27,6 +27,7 @@ mod keyword { syn::custom_keyword!(without_storage_info); syn::custom_keyword!(storage_version); syn::custom_keyword!(Store); + syn::custom_keyword!(call_weight); } /// Definition of the pallet pallet. @@ -46,24 +47,35 @@ pub struct PalletStructDef { pub without_storage_info: Option, /// The current storage version of the pallet. pub storage_version: Option, + pub call_weight: Option, } /// Parse for one variant of: /// * `#[pallet::generate_store($vis trait Store)]` /// * `#[pallet::without_storage_info]` /// * `#[pallet::storage_version(STORAGE_VERSION)]` +/// * `#[pallet::call_weight($weight_trait)]` pub enum PalletStructAttr { GenerateStore { span: proc_macro2::Span, vis: syn::Visibility, keyword: keyword::Store }, WithoutStorageInfoTrait(proc_macro2::Span), StorageVersion { storage_version: syn::Path, span: proc_macro2::Span }, + CallWeight(PalletCallWeight), +} + +#[derive(Clone)] +pub struct PalletCallWeight { + // FAIL-CI rename + pub weight_info: syn::Type, + pub span: proc_macro2::Span, } impl PalletStructAttr { fn span(&self) -> proc_macro2::Span { match self { - Self::GenerateStore { span, .. } => *span, - Self::WithoutStorageInfoTrait(span) => *span, - Self::StorageVersion { span, .. } => *span, + Self::GenerateStore { span, .. } | + Self::WithoutStorageInfoTrait(span) | + Self::StorageVersion { span, .. } | + Self::CallWeight(PalletCallWeight { span, .. }) => *span, } } } @@ -97,6 +109,14 @@ impl syn::parse::Parse for PalletStructAttr { let storage_version = version_content.parse::()?; Ok(Self::StorageVersion { storage_version, span }) + } else if lookahead.peek(keyword::call_weight) { + let span = content.parse::().expect("peeked").span(); + let attr_content; + syn::parenthesized!(attr_content in content); + attr_content.parse::()?; + let weight_info = attr_content.parse::()?; + + Ok(Self::CallWeight(PalletCallWeight { weight_info, span })) } else { Err(lookahead.error()) } @@ -119,6 +139,7 @@ impl PalletStructDef { let mut store = None; let mut without_storage_info = None; let mut storage_version_found = None; + let mut call_weight = None; let struct_attrs: Vec = helper::take_item_pallet_attrs(&mut item.attrs)?; for attr in struct_attrs { @@ -136,6 +157,9 @@ impl PalletStructDef { { storage_version_found = Some(storage_version); }, + PalletStructAttr::CallWeight(cw) if call_weight.is_none() => { + call_weight = Some(cw); + }, attr => { let msg = "Unexpected duplicated attribute"; return Err(syn::Error::new(attr.span(), msg)) @@ -166,6 +190,7 @@ impl PalletStructDef { attr_span, without_storage_info, storage_version: storage_version_found, + call_weight, }) } } diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index 036bd93464b9f..1b0fc10297290 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -2529,7 +2529,7 @@ pub mod pallet_prelude { /// #[pallet::extra_constants] /// impl, I: 'static> Pallet { /// /// Some description -/// fn exra_constant_name() -> u128 { 4u128 } +/// fn extra_constant_name() -> u128 { 4u128 } /// } /// /// #[pallet::pallet] From d2ebeada9732df4c767cb6839f1fcebe279a1fc0 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 17 Apr 2023 14:59:20 +0200 Subject: [PATCH 02/17] Use attr on pallet::call instead Signed-off-by: Oliver Tale-Yazdi --- frame/alliance/src/lib.rs | 3 +- frame/assets/src/lib.rs | 3 +- frame/balances/src/lib.rs | 3 +- frame/examples/basic/src/lib.rs | 4 +- frame/support/procedural/src/lib.rs | 6 --- .../procedural/src/pallet/expand/call.rs | 45 +++++++++---------- .../procedural/src/pallet/parse/call.rs | 30 +++++++------ .../procedural/src/pallet/parse/mod.rs | 27 ++++++++--- .../src/pallet/parse/pallet_struct.rs | 26 +---------- 9 files changed, 64 insertions(+), 83 deletions(-) diff --git a/frame/alliance/src/lib.rs b/frame/alliance/src/lib.rs index a415b0510005b..845f369b57f3e 100644 --- a/frame/alliance/src/lib.rs +++ b/frame/alliance/src/lib.rs @@ -223,7 +223,6 @@ pub mod pallet { #[pallet::pallet] #[pallet::storage_version(migration::STORAGE_VERSION)] - //#[pallet::call_weight(trait >::WeightInfo)] pub struct Pallet(PhantomData<(T, I)>); #[pallet::config] @@ -498,7 +497,7 @@ pub mod pallet { pub type UnscrupulousWebsites, I: 'static = ()> = StorageValue<_, BoundedVec, T::MaxUnscrupulousItems>, ValueQuery>; - #[pallet::call] + #[pallet::call(trait >::WeightInfo)] impl, I: 'static> Pallet { /// Add a new proposal to be voted on. /// diff --git a/frame/assets/src/lib.rs b/frame/assets/src/lib.rs index 086c2b272180b..533148d2cb5fd 100644 --- a/frame/assets/src/lib.rs +++ b/frame/assets/src/lib.rs @@ -202,7 +202,6 @@ pub mod pallet { #[pallet::pallet] #[pallet::storage_version(STORAGE_VERSION)] - #[pallet::call_weight(trait >::WeightInfo)] pub struct Pallet(_); #[cfg(feature = "runtime-benchmarks")] @@ -569,7 +568,7 @@ pub mod pallet { CallbackFailed, } - #[pallet::call] + #[pallet::call(trait >::WeightInfo)] impl, I: 'static> Pallet { /// Issue a new class of fungible assets from a public origin. /// diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index 4c1dcf008fe91..c5bfb1e141198 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -284,7 +284,6 @@ pub mod pallet { #[pallet::pallet] #[pallet::storage_version(STORAGE_VERSION)] - #[pallet::call_weight(trait >::WeightInfo)] pub struct Pallet(PhantomData<(T, I)>); #[pallet::event] @@ -520,7 +519,7 @@ pub mod pallet { } } - #[pallet::call] + #[pallet::call(trait >::WeightInfo)] impl, I: 'static> Pallet { /// Transfer some liquid free balance to another account. /// diff --git a/frame/examples/basic/src/lib.rs b/frame/examples/basic/src/lib.rs index ff743e4438c3f..f837352d0f600 100644 --- a/frame/examples/basic/src/lib.rs +++ b/frame/examples/basic/src/lib.rs @@ -379,7 +379,6 @@ pub mod pallet { // Simple declaration of the `Pallet` type. It is placeholder we use to implement traits and // method. #[pallet::pallet] - #[pallet::call_weight(trait ::WeightInfo)] pub struct Pallet(_); // Pallet implements [`Hooks`] trait to define some logic to execute in some context. @@ -442,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(trait ::WeightInfo)] impl Pallet { /// This is your public interface. Be extremely careful. /// This is just a simple example of how to interact with the pallet from the external @@ -498,7 +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)] - // The weight is calculated from the `#[pallet::call_weight]` attribute. pub fn accumulate_dummy(origin: OriginFor, 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)?; diff --git a/frame/support/procedural/src/lib.rs b/frame/support/procedural/src/lib.rs index 82f5f13f51b82..ea997752c3a53 100644 --- a/frame/support/procedural/src/lib.rs +++ b/frame/support/procedural/src/lib.rs @@ -865,12 +865,6 @@ pub fn generate_store(_: TokenStream, _: TokenStream) -> TokenStream { pallet_macro_stub() } -// FAIL-CI doc -#[proc_macro_attribute] -pub fn call_weight(_: TokenStream, _: TokenStream) -> TokenStream { - pallet_macro_stub() -} - /// To generate the full storage info (used for PoV calculation) use the attribute /// `#[pallet::generate_storage_info]`, e.g.: /// diff --git a/frame/support/procedural/src/pallet/expand/call.rs b/frame/support/procedural/src/pallet/expand/call.rs index 2c395400e69ff..5f163f0af5a73 100644 --- a/frame/support/procedural/src/pallet/expand/call.rs +++ b/frame/support/procedural/src/pallet/expand/call.rs @@ -19,7 +19,8 @@ use crate::{ pallet::{parse::call::CallWeightDef, Def}, COUNTER, }; -use quote::ToTokens; +use proc_macro2::TokenStream as TokenStream2; +use quote::{quote, ToTokens}; use syn::spanned::Spanned; /// @@ -77,10 +78,13 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream { call_index_warnings.push(warning); } - let mut fn_weight = Vec::::new(); + let mut fn_weight = Vec::::new(); let mut weight_warnings = Vec::new(); for method in methods.iter() { match &method.weight { + CallWeightDef::DevModeDefault => { + fn_weight.push(syn::parse_quote!(0)); + }, CallWeightDef::Immediate(e @ syn::Expr::Lit(lit)) if !def.dev_mode => { let warning = proc_macro_warning::Warning::new_deprecated("ConstantWeight") .index(weight_warnings.len()) @@ -90,29 +94,22 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream { .span(lit.span()) .build(); weight_warnings.push(warning); - fn_weight.push(e.clone()); + fn_weight.push(e.into_token_stream()); }, - CallWeightDef::Immediate(e) => fn_weight.push(e.clone()), - CallWeightDef::PalletInherited => { - // FAIL-CI check this already in the parsing step. - if let Some(ref pallet_weight) = def.pallet_struct.call_weight { - let t = &pallet_weight.weight_info; - let n = &method.name; - - fn_weight.push( - syn::parse::( - quote::quote!({ - #t :: #n () - }) - .into(), - ) - .expect("FAIL-CI"), - ); - } else { - panic!( - "Pallet call weight must be defined when using `#[pallet::call_weight]`" - ); - } + CallWeightDef::Immediate(e) => fn_weight.push(e.into_token_stream()), + CallWeightDef::Inherited => { + let pallet_weight = def + .call + .as_ref() + .expect("we have methods; we have calls; qed") + .call_weight + .as_ref() + .expect("the parser prevents this"); + + // Expand `::WeightInfo::call_name()`. + let t = &pallet_weight.typename; + let n = &method.name; + fn_weight.push(quote!({ #t :: #n () })); }, } } diff --git a/frame/support/procedural/src/pallet/parse/call.rs b/frame/support/procedural/src/pallet/parse/call.rs index b785f789601f5..50345ea51826a 100644 --- a/frame/support/procedural/src/pallet/parse/call.rs +++ b/frame/support/procedural/src/pallet/parse/call.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use super::helper; +use super::{helper, RuntimeCallWeightAttr}; use frame_support_procedural_tools::get_doc_literals; use quote::ToTokens; use std::collections::HashMap; @@ -46,17 +46,20 @@ pub struct CallDef { pub attr_span: proc_macro2::Span, /// Docs, specified on the impl Block. pub docs: Vec, + pub call_weight: Option, } #[derive(Clone)] pub enum CallWeightDef { + /// The default value that should be set for dev-mode pallets. Usually zero. + DevModeDefault, /// Explicitly set on the call itself. This value is used. Immediate(syn::Expr), /// Inherits whatever value is configured on the pallet level. /// /// The concrete value is not known at this point. - PalletInherited, + Inherited, } /// Definition of dispatchable typically: `#[weight...] fn foo(origin .., param1: ...) -> ..` @@ -162,6 +165,7 @@ impl CallDef { index: usize, item: &mut syn::Item, dev_mode: bool, + pallet_call_weight: Option, ) -> syn::Result { let item_impl = if let syn::Item::Impl(item) = item { item @@ -239,21 +243,18 @@ impl CallDef { weight_attrs.push(FunctionAttr::Weight(empty_weight)); } - let weight = if weight_attrs.len() == 1 { - match weight_attrs.pop().unwrap() { + let weight = match weight_attrs.len() { + 0 if pallet_call_weight.is_some() => CallWeightDef::Inherited, + 0 if dev_mode => CallWeightDef::DevModeDefault, + 1 => match weight_attrs.pop().unwrap() { FunctionAttr::Weight(w) => CallWeightDef::Immediate(w), _ => unreachable!("checked during creation of the let binding"), - } - } else if weight_attrs.len() == 0 { // FAIL-CI check that pallet defines - CallWeightDef::PalletInherited - /*} else { - let msg = if weight_attrs.is_empty() { - "Invalid pallet::call, requires weight attribute i.e. `#[pallet::weight($expr)]` or a pallet-wide weight info i.e. `#[pallet::call_weight(T::WeightInfo)]`"*/ - } else { - let msg = "Invalid pallet::call, too many weight attributes given"; - return Err(syn::Error::new(method.sig.span(), msg)) + }, + _ => { + let msg = "Invalid pallet::call, too many weight attributes given"; + return Err(syn::Error::new(method.sig.span(), msg)) + }, }; - if call_idx_attrs.len() > 1 { let msg = "Invalid pallet::call, too many call_index attributes given"; @@ -335,6 +336,7 @@ impl CallDef { methods, where_clause: item_impl.generics.where_clause.clone(), docs: get_doc_literals(&item_impl.attrs), + call_weight: pallet_call_weight, }) } } diff --git a/frame/support/procedural/src/pallet/parse/mod.rs b/frame/support/procedural/src/pallet/parse/mod.rs index 06b9899d03b97..d4c94419be971 100644 --- a/frame/support/procedural/src/pallet/parse/mod.rs +++ b/frame/support/procedural/src/pallet/parse/mod.rs @@ -110,8 +110,8 @@ impl Def { let m = hooks::HooksDef::try_from(span, index, item)?; hooks = Some(m); }, - Some(PalletAttr::RuntimeCall(span)) if call.is_none() => - call = Some(call::CallDef::try_from(span, index, item, dev_mode)?), + Some(PalletAttr::RuntimeCall(cw, span)) if call.is_none() => + call = Some(call::CallDef::try_from(span, index, item, dev_mode, cw)?), Some(PalletAttr::Error(span)) if error.is_none() => error = Some(error::ErrorDef::try_from(span, index, item)?), Some(PalletAttr::RuntimeEvent(span)) if event.is_none() => @@ -425,7 +425,7 @@ enum PalletAttr { Config(proc_macro2::Span), Pallet(proc_macro2::Span), Hooks(proc_macro2::Span), - RuntimeCall(proc_macro2::Span), + RuntimeCall(Option, proc_macro2::Span), Error(proc_macro2::Span), RuntimeEvent(proc_macro2::Span), RuntimeOrigin(proc_macro2::Span), @@ -445,7 +445,7 @@ impl PalletAttr { Self::Config(span) => *span, Self::Pallet(span) => *span, Self::Hooks(span) => *span, - Self::RuntimeCall(span) => *span, + Self::RuntimeCall(_, span) => *span, Self::Error(span) => *span, Self::RuntimeEvent(span) => *span, Self::RuntimeOrigin(span) => *span, @@ -477,7 +477,17 @@ impl syn::parse::Parse for PalletAttr { } else if lookahead.peek(keyword::hooks) { Ok(PalletAttr::Hooks(content.parse::()?.span())) } else if lookahead.peek(keyword::call) { - Ok(PalletAttr::RuntimeCall(content.parse::()?.span())) + let span = content.parse::().expect("peeked").span(); + if content.is_empty() { + return Ok(PalletAttr::RuntimeCall(None, span)) + } + + let attr_content; + syn::parenthesized!(attr_content in content); + attr_content.parse::()?; + let typename = attr_content.parse::()?; + + Ok(PalletAttr::RuntimeCall(Some(RuntimeCallWeightAttr { typename, span }), span)) } else if lookahead.peek(keyword::error) { Ok(PalletAttr::Error(content.parse::()?.span())) } else if lookahead.peek(keyword::event) { @@ -505,3 +515,10 @@ impl syn::parse::Parse for PalletAttr { } } } + +/// The optional weight annotation on a `#[pallet::call]` like `#[pallet::call(trait $type)]` +#[derive(Clone)] +pub struct RuntimeCallWeightAttr { + pub typename: syn::Type, + pub span: proc_macro2::Span, +} diff --git a/frame/support/procedural/src/pallet/parse/pallet_struct.rs b/frame/support/procedural/src/pallet/parse/pallet_struct.rs index 686e522feabdb..122ec4eeaf4e3 100644 --- a/frame/support/procedural/src/pallet/parse/pallet_struct.rs +++ b/frame/support/procedural/src/pallet/parse/pallet_struct.rs @@ -27,7 +27,6 @@ mod keyword { syn::custom_keyword!(without_storage_info); syn::custom_keyword!(storage_version); syn::custom_keyword!(Store); - syn::custom_keyword!(call_weight); } /// Definition of the pallet pallet. @@ -47,7 +46,6 @@ pub struct PalletStructDef { pub without_storage_info: Option, /// The current storage version of the pallet. pub storage_version: Option, - pub call_weight: Option, } /// Parse for one variant of: @@ -59,14 +57,6 @@ pub enum PalletStructAttr { GenerateStore { span: proc_macro2::Span, vis: syn::Visibility, keyword: keyword::Store }, WithoutStorageInfoTrait(proc_macro2::Span), StorageVersion { storage_version: syn::Path, span: proc_macro2::Span }, - CallWeight(PalletCallWeight), -} - -#[derive(Clone)] -pub struct PalletCallWeight { - // FAIL-CI rename - pub weight_info: syn::Type, - pub span: proc_macro2::Span, } impl PalletStructAttr { @@ -74,8 +64,7 @@ impl PalletStructAttr { match self { Self::GenerateStore { span, .. } | Self::WithoutStorageInfoTrait(span) | - Self::StorageVersion { span, .. } | - Self::CallWeight(PalletCallWeight { span, .. }) => *span, + Self::StorageVersion { span, .. } => *span, } } } @@ -109,14 +98,6 @@ impl syn::parse::Parse for PalletStructAttr { let storage_version = version_content.parse::()?; Ok(Self::StorageVersion { storage_version, span }) - } else if lookahead.peek(keyword::call_weight) { - let span = content.parse::().expect("peeked").span(); - let attr_content; - syn::parenthesized!(attr_content in content); - attr_content.parse::()?; - let weight_info = attr_content.parse::()?; - - Ok(Self::CallWeight(PalletCallWeight { weight_info, span })) } else { Err(lookahead.error()) } @@ -139,7 +120,6 @@ impl PalletStructDef { let mut store = None; let mut without_storage_info = None; let mut storage_version_found = None; - let mut call_weight = None; let struct_attrs: Vec = helper::take_item_pallet_attrs(&mut item.attrs)?; for attr in struct_attrs { @@ -157,9 +137,6 @@ impl PalletStructDef { { storage_version_found = Some(storage_version); }, - PalletStructAttr::CallWeight(cw) if call_weight.is_none() => { - call_weight = Some(cw); - }, attr => { let msg = "Unexpected duplicated attribute"; return Err(syn::Error::new(attr.span(), msg)) @@ -190,7 +167,6 @@ impl PalletStructDef { attr_span, without_storage_info, storage_version: storage_version_found, - call_weight, }) } } From 09e933817344afca68b7599a972e553e795085c0 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 17 Apr 2023 15:39:16 +0200 Subject: [PATCH 03/17] Ui tests Signed-off-by: Oliver Tale-Yazdi --- frame/alliance/src/lib.rs | 2 +- frame/assets/src/lib.rs | 2 +- frame/balances/src/lib.rs | 2 +- frame/examples/basic/src/lib.rs | 2 +- .../procedural/src/pallet/expand/call.rs | 4 +- .../procedural/src/pallet/parse/call.rs | 4 ++ .../procedural/src/pallet/parse/mod.rs | 4 +- .../pallet_ui/call_missing_weight.stderr | 4 +- .../call_weight_inherited_invalid.rs | 29 ++++++++++++++ .../call_weight_inherited_invalid.stderr | 5 +++ .../call_weight_inherited_invalid2.rs | 29 ++++++++++++++ .../call_weight_inherited_invalid2.stderr | 5 +++ .../tests/pallet_ui/dev_mode_without_arg.rs | 2 - .../pallet_ui/dev_mode_without_arg.stderr | 12 ++---- .../pallet_ui/pass/inherited_call_weight.rs | 30 +++++++++++++++ .../pallet_ui/pass/inherited_call_weight2.rs | 36 ++++++++++++++++++ .../pallet_ui/pass/inherited_call_weight3.rs | 38 +++++++++++++++++++ .../pass/inherited_call_weight_dev_mode.rs | 30 +++++++++++++++ 18 files changed, 219 insertions(+), 21 deletions(-) create mode 100644 frame/support/test/tests/pallet_ui/call_weight_inherited_invalid.rs create mode 100644 frame/support/test/tests/pallet_ui/call_weight_inherited_invalid.stderr create mode 100644 frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.rs create mode 100644 frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.stderr create mode 100644 frame/support/test/tests/pallet_ui/pass/inherited_call_weight.rs create mode 100644 frame/support/test/tests/pallet_ui/pass/inherited_call_weight2.rs create mode 100644 frame/support/test/tests/pallet_ui/pass/inherited_call_weight3.rs create mode 100644 frame/support/test/tests/pallet_ui/pass/inherited_call_weight_dev_mode.rs diff --git a/frame/alliance/src/lib.rs b/frame/alliance/src/lib.rs index 845f369b57f3e..221ad9935f0b8 100644 --- a/frame/alliance/src/lib.rs +++ b/frame/alliance/src/lib.rs @@ -497,7 +497,7 @@ pub mod pallet { pub type UnscrupulousWebsites, I: 'static = ()> = StorageValue<_, BoundedVec, T::MaxUnscrupulousItems>, ValueQuery>; - #[pallet::call(trait >::WeightInfo)] + #[pallet::call(impl >::WeightInfo)] impl, I: 'static> Pallet { /// Add a new proposal to be voted on. /// diff --git a/frame/assets/src/lib.rs b/frame/assets/src/lib.rs index 533148d2cb5fd..9edc96bf24996 100644 --- a/frame/assets/src/lib.rs +++ b/frame/assets/src/lib.rs @@ -568,7 +568,7 @@ pub mod pallet { CallbackFailed, } - #[pallet::call(trait >::WeightInfo)] + #[pallet::call(impl >::WeightInfo)] impl, I: 'static> Pallet { /// Issue a new class of fungible assets from a public origin. /// diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index c5bfb1e141198..5d9279d2c0a3a 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -519,7 +519,7 @@ pub mod pallet { } } - #[pallet::call(trait >::WeightInfo)] + #[pallet::call(impl >::WeightInfo)] impl, I: 'static> Pallet { /// Transfer some liquid free balance to another account. /// diff --git a/frame/examples/basic/src/lib.rs b/frame/examples/basic/src/lib.rs index f837352d0f600..53d62385c48c8 100644 --- a/frame/examples/basic/src/lib.rs +++ b/frame/examples/basic/src/lib.rs @@ -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(trait ::WeightInfo)] + #[pallet::call(impl ::WeightInfo)] impl Pallet { /// This is your public interface. Be extremely careful. /// This is just a simple example of how to interact with the pallet from the external diff --git a/frame/support/procedural/src/pallet/expand/call.rs b/frame/support/procedural/src/pallet/expand/call.rs index 5f163f0af5a73..6fd9f2bdc5aec 100644 --- a/frame/support/procedural/src/pallet/expand/call.rs +++ b/frame/support/procedural/src/pallet/expand/call.rs @@ -106,10 +106,10 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream { .as_ref() .expect("the parser prevents this"); - // Expand `::WeightInfo::call_name()`. + // Expand `<::WeightInfo>::call_name()`. let t = &pallet_weight.typename; let n = &method.name; - fn_weight.push(quote!({ #t :: #n () })); + fn_weight.push(quote!({ < #t > :: #n () })); }, } } diff --git a/frame/support/procedural/src/pallet/parse/call.rs b/frame/support/procedural/src/pallet/parse/call.rs index 50345ea51826a..12fe98fe4419c 100644 --- a/frame/support/procedural/src/pallet/parse/call.rs +++ b/frame/support/procedural/src/pallet/parse/call.rs @@ -246,6 +246,10 @@ impl CallDef { let weight = match weight_attrs.len() { 0 if pallet_call_weight.is_some() => CallWeightDef::Inherited, 0 if dev_mode => CallWeightDef::DevModeDefault, + 0 => return Err(syn::Error::new( + method.sig.span(), + "A pallet::call requires either a concrete `#[pallet::weight($expr)]` or an inherited weight from the `#[pallet:call(trait ...)]` attribute, but none were given.", + )), 1 => match weight_attrs.pop().unwrap() { FunctionAttr::Weight(w) => CallWeightDef::Immediate(w), _ => unreachable!("checked during creation of the let binding"), diff --git a/frame/support/procedural/src/pallet/parse/mod.rs b/frame/support/procedural/src/pallet/parse/mod.rs index d4c94419be971..261cc742795cb 100644 --- a/frame/support/procedural/src/pallet/parse/mod.rs +++ b/frame/support/procedural/src/pallet/parse/mod.rs @@ -484,7 +484,7 @@ impl syn::parse::Parse for PalletAttr { let attr_content; syn::parenthesized!(attr_content in content); - attr_content.parse::()?; + attr_content.parse::()?; let typename = attr_content.parse::()?; Ok(PalletAttr::RuntimeCall(Some(RuntimeCallWeightAttr { typename, span }), span)) @@ -516,7 +516,7 @@ impl syn::parse::Parse for PalletAttr { } } -/// The optional weight annotation on a `#[pallet::call]` like `#[pallet::call(trait $type)]` +/// The optional weight annotation on a `#[pallet::call]` like `#[pallet::call(impl $type)]` #[derive(Clone)] pub struct RuntimeCallWeightAttr { pub typename: syn::Type, diff --git a/frame/support/test/tests/pallet_ui/call_missing_weight.stderr b/frame/support/test/tests/pallet_ui/call_missing_weight.stderr index ec45d478870c1..46d385a11eb7c 100644 --- a/frame/support/test/tests/pallet_ui/call_missing_weight.stderr +++ b/frame/support/test/tests/pallet_ui/call_missing_weight.stderr @@ -1,5 +1,5 @@ -error: Invalid pallet::call, requires weight attribute i.e. `#[pallet::weight($expr)]` - --> $DIR/call_missing_weight.rs:17:7 +error: A pallet::call requires either a concrete weight via `#[pallet::weight]` or an inherited one from the `#[pallet:call(trait ...)]` attribute but none were given. + --> tests/pallet_ui/call_missing_weight.rs:17:7 | 17 | pub fn foo(origin: OriginFor) -> DispatchResultWithPostInfo {} | ^^ diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid.rs b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid.rs new file mode 100644 index 0000000000000..9781f8077b75e --- /dev/null +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid.rs @@ -0,0 +1,29 @@ +use frame_support::pallet_prelude::*; + +pub trait WeightInfo { + fn foo() -> Weight; +} + +#[frame_support::pallet] +mod pallet { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type WeightInfo: crate::WeightInfo; + } + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::call(123)] + impl Pallet { + #[pallet::call_index(0)] + pub fn foo(_: OriginFor) -> DispatchResult { + Ok(()) + } + } +} + +fn main() { +} diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid.stderr b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid.stderr new file mode 100644 index 0000000000000..69f0db02d446f --- /dev/null +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid.stderr @@ -0,0 +1,5 @@ +error: expected `impl` + --> tests/pallet_ui/call_weight_inherited_invalid.rs:19:17 + | +19 | #[pallet::call(123)] + | ^^^ diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.rs b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.rs new file mode 100644 index 0000000000000..ab2e6824d6e0b --- /dev/null +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.rs @@ -0,0 +1,29 @@ +use frame_support::pallet_prelude::*; + +pub trait WeightInfo { + fn foo() -> Weight; +} + +#[frame_support::pallet] +mod pallet { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type WeightInfo: crate::WeightInfo; + } + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::call(impl ::WeightInfo 654)] + impl Pallet { + #[pallet::call_index(0)] + pub fn foo(_: OriginFor) -> DispatchResult { + Ok(()) + } + } +} + +fn main() { +} diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.stderr b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.stderr new file mode 100644 index 0000000000000..7d6e8b1113ab1 --- /dev/null +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.stderr @@ -0,0 +1,5 @@ +error: unexpected token + --> tests/pallet_ui/call_weight_inherited_invalid2.rs:19:48 + | +19 | #[pallet::call(impl ::WeightInfo 654)] + | ^^^ diff --git a/frame/support/test/tests/pallet_ui/dev_mode_without_arg.rs b/frame/support/test/tests/pallet_ui/dev_mode_without_arg.rs index f044ae6d7878f..2a413eea9b4aa 100644 --- a/frame/support/test/tests/pallet_ui/dev_mode_without_arg.rs +++ b/frame/support/test/tests/pallet_ui/dev_mode_without_arg.rs @@ -1,7 +1,5 @@ #![cfg_attr(not(feature = "std"), no_std)] -pub use pallet::*; - #[frame_support::pallet] pub mod pallet { use frame_support::pallet_prelude::*; diff --git a/frame/support/test/tests/pallet_ui/dev_mode_without_arg.stderr b/frame/support/test/tests/pallet_ui/dev_mode_without_arg.stderr index fac7fd77df9ae..289017a75e55e 100644 --- a/frame/support/test/tests/pallet_ui/dev_mode_without_arg.stderr +++ b/frame/support/test/tests/pallet_ui/dev_mode_without_arg.stderr @@ -1,11 +1,5 @@ -error: Invalid pallet::call, requires weight attribute i.e. `#[pallet::weight($expr)]` - --> tests/pallet_ui/dev_mode_without_arg.rs:24:7 +error: A pallet::call requires either a concrete weight via `#[pallet::weight]` or an inherited one from the `#[pallet:call(trait ...)]` attribute but none were given. + --> tests/pallet_ui/dev_mode_without_arg.rs:22:7 | -24 | pub fn my_call(_origin: OriginFor) -> DispatchResult { +22 | pub fn my_call(_origin: OriginFor) -> DispatchResult { | ^^ - -error[E0432]: unresolved import `pallet` - --> tests/pallet_ui/dev_mode_without_arg.rs:3:9 - | -3 | pub use pallet::*; - | ^^^^^^ help: a similar path exists: `test_pallet::pallet` diff --git a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight.rs b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight.rs new file mode 100644 index 0000000000000..9159f83640fac --- /dev/null +++ b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight.rs @@ -0,0 +1,30 @@ +use frame_support::pallet_prelude::*; +use frame_system::pallet_prelude::*; + +pub trait WeightInfo { + fn foo() -> Weight; +} + +#[frame_support::pallet] +mod pallet { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type WeightInfo: crate::WeightInfo; + } + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::call(impl ::WeightInfo)] + impl Pallet { + #[pallet::call_index(0)] + pub fn foo(_: OriginFor) -> DispatchResult { + Ok(()) + } + } +} + +fn main() { +} diff --git a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight2.rs b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight2.rs new file mode 100644 index 0000000000000..0055578c49f1d --- /dev/null +++ b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight2.rs @@ -0,0 +1,36 @@ +use frame_support::pallet_prelude::*; +use frame_system::pallet_prelude::*; + +pub trait WeightInfo { + fn foo() -> Weight; +} + +impl WeightInfo for () { + fn foo() -> Weight { + Weight::zero() + } +} + +#[frame_support::pallet] +mod pallet { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + } + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + // Crazy man just uses `()`, but it still works ;) + #[pallet::call(impl ())] + impl Pallet { + #[pallet::call_index(0)] + pub fn foo(_: OriginFor) -> DispatchResult { + Ok(()) + } + } +} + +fn main() { +} diff --git a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight3.rs b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight3.rs new file mode 100644 index 0000000000000..0937c4c2ad534 --- /dev/null +++ b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight3.rs @@ -0,0 +1,38 @@ +use frame_support::pallet_prelude::*; +use frame_system::pallet_prelude::*; + +pub trait WeightInfo { + fn foo() -> Weight; +} + +// If, for whatever reason, you dont to not use a `WeightInfo` trait; it will still work. +struct Impl; + +impl WeightInfo for Impl { + fn foo() -> Weight { + Weight::zero() + } +} + +#[frame_support::pallet] +mod pallet { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + } + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::call(impl crate::Impl)] + impl Pallet { + #[pallet::call_index(0)] + pub fn foo(_: OriginFor) -> DispatchResult { + Ok(()) + } + } +} + +fn main() { +} diff --git a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight_dev_mode.rs b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight_dev_mode.rs new file mode 100644 index 0000000000000..3b653689b6317 --- /dev/null +++ b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight_dev_mode.rs @@ -0,0 +1,30 @@ +use frame_support::pallet_prelude::*; +use frame_system::pallet_prelude::*; + +pub trait WeightInfo { + fn foo() -> Weight; +} + +#[frame_support::pallet(dev_mode)] +mod pallet { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type WeightInfo: WeightInfo; + } + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::call(impl ::WeightInfo)] + impl Pallet { + #[pallet::call_index(0)] + pub fn foo(_: OriginFor) -> DispatchResult { + Ok(()) + } + } +} + +fn main() { +} From 8f86155e08748fc56b5acc895b6139c293e83db1 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 17 Apr 2023 15:47:26 +0200 Subject: [PATCH 04/17] Rename to weight(prefix = ...)) Signed-off-by: Oliver Tale-Yazdi --- frame/alliance/src/lib.rs | 2 +- frame/assets/src/lib.rs | 2 +- frame/balances/src/lib.rs | 2 +- frame/examples/basic/src/lib.rs | 2 +- .../procedural/src/pallet/parse/mod.rs | 13 +++++++-- .../call_weight_inherited_invalid.stderr | 2 +- .../call_weight_inherited_invalid2.rs | 2 +- .../call_weight_inherited_invalid2.stderr | 8 ++--- .../call_weight_inherited_invalid3.rs | 29 +++++++++++++++++++ .../call_weight_inherited_invalid3.stderr | 5 ++++ .../pallet_ui/pass/inherited_call_weight.rs | 2 +- .../pallet_ui/pass/inherited_call_weight2.rs | 2 +- .../pallet_ui/pass/inherited_call_weight3.rs | 2 +- .../pass/inherited_call_weight_dev_mode.rs | 2 +- 14 files changed, 58 insertions(+), 17 deletions(-) create mode 100644 frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.rs create mode 100644 frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.stderr diff --git a/frame/alliance/src/lib.rs b/frame/alliance/src/lib.rs index 221ad9935f0b8..1d3c1fa0007cd 100644 --- a/frame/alliance/src/lib.rs +++ b/frame/alliance/src/lib.rs @@ -497,7 +497,7 @@ pub mod pallet { pub type UnscrupulousWebsites, I: 'static = ()> = StorageValue<_, BoundedVec, T::MaxUnscrupulousItems>, ValueQuery>; - #[pallet::call(impl >::WeightInfo)] + #[pallet::call(weight(prefix = >::WeightInfo))] impl, I: 'static> Pallet { /// Add a new proposal to be voted on. /// diff --git a/frame/assets/src/lib.rs b/frame/assets/src/lib.rs index 9edc96bf24996..dd3d885f1c1e0 100644 --- a/frame/assets/src/lib.rs +++ b/frame/assets/src/lib.rs @@ -568,7 +568,7 @@ pub mod pallet { CallbackFailed, } - #[pallet::call(impl >::WeightInfo)] + #[pallet::call(weight(prefix = >::WeightInfo))] impl, I: 'static> Pallet { /// Issue a new class of fungible assets from a public origin. /// diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index 5d9279d2c0a3a..2e6465f2d729c 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -519,7 +519,7 @@ pub mod pallet { } } - #[pallet::call(impl >::WeightInfo)] + #[pallet::call(weight(prefix = >::WeightInfo))] impl, I: 'static> Pallet { /// Transfer some liquid free balance to another account. /// diff --git a/frame/examples/basic/src/lib.rs b/frame/examples/basic/src/lib.rs index 53d62385c48c8..5c1083d07ffb2 100644 --- a/frame/examples/basic/src/lib.rs +++ b/frame/examples/basic/src/lib.rs @@ -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(impl ::WeightInfo)] + #[pallet::call(weight(prefix = ::WeightInfo))] impl Pallet { /// This is your public interface. Be extremely careful. /// This is just a simple example of how to interact with the pallet from the external diff --git a/frame/support/procedural/src/pallet/parse/mod.rs b/frame/support/procedural/src/pallet/parse/mod.rs index 261cc742795cb..04ad748de1c0c 100644 --- a/frame/support/procedural/src/pallet/parse/mod.rs +++ b/frame/support/procedural/src/pallet/parse/mod.rs @@ -402,6 +402,8 @@ impl GenericKind { mod keyword { syn::custom_keyword!(origin); syn::custom_keyword!(call); + syn::custom_keyword!(weight); + syn::custom_keyword!(prefix); syn::custom_keyword!(event); syn::custom_keyword!(config); syn::custom_keyword!(hooks); @@ -484,8 +486,12 @@ impl syn::parse::Parse for PalletAttr { let attr_content; syn::parenthesized!(attr_content in content); - attr_content.parse::()?; - let typename = attr_content.parse::()?; + attr_content.parse::()?; + let weight_content; + syn::parenthesized!(weight_content in attr_content); + weight_content.parse::()?; + weight_content.parse::()?; + let typename = weight_content.parse::()?; Ok(PalletAttr::RuntimeCall(Some(RuntimeCallWeightAttr { typename, span }), span)) } else if lookahead.peek(keyword::error) { @@ -516,7 +522,8 @@ impl syn::parse::Parse for PalletAttr { } } -/// The optional weight annotation on a `#[pallet::call]` like `#[pallet::call(impl $type)]` +/// The optional weight annotation on a `#[pallet::call]` like `#[pallet::call(weight_prefix +/// $type)]` #[derive(Clone)] pub struct RuntimeCallWeightAttr { pub typename: syn::Type, diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid.stderr b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid.stderr index 69f0db02d446f..bf5ba623b3fea 100644 --- a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid.stderr +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid.stderr @@ -1,4 +1,4 @@ -error: expected `impl` +error: expected `weight` --> tests/pallet_ui/call_weight_inherited_invalid.rs:19:17 | 19 | #[pallet::call(123)] diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.rs b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.rs index ab2e6824d6e0b..5ae6776e6e64a 100644 --- a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.rs +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.rs @@ -16,7 +16,7 @@ mod pallet { #[pallet::pallet] pub struct Pallet(core::marker::PhantomData); - #[pallet::call(impl ::WeightInfo 654)] + #[pallet::call(weight(prefix))] impl Pallet { #[pallet::call_index(0)] pub fn foo(_: OriginFor) -> DispatchResult { diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.stderr b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.stderr index 7d6e8b1113ab1..7282270d5394d 100644 --- a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.stderr +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.stderr @@ -1,5 +1,5 @@ -error: unexpected token - --> tests/pallet_ui/call_weight_inherited_invalid2.rs:19:48 +error: expected `=` + --> tests/pallet_ui/call_weight_inherited_invalid2.rs:19:30 | -19 | #[pallet::call(impl ::WeightInfo 654)] - | ^^^ +19 | #[pallet::call(weight(prefix))] + | ^ diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.rs b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.rs new file mode 100644 index 0000000000000..958dc8ccf4532 --- /dev/null +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.rs @@ -0,0 +1,29 @@ +use frame_support::pallet_prelude::*; + +pub trait WeightInfo { + fn foo() -> Weight; +} + +#[frame_support::pallet] +mod pallet { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type WeightInfo: crate::WeightInfo; + } + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::call(weight(prefix = 123))] + impl Pallet { + #[pallet::call_index(0)] + pub fn foo(_: OriginFor) -> DispatchResult { + Ok(()) + } + } +} + +fn main() { +} diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.stderr b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.stderr new file mode 100644 index 0000000000000..6a581dd15d26c --- /dev/null +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.stderr @@ -0,0 +1,5 @@ +error: expected one of: `for`, parentheses, `fn`, `unsafe`, `extern`, identifier, `::`, `<`, `dyn`, square brackets, `*`, `&`, `!`, `impl`, `_`, lifetime + --> tests/pallet_ui/call_weight_inherited_invalid3.rs:19:33 + | +19 | #[pallet::call(weight(prefix = 123))] + | ^^^ diff --git a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight.rs b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight.rs index 9159f83640fac..8393f135ee6ff 100644 --- a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight.rs +++ b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight.rs @@ -17,7 +17,7 @@ mod pallet { #[pallet::pallet] pub struct Pallet(core::marker::PhantomData); - #[pallet::call(impl ::WeightInfo)] + #[pallet::call(weight(prefix = ::WeightInfo))] impl Pallet { #[pallet::call_index(0)] pub fn foo(_: OriginFor) -> DispatchResult { diff --git a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight2.rs b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight2.rs index 0055578c49f1d..1481823608d55 100644 --- a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight2.rs +++ b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight2.rs @@ -23,7 +23,7 @@ mod pallet { pub struct Pallet(core::marker::PhantomData); // Crazy man just uses `()`, but it still works ;) - #[pallet::call(impl ())] + #[pallet::call(weight(prefix = ()))] impl Pallet { #[pallet::call_index(0)] pub fn foo(_: OriginFor) -> DispatchResult { diff --git a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight3.rs b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight3.rs index 0937c4c2ad534..f0c4e84581c72 100644 --- a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight3.rs +++ b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight3.rs @@ -25,7 +25,7 @@ mod pallet { #[pallet::pallet] pub struct Pallet(core::marker::PhantomData); - #[pallet::call(impl crate::Impl)] + #[pallet::call(weight(prefix = crate::Impl))] impl Pallet { #[pallet::call_index(0)] pub fn foo(_: OriginFor) -> DispatchResult { diff --git a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight_dev_mode.rs b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight_dev_mode.rs index 3b653689b6317..6a0e488698a94 100644 --- a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight_dev_mode.rs +++ b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight_dev_mode.rs @@ -17,7 +17,7 @@ mod pallet { #[pallet::pallet] pub struct Pallet(core::marker::PhantomData); - #[pallet::call(impl ::WeightInfo)] + #[pallet::call(weight(prefix = ::WeightInfo))] impl Pallet { #[pallet::call_index(0)] pub fn foo(_: OriginFor) -> DispatchResult { From 73b1bb43a451654017e7eec7cf2d50efcacc3e26 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 17 Apr 2023 20:42:10 +0200 Subject: [PATCH 05/17] Simplify to #[pallet::call(weight(T))] Signed-off-by: Oliver Tale-Yazdi --- frame/alliance/src/lib.rs | 2 +- frame/assets/src/lib.rs | 2 +- frame/balances/src/lib.rs | 2 +- frame/examples/basic/src/lib.rs | 2 +- .../procedural/src/pallet/parse/call.rs | 2 +- .../procedural/src/pallet/parse/mod.rs | 38 +++++++++++-------- .../pallet_ui/call_missing_weight.stderr | 2 +- .../call_weight_inherited_invalid2.stderr | 17 +++++++-- .../call_weight_inherited_invalid3.rs | 2 +- .../call_weight_inherited_invalid3.stderr | 6 +-- .../call_weight_inherited_invalid4.rs | 26 +++++++++++++ .../call_weight_inherited_invalid4.stderr | 29 ++++++++++++++ .../pallet_ui/dev_mode_without_arg.stderr | 2 +- .../pallet_ui/pass/inherited_call_weight.rs | 2 +- .../pallet_ui/pass/inherited_call_weight2.rs | 2 +- .../pallet_ui/pass/inherited_call_weight3.rs | 10 ++--- .../pass/inherited_call_weight_dev_mode.rs | 2 +- 17 files changed, 108 insertions(+), 40 deletions(-) create mode 100644 frame/support/test/tests/pallet_ui/call_weight_inherited_invalid4.rs create mode 100644 frame/support/test/tests/pallet_ui/call_weight_inherited_invalid4.stderr diff --git a/frame/alliance/src/lib.rs b/frame/alliance/src/lib.rs index 1d3c1fa0007cd..86a64caaf8e75 100644 --- a/frame/alliance/src/lib.rs +++ b/frame/alliance/src/lib.rs @@ -497,7 +497,7 @@ pub mod pallet { pub type UnscrupulousWebsites, I: 'static = ()> = StorageValue<_, BoundedVec, T::MaxUnscrupulousItems>, ValueQuery>; - #[pallet::call(weight(prefix = >::WeightInfo))] + #[pallet::call(weight(>::WeightInfo))] impl, I: 'static> Pallet { /// Add a new proposal to be voted on. /// diff --git a/frame/assets/src/lib.rs b/frame/assets/src/lib.rs index dd3d885f1c1e0..d32b407e67f6e 100644 --- a/frame/assets/src/lib.rs +++ b/frame/assets/src/lib.rs @@ -568,7 +568,7 @@ pub mod pallet { CallbackFailed, } - #[pallet::call(weight(prefix = >::WeightInfo))] + #[pallet::call(weight(>::WeightInfo))] impl, I: 'static> Pallet { /// Issue a new class of fungible assets from a public origin. /// diff --git a/frame/balances/src/lib.rs b/frame/balances/src/lib.rs index 2e6465f2d729c..7cb984aa1346f 100644 --- a/frame/balances/src/lib.rs +++ b/frame/balances/src/lib.rs @@ -519,7 +519,7 @@ pub mod pallet { } } - #[pallet::call(weight(prefix = >::WeightInfo))] + #[pallet::call(weight(>::WeightInfo))] impl, I: 'static> Pallet { /// Transfer some liquid free balance to another account. /// diff --git a/frame/examples/basic/src/lib.rs b/frame/examples/basic/src/lib.rs index 5c1083d07ffb2..bbeaac19f809c 100644 --- a/frame/examples/basic/src/lib.rs +++ b/frame/examples/basic/src/lib.rs @@ -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(weight(prefix = ::WeightInfo))] + #[pallet::call(weight(::WeightInfo))] impl Pallet { /// This is your public interface. Be extremely careful. /// This is just a simple example of how to interact with the pallet from the external diff --git a/frame/support/procedural/src/pallet/parse/call.rs b/frame/support/procedural/src/pallet/parse/call.rs index 12fe98fe4419c..fecbbec14053e 100644 --- a/frame/support/procedural/src/pallet/parse/call.rs +++ b/frame/support/procedural/src/pallet/parse/call.rs @@ -248,7 +248,7 @@ impl CallDef { 0 if dev_mode => CallWeightDef::DevModeDefault, 0 => return Err(syn::Error::new( method.sig.span(), - "A pallet::call requires either a concrete `#[pallet::weight($expr)]` or an inherited weight from the `#[pallet:call(trait ...)]` attribute, but none were given.", + "A pallet::call requires either a concrete `#[pallet::weight($expr)]` or an inherited weight from the `#[pallet:call(weight($type))]` attribute, but none were given.", )), 1 => match weight_attrs.pop().unwrap() { FunctionAttr::Weight(w) => CallWeightDef::Immediate(w), diff --git a/frame/support/procedural/src/pallet/parse/mod.rs b/frame/support/procedural/src/pallet/parse/mod.rs index 04ad748de1c0c..144f3c11f4266 100644 --- a/frame/support/procedural/src/pallet/parse/mod.rs +++ b/frame/support/procedural/src/pallet/parse/mod.rs @@ -427,6 +427,7 @@ enum PalletAttr { Config(proc_macro2::Span), Pallet(proc_macro2::Span), Hooks(proc_macro2::Span), + /// A `#[pallet::call]` with or without `#[pallet::call(weight($type))]` attribute. RuntimeCall(Option, proc_macro2::Span), Error(proc_macro2::Span), RuntimeEvent(proc_macro2::Span), @@ -480,20 +481,11 @@ impl syn::parse::Parse for PalletAttr { Ok(PalletAttr::Hooks(content.parse::()?.span())) } else if lookahead.peek(keyword::call) { let span = content.parse::().expect("peeked").span(); - if content.is_empty() { - return Ok(PalletAttr::RuntimeCall(None, span)) - } - - let attr_content; - syn::parenthesized!(attr_content in content); - attr_content.parse::()?; - let weight_content; - syn::parenthesized!(weight_content in attr_content); - weight_content.parse::()?; - weight_content.parse::()?; - let typename = weight_content.parse::()?; - - Ok(PalletAttr::RuntimeCall(Some(RuntimeCallWeightAttr { typename, span }), span)) + let attr = match content.is_empty() { + true => None, + false => Some(RuntimeCallWeightAttr::parse(&content)?), + }; + Ok(PalletAttr::RuntimeCall(attr, span)) } else if lookahead.peek(keyword::error) { Ok(PalletAttr::Error(content.parse::()?.span())) } else if lookahead.peek(keyword::event) { @@ -522,10 +514,24 @@ impl syn::parse::Parse for PalletAttr { } } -/// The optional weight annotation on a `#[pallet::call]` like `#[pallet::call(weight_prefix -/// $type)]` +/// The optional weight annotation on a `#[pallet::call]` like `#[pallet::call(weight($type))]`. #[derive(Clone)] pub struct RuntimeCallWeightAttr { pub typename: syn::Type, pub span: proc_macro2::Span, } + +impl syn::parse::Parse for RuntimeCallWeightAttr { + // Parses `(weight($type))`. + fn parse(input: syn::parse::ParseStream) -> syn::Result { + let content; + syn::parenthesized!(content in input); + content.parse::()?; + + let weight_content; + syn::parenthesized!(weight_content in content); + let typename = weight_content.parse::()?; + + Ok(RuntimeCallWeightAttr { typename, span: input.span() }) + } +} diff --git a/frame/support/test/tests/pallet_ui/call_missing_weight.stderr b/frame/support/test/tests/pallet_ui/call_missing_weight.stderr index 46d385a11eb7c..2dd6c49df568b 100644 --- a/frame/support/test/tests/pallet_ui/call_missing_weight.stderr +++ b/frame/support/test/tests/pallet_ui/call_missing_weight.stderr @@ -1,4 +1,4 @@ -error: A pallet::call requires either a concrete weight via `#[pallet::weight]` or an inherited one from the `#[pallet:call(trait ...)]` attribute but none were given. +error: A pallet::call requires either a concrete `#[pallet::weight($expr)]` or an inherited weight from the `#[pallet:call(weight($type))]` attribute, but none were given. --> tests/pallet_ui/call_missing_weight.rs:17:7 | 17 | pub fn foo(origin: OriginFor) -> DispatchResultWithPostInfo {} diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.stderr b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.stderr index 7282270d5394d..fa3b4c14b98a7 100644 --- a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.stderr +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.stderr @@ -1,5 +1,16 @@ -error: expected `=` - --> tests/pallet_ui/call_weight_inherited_invalid2.rs:19:30 +error[E0412]: cannot find type `OriginFor` in this scope + --> tests/pallet_ui/call_weight_inherited_invalid2.rs:22:17 + | +22 | pub fn foo(_: OriginFor) -> DispatchResult { + | ^^^^^^^^^ not found in this scope + | +help: consider importing this type alias + | +9 | use frame_system::pallet_prelude::OriginFor; + | + +error[E0412]: cannot find type `prefix` in this scope + --> tests/pallet_ui/call_weight_inherited_invalid2.rs:19:24 | 19 | #[pallet::call(weight(prefix))] - | ^ + | ^^^^^^ not found in this scope diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.rs b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.rs index 958dc8ccf4532..040ee104550dd 100644 --- a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.rs +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.rs @@ -16,7 +16,7 @@ mod pallet { #[pallet::pallet] pub struct Pallet(core::marker::PhantomData); - #[pallet::call(weight(prefix = 123))] + #[pallet::call(weight(123))] impl Pallet { #[pallet::call_index(0)] pub fn foo(_: OriginFor) -> DispatchResult { diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.stderr b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.stderr index 6a581dd15d26c..c70b1c2cb8461 100644 --- a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.stderr +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.stderr @@ -1,5 +1,5 @@ error: expected one of: `for`, parentheses, `fn`, `unsafe`, `extern`, identifier, `::`, `<`, `dyn`, square brackets, `*`, `&`, `!`, `impl`, `_`, lifetime - --> tests/pallet_ui/call_weight_inherited_invalid3.rs:19:33 + --> tests/pallet_ui/call_weight_inherited_invalid3.rs:19:24 | -19 | #[pallet::call(weight(prefix = 123))] - | ^^^ +19 | #[pallet::call(weight(123))] + | ^^^ diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid4.rs b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid4.rs new file mode 100644 index 0000000000000..c707f7bd3bc8f --- /dev/null +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid4.rs @@ -0,0 +1,26 @@ +pub trait WeightInfo { +} + +#[frame_support::pallet] +mod pallet { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type WeightInfo: crate::WeightInfo; + } + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::call(weight(::WeightInfo))] + impl Pallet { + #[pallet::call_index(0)] + pub fn foo(_: OriginFor) -> DispatchResult { + Ok(()) + } + } +} + +fn main() { +} diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid4.stderr b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid4.stderr new file mode 100644 index 0000000000000..ed8fb2c8076d6 --- /dev/null +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid4.stderr @@ -0,0 +1,29 @@ +error[E0412]: cannot find type `OriginFor` in this scope + --> tests/pallet_ui/call_weight_inherited_invalid4.rs:19:17 + | +19 | pub fn foo(_: OriginFor) -> DispatchResult { + | ^^^^^^^^^ not found in this scope + | +help: consider importing this type alias + | +6 | use frame_system::pallet_prelude::OriginFor; + | + +error[E0412]: cannot find type `DispatchResult` in this scope + --> tests/pallet_ui/call_weight_inherited_invalid4.rs:19:34 + | +19 | pub fn foo(_: OriginFor) -> DispatchResult { + | ^^^^^^^^^^^^^^ not found in this scope + | +help: consider importing one of these items + | +6 | use frame_support::pallet_prelude::DispatchResult; + | +6 | use sp_runtime::DispatchResult; + | + +error[E0599]: no function or associated item named `foo` found for associated type `::WeightInfo` in the current scope + --> tests/pallet_ui/call_weight_inherited_invalid4.rs:19:10 + | +19 | pub fn foo(_: OriginFor) -> DispatchResult { + | ^^^ function or associated item not found in `::WeightInfo` diff --git a/frame/support/test/tests/pallet_ui/dev_mode_without_arg.stderr b/frame/support/test/tests/pallet_ui/dev_mode_without_arg.stderr index 289017a75e55e..800def65f6bde 100644 --- a/frame/support/test/tests/pallet_ui/dev_mode_without_arg.stderr +++ b/frame/support/test/tests/pallet_ui/dev_mode_without_arg.stderr @@ -1,4 +1,4 @@ -error: A pallet::call requires either a concrete weight via `#[pallet::weight]` or an inherited one from the `#[pallet:call(trait ...)]` attribute but none were given. +error: A pallet::call requires either a concrete `#[pallet::weight($expr)]` or an inherited weight from the `#[pallet:call(weight($type))]` attribute, but none were given. --> tests/pallet_ui/dev_mode_without_arg.rs:22:7 | 22 | pub fn my_call(_origin: OriginFor) -> DispatchResult { diff --git a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight.rs b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight.rs index 8393f135ee6ff..474e820b30401 100644 --- a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight.rs +++ b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight.rs @@ -17,7 +17,7 @@ mod pallet { #[pallet::pallet] pub struct Pallet(core::marker::PhantomData); - #[pallet::call(weight(prefix = ::WeightInfo))] + #[pallet::call(weight(::WeightInfo))] impl Pallet { #[pallet::call_index(0)] pub fn foo(_: OriginFor) -> DispatchResult { diff --git a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight2.rs b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight2.rs index 1481823608d55..318ad30b0e89d 100644 --- a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight2.rs +++ b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight2.rs @@ -23,7 +23,7 @@ mod pallet { pub struct Pallet(core::marker::PhantomData); // Crazy man just uses `()`, but it still works ;) - #[pallet::call(weight(prefix = ()))] + #[pallet::call(weight(()))] impl Pallet { #[pallet::call_index(0)] pub fn foo(_: OriginFor) -> DispatchResult { diff --git a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight3.rs b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight3.rs index f0c4e84581c72..8385aac30f69c 100644 --- a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight3.rs +++ b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight3.rs @@ -1,14 +1,10 @@ use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; -pub trait WeightInfo { - fn foo() -> Weight; -} - -// If, for whatever reason, you dont to not use a `WeightInfo` trait; it will still work. +// If, for whatever reason, you dont to not use a `WeightInfo` trait - it will still work. struct Impl; -impl WeightInfo for Impl { +impl Impl { fn foo() -> Weight { Weight::zero() } @@ -25,7 +21,7 @@ mod pallet { #[pallet::pallet] pub struct Pallet(core::marker::PhantomData); - #[pallet::call(weight(prefix = crate::Impl))] + #[pallet::call(weight(crate::Impl))] impl Pallet { #[pallet::call_index(0)] pub fn foo(_: OriginFor) -> DispatchResult { diff --git a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight_dev_mode.rs b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight_dev_mode.rs index 6a0e488698a94..04ce49ee71e99 100644 --- a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight_dev_mode.rs +++ b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight_dev_mode.rs @@ -17,7 +17,7 @@ mod pallet { #[pallet::pallet] pub struct Pallet(core::marker::PhantomData); - #[pallet::call(weight(prefix = ::WeightInfo))] + #[pallet::call(weight(::WeightInfo))] impl Pallet { #[pallet::call_index(0)] pub fn foo(_: OriginFor) -> DispatchResult { From 03736446ec3430932f17d0a6df18e05350bbcfc9 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 17 Apr 2023 21:08:55 +0200 Subject: [PATCH 06/17] Add stray token error Signed-off-by: Oliver Tale-Yazdi --- .../procedural/src/pallet/parse/mod.rs | 24 ++++++++-- .../call_weight_inherited_invalid.rs | 23 +++++++++- .../call_weight_inherited_invalid.stderr | 10 ++++- .../call_weight_inherited_invalid2.rs | 26 ++++++++++- .../call_weight_inherited_invalid2.stderr | 19 +++----- .../call_weight_inherited_invalid3.rs | 26 ++++++++++- .../call_weight_inherited_invalid3.stderr | 18 +++++++- .../call_weight_inherited_invalid4.rs | 28 +++++++++++- .../call_weight_inherited_invalid4.stderr | 30 +++---------- .../call_weight_inherited_invalid5.rs | 44 +++++++++++++++++++ .../call_weight_inherited_invalid5.stderr | 11 +++++ .../pallet_ui/pass/inherited_call_weight.rs | 23 +++++++++- .../pallet_ui/pass/inherited_call_weight2.rs | 23 +++++++++- .../pallet_ui/pass/inherited_call_weight3.rs | 22 +++++++++- 14 files changed, 276 insertions(+), 51 deletions(-) create mode 100644 frame/support/test/tests/pallet_ui/call_weight_inherited_invalid5.rs create mode 100644 frame/support/test/tests/pallet_ui/call_weight_inherited_invalid5.stderr diff --git a/frame/support/procedural/src/pallet/parse/mod.rs b/frame/support/procedural/src/pallet/parse/mod.rs index 144f3c11f4266..3b7dce993aca3 100644 --- a/frame/support/procedural/src/pallet/parse/mod.rs +++ b/frame/support/procedural/src/pallet/parse/mod.rs @@ -528,10 +528,26 @@ impl syn::parse::Parse for RuntimeCallWeightAttr { syn::parenthesized!(content in input); content.parse::()?; - let weight_content; - syn::parenthesized!(weight_content in content); - let typename = weight_content.parse::()?; + let lookahead = content.lookahead1(); + + let typename = if lookahead.peek(syn::token::Paren) { + let weight_content; + syn::parenthesized!(weight_content in content); + weight_content.parse::()? + } else if lookahead.peek(syn::Token![=]) { + content.parse::().expect("peeked"); + let typename = content.parse::()?; + if !content.is_empty() { + return Err(content.error("unexpected stray tokens")) + } + typename + } else { + return Err(lookahead.error()) + }; - Ok(RuntimeCallWeightAttr { typename, span: input.span() }) + Ok(Self { + typename, + span: content.span(), + }) } } diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid.rs b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid.rs index 9781f8077b75e..ff235e986099f 100644 --- a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid.rs +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid.rs @@ -16,7 +16,28 @@ mod pallet { #[pallet::pallet] pub struct Pallet(core::marker::PhantomData); - #[pallet::call(123)] + #[pallet::call(invalid)] + impl Pallet { + #[pallet::call_index(0)] + pub fn foo(_: OriginFor) -> DispatchResult { + Ok(()) + } + } +} + +#[frame_support::pallet] +mod assign { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type WeightInfo: crate::WeightInfo; + } + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::call = invalid] impl Pallet { #[pallet::call_index(0)] pub fn foo(_: OriginFor) -> DispatchResult { diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid.stderr b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid.stderr index bf5ba623b3fea..7eed646e7b190 100644 --- a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid.stderr +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid.stderr @@ -1,5 +1,11 @@ error: expected `weight` --> tests/pallet_ui/call_weight_inherited_invalid.rs:19:17 | -19 | #[pallet::call(123)] - | ^^^ +19 | #[pallet::call(invalid)] + | ^^^^^^^ + +error: expected parentheses + --> tests/pallet_ui/call_weight_inherited_invalid.rs:40:17 + | +40 | #[pallet::call = invalid] + | ^ diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.rs b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.rs index 5ae6776e6e64a..76ccf5db22019 100644 --- a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.rs +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.rs @@ -1,11 +1,14 @@ +// Weight is an ident instead of a type. + use frame_support::pallet_prelude::*; +use frame_system::pallet_prelude::*; pub trait WeightInfo { fn foo() -> Weight; } #[frame_support::pallet] -mod pallet { +mod parentheses { use super::*; #[pallet::config] @@ -25,5 +28,26 @@ mod pallet { } } +#[frame_support::pallet] +mod assign { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type WeightInfo: crate::WeightInfo; + } + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::call(weight = prefix)] + impl Pallet { + #[pallet::call_index(0)] + pub fn foo(_: OriginFor) -> DispatchResult { + Ok(()) + } + } +} + fn main() { } diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.stderr b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.stderr index fa3b4c14b98a7..29f3b6bfd2b0d 100644 --- a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.stderr +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid2.stderr @@ -1,16 +1,11 @@ -error[E0412]: cannot find type `OriginFor` in this scope - --> tests/pallet_ui/call_weight_inherited_invalid2.rs:22:17 - | -22 | pub fn foo(_: OriginFor) -> DispatchResult { - | ^^^^^^^^^ not found in this scope - | -help: consider importing this type alias - | -9 | use frame_system::pallet_prelude::OriginFor; +error[E0412]: cannot find type `prefix` in this scope + --> tests/pallet_ui/call_weight_inherited_invalid2.rs:22:24 | +22 | #[pallet::call(weight(prefix))] + | ^^^^^^ not found in this scope error[E0412]: cannot find type `prefix` in this scope - --> tests/pallet_ui/call_weight_inherited_invalid2.rs:19:24 + --> tests/pallet_ui/call_weight_inherited_invalid2.rs:43:26 | -19 | #[pallet::call(weight(prefix))] - | ^^^^^^ not found in this scope +43 | #[pallet::call(weight = prefix)] + | ^^^^^^ not found in this scope diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.rs b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.rs index 040ee104550dd..b31bc0ae234b2 100644 --- a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.rs +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.rs @@ -1,11 +1,14 @@ +// Call weight is an LitInt instead of a type. + use frame_support::pallet_prelude::*; +use frame_system::pallet_prelude::*; pub trait WeightInfo { fn foo() -> Weight; } #[frame_support::pallet] -mod pallet { +mod parentheses { use super::*; #[pallet::config] @@ -25,5 +28,26 @@ mod pallet { } } +#[frame_support::pallet] +mod assign { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type WeightInfo: crate::WeightInfo; + } + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::call(weight = 123)] + impl Pallet { + #[pallet::call_index(0)] + pub fn foo(_: OriginFor) -> DispatchResult { + Ok(()) + } + } +} + fn main() { } diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.stderr b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.stderr index c70b1c2cb8461..fab7acb90deaf 100644 --- a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.stderr +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid3.stderr @@ -1,5 +1,19 @@ error: expected one of: `for`, parentheses, `fn`, `unsafe`, `extern`, identifier, `::`, `<`, `dyn`, square brackets, `*`, `&`, `!`, `impl`, `_`, lifetime - --> tests/pallet_ui/call_weight_inherited_invalid3.rs:19:24 + --> tests/pallet_ui/call_weight_inherited_invalid3.rs:22:24 | -19 | #[pallet::call(weight(123))] +22 | #[pallet::call(weight(123))] | ^^^ + +error: expected one of: `for`, parentheses, `fn`, `unsafe`, `extern`, identifier, `::`, `<`, `dyn`, square brackets, `*`, `&`, `!`, `impl`, `_`, lifetime + --> tests/pallet_ui/call_weight_inherited_invalid3.rs:43:26 + | +43 | #[pallet::call(weight = 123)] + | ^^^ + +error: unused import: `frame_system::pallet_prelude::*` + --> tests/pallet_ui/call_weight_inherited_invalid3.rs:4:5 + | +4 | use frame_system::pallet_prelude::*; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D unused-imports` implied by `-D warnings` diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid4.rs b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid4.rs index c707f7bd3bc8f..39c0929d603ad 100644 --- a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid4.rs +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid4.rs @@ -1,8 +1,13 @@ +// Function does not exist in the trait. + +use frame_support::pallet_prelude::*; +use frame_system::pallet_prelude::*; + pub trait WeightInfo { } #[frame_support::pallet] -mod pallet { +mod parentheses { use super::*; #[pallet::config] @@ -22,5 +27,26 @@ mod pallet { } } +#[frame_support::pallet] +mod assign { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type WeightInfo: crate::WeightInfo; + } + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::call(weight = ::WeightInfo)] + impl Pallet { + #[pallet::call_index(0)] + pub fn foo(_: OriginFor) -> DispatchResult { + Ok(()) + } + } +} + fn main() { } diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid4.stderr b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid4.stderr index ed8fb2c8076d6..46872fc7c3691 100644 --- a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid4.stderr +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid4.stderr @@ -1,29 +1,11 @@ -error[E0412]: cannot find type `OriginFor` in this scope - --> tests/pallet_ui/call_weight_inherited_invalid4.rs:19:17 - | -19 | pub fn foo(_: OriginFor) -> DispatchResult { - | ^^^^^^^^^ not found in this scope - | -help: consider importing this type alias - | -6 | use frame_system::pallet_prelude::OriginFor; - | - -error[E0412]: cannot find type `DispatchResult` in this scope - --> tests/pallet_ui/call_weight_inherited_invalid4.rs:19:34 - | -19 | pub fn foo(_: OriginFor) -> DispatchResult { - | ^^^^^^^^^^^^^^ not found in this scope - | -help: consider importing one of these items - | -6 | use frame_support::pallet_prelude::DispatchResult; - | -6 | use sp_runtime::DispatchResult; +error[E0599]: no function or associated item named `foo` found for associated type `::WeightInfo` in the current scope + --> tests/pallet_ui/call_weight_inherited_invalid4.rs:24:10 | +24 | pub fn foo(_: OriginFor) -> DispatchResult { + | ^^^ function or associated item not found in `::WeightInfo` error[E0599]: no function or associated item named `foo` found for associated type `::WeightInfo` in the current scope - --> tests/pallet_ui/call_weight_inherited_invalid4.rs:19:10 + --> tests/pallet_ui/call_weight_inherited_invalid4.rs:45:10 | -19 | pub fn foo(_: OriginFor) -> DispatchResult { +45 | pub fn foo(_: OriginFor) -> DispatchResult { | ^^^ function or associated item not found in `::WeightInfo` diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid5.rs b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid5.rs new file mode 100644 index 0000000000000..a5b2f5c7f6aa6 --- /dev/null +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid5.rs @@ -0,0 +1,44 @@ +// Stray tokens after good input. + +#[frame_support::pallet] +mod parentheses { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + } + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::call(weight(::WeightInfo straycat))] + impl Pallet { + #[pallet::call_index(0)] + pub fn foo(_: OriginFor) -> DispatchResult { + Ok(()) + } + } +} + +#[frame_support::pallet] +mod assign { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + } + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::call(weight = ::WeightInfo straycat)] + impl Pallet { + #[pallet::call_index(0)] + pub fn foo(_: OriginFor) -> DispatchResult { + Ok(()) + } + } +} + +fn main() { +} diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid5.stderr b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid5.stderr new file mode 100644 index 0000000000000..1c6b8c5940999 --- /dev/null +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid5.stderr @@ -0,0 +1,11 @@ +error: unexpected token + --> tests/pallet_ui/call_weight_inherited_invalid5.rs:14:50 + | +14 | #[pallet::call(weight(::WeightInfo straycat))] + | ^^^^^^^^ + +error: unexpected stray tokens + --> tests/pallet_ui/call_weight_inherited_invalid5.rs:34:52 + | +34 | #[pallet::call(weight = ::WeightInfo straycat)] + | ^^^^^^^^ diff --git a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight.rs b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight.rs index 474e820b30401..355a1c978df06 100644 --- a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight.rs +++ b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight.rs @@ -6,7 +6,7 @@ pub trait WeightInfo { } #[frame_support::pallet] -mod pallet { +mod parentheses { use super::*; #[pallet::config] @@ -26,5 +26,26 @@ mod pallet { } } +#[frame_support::pallet] +mod assign { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type WeightInfo: crate::WeightInfo; + } + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::call(weight = ::WeightInfo)] + impl Pallet { + #[pallet::call_index(0)] + pub fn foo(_: OriginFor) -> DispatchResult { + Ok(()) + } + } +} + fn main() { } diff --git a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight2.rs b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight2.rs index 318ad30b0e89d..ae70c295d8db2 100644 --- a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight2.rs +++ b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight2.rs @@ -12,7 +12,7 @@ impl WeightInfo for () { } #[frame_support::pallet] -mod pallet { +mod parentheses { use super::*; #[pallet::config] @@ -32,5 +32,26 @@ mod pallet { } } +#[frame_support::pallet] +mod assign { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + } + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + // Crazy man just uses `()`, but it still works ;) + #[pallet::call(weight = ())] + impl Pallet { + #[pallet::call_index(0)] + pub fn foo(_: OriginFor) -> DispatchResult { + Ok(()) + } + } +} + fn main() { } diff --git a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight3.rs b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight3.rs index 8385aac30f69c..567fd2e5fa032 100644 --- a/frame/support/test/tests/pallet_ui/pass/inherited_call_weight3.rs +++ b/frame/support/test/tests/pallet_ui/pass/inherited_call_weight3.rs @@ -11,7 +11,7 @@ impl Impl { } #[frame_support::pallet] -mod pallet { +mod parentheses { use super::*; #[pallet::config] @@ -30,5 +30,25 @@ mod pallet { } } +#[frame_support::pallet] +mod assign { + use super::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + } + + #[pallet::pallet] + pub struct Pallet(core::marker::PhantomData); + + #[pallet::call(weight = crate::Impl)] + impl Pallet { + #[pallet::call_index(0)] + pub fn foo(_: OriginFor) -> DispatchResult { + Ok(()) + } + } +} + fn main() { } From fe3d657fbe016824e56e4724d601fae468ccfd9b Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 17 Apr 2023 21:30:52 +0200 Subject: [PATCH 07/17] Cleanup Signed-off-by: Oliver Tale-Yazdi --- .../procedural/src/pallet/parse/mod.rs | 22 ++++++------------- .../call_weight_inherited_invalid5.stderr | 2 +- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/frame/support/procedural/src/pallet/parse/mod.rs b/frame/support/procedural/src/pallet/parse/mod.rs index 3b7dce993aca3..7a20558a9b077 100644 --- a/frame/support/procedural/src/pallet/parse/mod.rs +++ b/frame/support/procedural/src/pallet/parse/mod.rs @@ -522,32 +522,24 @@ pub struct RuntimeCallWeightAttr { } impl syn::parse::Parse for RuntimeCallWeightAttr { - // Parses `(weight($type))`. + // Parses `(weight($type))` or `(weight = $type)`. fn parse(input: syn::parse::ParseStream) -> syn::Result { let content; syn::parenthesized!(content in input); content.parse::()?; - let lookahead = content.lookahead1(); - let typename = if lookahead.peek(syn::token::Paren) { - let weight_content; - syn::parenthesized!(weight_content in content); - weight_content.parse::()? + let buffer = if lookahead.peek(syn::token::Paren) { + let inner; + syn::parenthesized!(inner in content); + inner } else if lookahead.peek(syn::Token![=]) { content.parse::().expect("peeked"); - let typename = content.parse::()?; - if !content.is_empty() { - return Err(content.error("unexpected stray tokens")) - } - typename + content } else { return Err(lookahead.error()) }; - Ok(Self { - typename, - span: content.span(), - }) + Ok(Self { typename: buffer.parse()?, span: input.span() }) } } diff --git a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid5.stderr b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid5.stderr index 1c6b8c5940999..c0e9ef2d9e9d8 100644 --- a/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid5.stderr +++ b/frame/support/test/tests/pallet_ui/call_weight_inherited_invalid5.stderr @@ -4,7 +4,7 @@ error: unexpected token 14 | #[pallet::call(weight(::WeightInfo straycat))] | ^^^^^^^^ -error: unexpected stray tokens +error: unexpected token --> tests/pallet_ui/call_weight_inherited_invalid5.rs:34:52 | 34 | #[pallet::call(weight = ::WeightInfo straycat)] From 331d4b42d72de1dacaed714d69166fa1bc9c92dd Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Tue, 18 Apr 2023 14:09:45 +0200 Subject: [PATCH 08/17] 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 --- bin/node-template/pallets/template/src/lib.rs | 4 +-- frame/bags-list/src/lib.rs | 3 +- frame/contracts/src/lib.rs | 4 +-- frame/conviction-voting/src/lib.rs | 5 +-- frame/democracy/src/lib.rs | 12 +------ .../election-provider-multi-phase/src/lib.rs | 3 +- frame/elections-phragmen/src/lib.rs | 3 +- frame/glutton/src/lib.rs | 4 +-- frame/grandpa/src/lib.rs | 3 +- frame/indices/src/lib.rs | 7 +--- frame/lottery/src/lib.rs | 4 +-- frame/message-queue/src/lib.rs | 3 +- frame/nfts/src/lib.rs | 35 +------------------ frame/nis/src/lib.rs | 7 +--- frame/node-authorization/src/lib.rs | 7 +--- frame/nomination-pools/src/lib.rs | 14 +------- frame/preimage/src/lib.rs | 5 +-- frame/ranked-collective/src/lib.rs | 4 +-- frame/recovery/src/lib.rs | 5 +-- frame/referenda/src/lib.rs | 7 +--- frame/session/src/lib.rs | 4 +-- frame/staking/src/pallet/mod.rs | 15 +------- frame/transaction-storage/src/lib.rs | 3 +- frame/treasury/src/lib.rs | 4 +-- frame/uniques/src/lib.rs | 25 +------------ frame/whitelist/src/lib.rs | 4 +-- 26 files changed, 26 insertions(+), 168 deletions(-) diff --git a/bin/node-template/pallets/template/src/lib.rs b/bin/node-template/pallets/template/src/lib.rs index 9550d3d546cca..1c40356f6f539 100644 --- a/bin/node-template/pallets/template/src/lib.rs +++ b/bin/node-template/pallets/template/src/lib.rs @@ -64,12 +64,11 @@ pub mod pallet { // Dispatchable functions allows users to interact with the pallet and invoke state changes. // These functions materialize as "extrinsics", which are often compared to transactions. // Dispatchable functions must be annotated with a weight and must return a DispatchResult. - #[pallet::call] + #[pallet::call(weight = ::WeightInfo)] impl Pallet { /// An example dispatchable that takes a singles value as a parameter, writes the value to /// storage and emits an event. This function must be dispatched by a signed extrinsic. #[pallet::call_index(0)] - #[pallet::weight(T::WeightInfo::do_something())] pub fn do_something(origin: OriginFor, something: u32) -> DispatchResult { // Check that the extrinsic was signed and get the signer. // This function will return an error if the extrinsic is not signed. @@ -87,7 +86,6 @@ pub mod pallet { /// An example dispatchable that may throw a custom error. #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::cause_error())] pub fn cause_error(origin: OriginFor) -> DispatchResult { let _who = ensure_signed(origin)?; diff --git a/frame/bags-list/src/lib.rs b/frame/bags-list/src/lib.rs index 87eb2d1b341aa..dd6aa5d39c0c7 100644 --- a/frame/bags-list/src/lib.rs +++ b/frame/bags-list/src/lib.rs @@ -211,7 +211,7 @@ pub mod pallet { } } - #[pallet::call] + #[pallet::call(weight = >::WeightInfo)] impl, I: 'static> Pallet { /// Declare that some `dislocated` account has, through rewards or penalties, sufficiently /// changed its score that it should properly fall into a different bag than its current @@ -243,7 +243,6 @@ pub mod pallet { /// - both nodes are within the same bag, /// - and `origin` has a greater `Score` than `lighter`. #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::put_in_front_of())] pub fn put_in_front_of( origin: OriginFor, lighter: AccountIdLookupOf, diff --git a/frame/contracts/src/lib.rs b/frame/contracts/src/lib.rs index 26b16b3291a2f..640bf3d63b477 100644 --- a/frame/contracts/src/lib.rs +++ b/frame/contracts/src/lib.rs @@ -374,7 +374,7 @@ pub mod pallet { } } - #[pallet::call] + #[pallet::call(weight = ::WeightInfo)] impl Pallet where as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, @@ -497,7 +497,6 @@ pub mod pallet { /// A code can only be removed by its original uploader (its owner) and only if it is /// not used by any contract. #[pallet::call_index(4)] - #[pallet::weight(T::WeightInfo::remove_code())] pub fn remove_code( origin: OriginFor, code_hash: CodeHash, @@ -519,7 +518,6 @@ pub mod pallet { /// that the contract address is no longer derived from its code hash after calling /// this dispatchable. #[pallet::call_index(5)] - #[pallet::weight(T::WeightInfo::set_code())] pub fn set_code( origin: OriginFor, dest: AccountIdLookupOf, diff --git a/frame/conviction-voting/src/lib.rs b/frame/conviction-voting/src/lib.rs index 072e57035484d..2e902dd4caa89 100644 --- a/frame/conviction-voting/src/lib.rs +++ b/frame/conviction-voting/src/lib.rs @@ -196,7 +196,7 @@ pub mod pallet { BadClass, } - #[pallet::call] + #[pallet::call(weight = >::WeightInfo)] impl, I: 'static> Pallet { /// Vote in a poll. If `vote.is_aye()`, the vote is to enact the proposal; /// otherwise it is a vote to keep the status quo. @@ -296,7 +296,6 @@ pub mod pallet { /// /// Weight: `O(R)` with R number of vote of target. #[pallet::call_index(3)] - #[pallet::weight(T::WeightInfo::unlock())] pub fn unlock( origin: OriginFor, class: ClassOf, @@ -338,7 +337,6 @@ pub mod pallet { /// Weight: `O(R + log R)` where R is the number of polls that `target` has voted on. /// Weight is calculated for the maximum number of vote. #[pallet::call_index(4)] - #[pallet::weight(T::WeightInfo::remove_vote())] pub fn remove_vote( origin: OriginFor, class: Option>, @@ -365,7 +363,6 @@ pub mod pallet { /// Weight: `O(R + log R)` where R is the number of polls that `target` has voted on. /// Weight is calculated for the maximum number of vote. #[pallet::call_index(5)] - #[pallet::weight(T::WeightInfo::remove_other_vote())] pub fn remove_other_vote( origin: OriginFor, target: AccountIdLookupOf, diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index a3d7f103a98f3..954bb14033100 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -576,7 +576,7 @@ pub mod pallet { } } - #[pallet::call] + #[pallet::call(weight = ::WeightInfo)] impl Pallet { /// Propose a sensitive action to be taken. /// @@ -588,7 +588,6 @@ pub mod pallet { /// /// Emits `Proposed`. #[pallet::call_index(0)] - #[pallet::weight(T::WeightInfo::propose())] pub fn propose( origin: OriginFor, proposal: BoundedCallOf, @@ -631,7 +630,6 @@ pub mod pallet { /// /// - `proposal`: The index of the proposal to second. #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::second())] pub fn second( origin: OriginFor, #[pallet::compact] proposal: PropIndex, @@ -699,7 +697,6 @@ pub mod pallet { /// /// - `proposal_hash`: The preimage hash of the proposal. #[pallet::call_index(4)] - #[pallet::weight(T::WeightInfo::external_propose())] pub fn external_propose( origin: OriginFor, proposal: BoundedCallOf, @@ -728,7 +725,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(5)] - #[pallet::weight(T::WeightInfo::external_propose_majority())] pub fn external_propose_majority( origin: OriginFor, proposal: BoundedCallOf, @@ -750,7 +746,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(6)] - #[pallet::weight(T::WeightInfo::external_propose_default())] pub fn external_propose_default( origin: OriginFor, proposal: BoundedCallOf, @@ -777,7 +772,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(7)] - #[pallet::weight(T::WeightInfo::fast_track())] pub fn fast_track( origin: OriginFor, proposal_hash: H256, @@ -831,7 +825,6 @@ pub mod pallet { /// /// Weight: `O(V + log(V))` where V is number of `existing vetoers` #[pallet::call_index(8)] - #[pallet::weight(T::WeightInfo::veto_external())] pub fn veto_external(origin: OriginFor, proposal_hash: H256) -> DispatchResult { let who = T::VetoOrigin::ensure_origin(origin)?; @@ -867,7 +860,6 @@ pub mod pallet { /// /// # Weight: `O(1)`. #[pallet::call_index(9)] - #[pallet::weight(T::WeightInfo::cancel_referendum())] pub fn cancel_referendum( origin: OriginFor, #[pallet::compact] ref_index: ReferendumIndex, @@ -942,7 +934,6 @@ pub mod pallet { /// /// Weight: `O(1)`. #[pallet::call_index(12)] - #[pallet::weight(T::WeightInfo::clear_public_proposals())] pub fn clear_public_proposals(origin: OriginFor) -> DispatchResult { ensure_root(origin)?; >::kill(); @@ -1096,7 +1087,6 @@ pub mod pallet { /// /// Weight: `O(p)` where `p = PublicProps::::decode_len()` #[pallet::call_index(17)] - #[pallet::weight(T::WeightInfo::cancel_proposal())] pub fn cancel_proposal( origin: OriginFor, #[pallet::compact] prop_index: PropIndex, diff --git a/frame/election-provider-multi-phase/src/lib.rs b/frame/election-provider-multi-phase/src/lib.rs index 3599037104d18..7444d5637d670 100644 --- a/frame/election-provider-multi-phase/src/lib.rs +++ b/frame/election-provider-multi-phase/src/lib.rs @@ -883,7 +883,7 @@ pub mod pallet { } } - #[pallet::call] + #[pallet::call(weight = ::WeightInfo)] impl Pallet { /// Submit a solution for the unsigned phase. /// @@ -1009,7 +1009,6 @@ pub mod pallet { /// A deposit is reserved and recorded for the solution. Based on the outcome, the solution /// might be rewarded, slashed, or get all or a part of the deposit back. #[pallet::call_index(3)] - #[pallet::weight(T::WeightInfo::submit())] pub fn submit( origin: OriginFor, raw_solution: Box>>, diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index d83c94db139a4..956074653390b 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -327,7 +327,7 @@ pub mod pallet { } } - #[pallet::call] + #[pallet::call(weight = ::WeightInfo)] impl Pallet { /// Vote for a set of candidates for the upcoming round of election. This can be called to /// set the initial votes, or update already existing votes. @@ -414,7 +414,6 @@ pub mod pallet { /// /// The dispatch origin of this call must be signed and be a voter. #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::remove_voter())] pub fn remove_voter(origin: OriginFor) -> DispatchResult { let who = ensure_signed(origin)?; ensure!(Self::is_voter(&who), Error::::MustBeVoter); diff --git a/frame/glutton/src/lib.rs b/frame/glutton/src/lib.rs index e9a46374a5ade..8882d4fc83c9a 100644 --- a/frame/glutton/src/lib.rs +++ b/frame/glutton/src/lib.rs @@ -139,7 +139,7 @@ pub mod pallet { } } - #[pallet::call] + #[pallet::call(weight = ::WeightInfo)] impl Pallet { /// Initializes the pallet by writing into `TrashData`. /// @@ -178,7 +178,6 @@ pub mod pallet { /// /// Only callable by Root. #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::set_compute())] pub fn set_compute(origin: OriginFor, compute: Perbill) -> DispatchResult { ensure_root(origin)?; Compute::::set(compute); @@ -192,7 +191,6 @@ pub mod pallet { /// /// Only callable by Root. #[pallet::call_index(2)] - #[pallet::weight(T::WeightInfo::set_storage())] pub fn set_storage(origin: OriginFor, storage: Perbill) -> DispatchResult { ensure_root(origin)?; Storage::::set(storage); diff --git a/frame/grandpa/src/lib.rs b/frame/grandpa/src/lib.rs index f01c25e49edd4..d5c51f08d7819 100644 --- a/frame/grandpa/src/lib.rs +++ b/frame/grandpa/src/lib.rs @@ -181,7 +181,7 @@ pub mod pallet { } } - #[pallet::call] + #[pallet::call(weight = ::WeightInfo)] impl Pallet { /// Report voter equivocation/misbehavior. This method will verify the /// equivocation proof and validate the given key ownership proof @@ -242,7 +242,6 @@ pub mod pallet { /// /// Only callable by root. #[pallet::call_index(2)] - #[pallet::weight(T::WeightInfo::note_stalled())] pub fn note_stalled( origin: OriginFor, delay: T::BlockNumber, diff --git a/frame/indices/src/lib.rs b/frame/indices/src/lib.rs index 74f86abb51914..d041a8808c312 100644 --- a/frame/indices/src/lib.rs +++ b/frame/indices/src/lib.rs @@ -77,7 +77,7 @@ pub mod pallet { #[pallet::pallet] pub struct Pallet(PhantomData); - #[pallet::call] + #[pallet::call(weight = ::WeightInfo)] impl Pallet { /// Assign an previously unassigned index. /// @@ -92,7 +92,6 @@ pub mod pallet { /// ## Complexity /// - `O(1)`. #[pallet::call_index(0)] - #[pallet::weight(T::WeightInfo::claim())] pub fn claim(origin: OriginFor, index: T::AccountIndex) -> DispatchResult { let who = ensure_signed(origin)?; @@ -118,7 +117,6 @@ pub mod pallet { /// ## Complexity /// - `O(1)`. #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::transfer())] pub fn transfer( origin: OriginFor, new: AccountIdLookupOf, @@ -153,7 +151,6 @@ pub mod pallet { /// ## Complexity /// - `O(1)`. #[pallet::call_index(2)] - #[pallet::weight(T::WeightInfo::free())] pub fn free(origin: OriginFor, index: T::AccountIndex) -> DispatchResult { let who = ensure_signed(origin)?; @@ -182,7 +179,6 @@ pub mod pallet { /// ## Complexity /// - `O(1)`. #[pallet::call_index(3)] - #[pallet::weight(T::WeightInfo::force_transfer())] pub fn force_transfer( origin: OriginFor, new: AccountIdLookupOf, @@ -215,7 +211,6 @@ pub mod pallet { /// ## Complexity /// - `O(1)`. #[pallet::call_index(4)] - #[pallet::weight(T::WeightInfo::freeze())] pub fn freeze(origin: OriginFor, index: T::AccountIndex) -> DispatchResult { let who = ensure_signed(origin)?; diff --git a/frame/lottery/src/lib.rs b/frame/lottery/src/lib.rs index 178f221a8946f..b17d40861e825 100644 --- a/frame/lottery/src/lib.rs +++ b/frame/lottery/src/lib.rs @@ -282,7 +282,7 @@ pub mod pallet { } } - #[pallet::call] + #[pallet::call(weight = ::WeightInfo)] impl Pallet { /// Buy a ticket to enter the lottery. /// @@ -346,7 +346,6 @@ pub mod pallet { /// * `delay`: How long after the lottery end we should wait before picking a winner. /// * `repeat`: If the lottery should repeat when completed. #[pallet::call_index(2)] - #[pallet::weight(T::WeightInfo::start_lottery())] pub fn start_lottery( origin: OriginFor, price: BalanceOf, @@ -379,7 +378,6 @@ pub mod pallet { /// /// This extrinsic must be called by the `ManagerOrigin`. #[pallet::call_index(3)] - #[pallet::weight(T::WeightInfo::stop_repeat())] pub fn stop_repeat(origin: OriginFor) -> DispatchResult { T::ManagerOrigin::ensure_origin(origin)?; Lottery::::mutate(|mut lottery| { diff --git a/frame/message-queue/src/lib.rs b/frame/message-queue/src/lib.rs index c8e1976103ebf..c08e7be90e2eb 100644 --- a/frame/message-queue/src/lib.rs +++ b/frame/message-queue/src/lib.rs @@ -576,11 +576,10 @@ pub mod pallet { } } - #[pallet::call] + #[pallet::call(weight = ::WeightInfo)] impl Pallet { /// Remove a page which has no more messages remaining to be processed or is stale. #[pallet::call_index(0)] - #[pallet::weight(T::WeightInfo::reap_page())] pub fn reap_page( origin: OriginFor, message_origin: MessageOriginOf, diff --git a/frame/nfts/src/lib.rs b/frame/nfts/src/lib.rs index f4d0e41593476..7d7f556ddf330 100644 --- a/frame/nfts/src/lib.rs +++ b/frame/nfts/src/lib.rs @@ -639,7 +639,7 @@ pub mod pallet { CollectionNotEmpty, } - #[pallet::call] + #[pallet::call(weight = >::WeightInfo)] impl, I: 'static> Pallet { /// Issue a new collection of non-fungible items from a public origin. /// @@ -657,7 +657,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(0)] - #[pallet::weight(T::WeightInfo::create())] pub fn create( origin: OriginFor, admin: AccountIdLookupOf, @@ -701,7 +700,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::force_create())] pub fn force_create( origin: OriginFor, owner: AccountIdLookupOf, @@ -780,7 +778,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(3)] - #[pallet::weight(T::WeightInfo::mint())] pub fn mint( origin: OriginFor, collection: T::CollectionId, @@ -886,7 +883,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(4)] - #[pallet::weight(T::WeightInfo::force_mint())] pub fn force_mint( origin: OriginFor, collection: T::CollectionId, @@ -920,7 +916,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(5)] - #[pallet::weight(T::WeightInfo::burn())] pub fn burn( origin: OriginFor, collection: T::CollectionId, @@ -953,7 +948,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(6)] - #[pallet::weight(T::WeightInfo::transfer())] pub fn transfer( origin: OriginFor, collection: T::CollectionId, @@ -1054,7 +1048,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(8)] - #[pallet::weight(T::WeightInfo::lock_item_transfer())] pub fn lock_item_transfer( origin: OriginFor, collection: T::CollectionId, @@ -1075,7 +1068,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(9)] - #[pallet::weight(T::WeightInfo::unlock_item_transfer())] pub fn unlock_item_transfer( origin: OriginFor, collection: T::CollectionId, @@ -1098,7 +1090,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(10)] - #[pallet::weight(T::WeightInfo::lock_collection())] pub fn lock_collection( origin: OriginFor, collection: T::CollectionId, @@ -1120,7 +1111,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(11)] - #[pallet::weight(T::WeightInfo::transfer_ownership())] pub fn transfer_ownership( origin: OriginFor, collection: T::CollectionId, @@ -1148,7 +1138,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(12)] - #[pallet::weight(T::WeightInfo::set_team())] pub fn set_team( origin: OriginFor, collection: T::CollectionId, @@ -1176,7 +1165,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(13)] - #[pallet::weight(T::WeightInfo::force_collection_owner())] pub fn force_collection_owner( origin: OriginFor, collection: T::CollectionId, @@ -1198,7 +1186,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(14)] - #[pallet::weight(T::WeightInfo::force_collection_config())] pub fn force_collection_config( origin: OriginFor, collection: T::CollectionId, @@ -1223,7 +1210,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(15)] - #[pallet::weight(T::WeightInfo::approve_transfer())] pub fn approve_transfer( origin: OriginFor, collection: T::CollectionId, @@ -1259,7 +1245,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(16)] - #[pallet::weight(T::WeightInfo::cancel_approval())] pub fn cancel_approval( origin: OriginFor, collection: T::CollectionId, @@ -1287,7 +1272,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(17)] - #[pallet::weight(T::WeightInfo::clear_all_transfer_approvals())] pub fn clear_all_transfer_approvals( origin: OriginFor, collection: T::CollectionId, @@ -1317,7 +1301,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(18)] - #[pallet::weight(T::WeightInfo::lock_item_properties())] pub fn lock_item_properties( origin: OriginFor, collection: T::CollectionId, @@ -1360,7 +1343,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(19)] - #[pallet::weight(T::WeightInfo::set_attribute())] pub fn set_attribute( origin: OriginFor, collection: T::CollectionId, @@ -1396,7 +1378,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(20)] - #[pallet::weight(T::WeightInfo::force_set_attribute())] pub fn force_set_attribute( origin: OriginFor, set_as: Option, @@ -1426,7 +1407,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(21)] - #[pallet::weight(T::WeightInfo::clear_attribute())] pub fn clear_attribute( origin: OriginFor, collection: T::CollectionId, @@ -1450,7 +1430,6 @@ pub mod pallet { /// /// Emits `ItemAttributesApprovalAdded` on success. #[pallet::call_index(22)] - #[pallet::weight(T::WeightInfo::approve_item_attributes())] pub fn approve_item_attributes( origin: OriginFor, collection: T::CollectionId, @@ -1505,7 +1484,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(24)] - #[pallet::weight(T::WeightInfo::set_metadata())] pub fn set_metadata( origin: OriginFor, collection: T::CollectionId, @@ -1532,7 +1510,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(25)] - #[pallet::weight(T::WeightInfo::clear_metadata())] pub fn clear_metadata( origin: OriginFor, collection: T::CollectionId, @@ -1560,7 +1537,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(26)] - #[pallet::weight(T::WeightInfo::set_collection_metadata())] pub fn set_collection_metadata( origin: OriginFor, collection: T::CollectionId, @@ -1585,7 +1561,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(27)] - #[pallet::weight(T::WeightInfo::clear_collection_metadata())] pub fn clear_collection_metadata( origin: OriginFor, collection: T::CollectionId, @@ -1607,7 +1582,6 @@ pub mod pallet { /// /// Emits `OwnershipAcceptanceChanged`. #[pallet::call_index(28)] - #[pallet::weight(T::WeightInfo::set_accept_ownership())] pub fn set_accept_ownership( origin: OriginFor, maybe_collection: Option, @@ -1626,7 +1600,6 @@ pub mod pallet { /// /// Emits `CollectionMaxSupplySet` event when successful. #[pallet::call_index(29)] - #[pallet::weight(T::WeightInfo::set_collection_max_supply())] pub fn set_collection_max_supply( origin: OriginFor, collection: T::CollectionId, @@ -1648,7 +1621,6 @@ pub mod pallet { /// /// Emits `CollectionMintSettingsUpdated` event when successful. #[pallet::call_index(30)] - #[pallet::weight(T::WeightInfo::update_mint_settings())] pub fn update_mint_settings( origin: OriginFor, collection: T::CollectionId, @@ -1676,7 +1648,6 @@ pub mod pallet { /// Emits `ItemPriceSet` on success if the price is not `None`. /// Emits `ItemPriceRemoved` on success if the price is `None`. #[pallet::call_index(31)] - #[pallet::weight(T::WeightInfo::set_price())] pub fn set_price( origin: OriginFor, collection: T::CollectionId, @@ -1699,7 +1670,6 @@ pub mod pallet { /// /// Emits `ItemBought` on success. #[pallet::call_index(32)] - #[pallet::weight(T::WeightInfo::buy_item())] pub fn buy_item( origin: OriginFor, collection: T::CollectionId, @@ -1744,7 +1714,6 @@ pub mod pallet { /// /// Emits `SwapCreated` on success. #[pallet::call_index(34)] - #[pallet::weight(T::WeightInfo::create_swap())] pub fn create_swap( origin: OriginFor, offered_collection: T::CollectionId, @@ -1776,7 +1745,6 @@ pub mod pallet { /// /// Emits `SwapCancelled` on success. #[pallet::call_index(35)] - #[pallet::weight(T::WeightInfo::cancel_swap())] pub fn cancel_swap( origin: OriginFor, offered_collection: T::CollectionId, @@ -1799,7 +1767,6 @@ pub mod pallet { /// /// Emits `SwapClaimed` on success. #[pallet::call_index(36)] - #[pallet::weight(T::WeightInfo::claim_swap())] pub fn claim_swap( origin: OriginFor, send_collection: T::CollectionId, diff --git a/frame/nis/src/lib.rs b/frame/nis/src/lib.rs index c4d0d0d420290..c420d275ea7d0 100644 --- a/frame/nis/src/lib.rs +++ b/frame/nis/src/lib.rs @@ -537,7 +537,7 @@ pub mod pallet { } } - #[pallet::call] + #[pallet::call(weight = ::WeightInfo)] impl Pallet { /// Place a bid. /// @@ -655,7 +655,6 @@ pub mod pallet { /// /// - `origin`: Must be accepted by `FundOrigin`. #[pallet::call_index(2)] - #[pallet::weight(T::WeightInfo::fund_deficit())] pub fn fund_deficit(origin: OriginFor) -> DispatchResult { T::FundOrigin::ensure_origin(origin)?; let summary: SummaryRecordOf = Summary::::get(); @@ -677,7 +676,6 @@ pub mod pallet { /// - `portion`: If `Some`, then only the given portion of the receipt should be thawed. If /// `None`, then all of it should be. #[pallet::call_index(3)] - #[pallet::weight(T::WeightInfo::thaw_private())] pub fn thaw_private( origin: OriginFor, #[pallet::compact] index: ReceiptIndex, @@ -783,7 +781,6 @@ pub mod pallet { /// for receipt `index`. /// - `index`: The index of the receipt. #[pallet::call_index(4)] - #[pallet::weight(T::WeightInfo::thaw_communal())] pub fn thaw_communal( origin: OriginFor, #[pallet::compact] index: ReceiptIndex, @@ -834,7 +831,6 @@ pub mod pallet { /// Make a private receipt communal and create fungible counterparts for its owner. #[pallet::call_index(5)] - #[pallet::weight(T::WeightInfo::communify())] pub fn communify( origin: OriginFor, #[pallet::compact] index: ReceiptIndex, @@ -872,7 +868,6 @@ pub mod pallet { /// Make a communal receipt private and burn fungible counterparts from its owner. #[pallet::call_index(6)] - #[pallet::weight(T::WeightInfo::privatize())] pub fn privatize( origin: OriginFor, #[pallet::compact] index: ReceiptIndex, diff --git a/frame/node-authorization/src/lib.rs b/frame/node-authorization/src/lib.rs index eaeda3cade9e9..27cca7e9433ac 100644 --- a/frame/node-authorization/src/lib.rs +++ b/frame/node-authorization/src/lib.rs @@ -201,7 +201,7 @@ pub mod pallet { } } - #[pallet::call] + #[pallet::call(weight = ::WeightInfo)] impl Pallet { /// Add a node to the set of well known nodes. If the node is already claimed, the owner /// will be updated and keep the existing additional connection unchanged. @@ -322,7 +322,6 @@ pub mod pallet { /// /// - `node`: identifier of the node. #[pallet::call_index(4)] - #[pallet::weight(T::WeightInfo::claim_node())] pub fn claim_node(origin: OriginFor, node: PeerId) -> DispatchResult { let sender = ensure_signed(origin)?; @@ -340,7 +339,6 @@ pub mod pallet { /// /// - `node`: identifier of the node. #[pallet::call_index(5)] - #[pallet::weight(T::WeightInfo::remove_claim())] pub fn remove_claim(origin: OriginFor, node: PeerId) -> DispatchResult { let sender = ensure_signed(origin)?; @@ -361,7 +359,6 @@ pub mod pallet { /// - `node`: identifier of the node. /// - `owner`: new owner of the node. #[pallet::call_index(6)] - #[pallet::weight(T::WeightInfo::transfer_node())] pub fn transfer_node( origin: OriginFor, node: PeerId, @@ -385,7 +382,6 @@ pub mod pallet { /// - `node`: identifier of the node. /// - `connections`: additonal nodes from which the connections are allowed. #[pallet::call_index(7)] - #[pallet::weight(T::WeightInfo::add_connections())] pub fn add_connections( origin: OriginFor, node: PeerId, @@ -420,7 +416,6 @@ pub mod pallet { /// - `node`: identifier of the node. /// - `connections`: additonal nodes from which the connections are not allowed anymore. #[pallet::call_index(8)] - #[pallet::weight(T::WeightInfo::remove_connections())] pub fn remove_connections( origin: OriginFor, node: PeerId, diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index 78f0c730ce5dd..d10ecf21e75ee 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1859,7 +1859,7 @@ pub mod pallet { } } - #[pallet::call] + #[pallet::call(weight = ::WeightInfo)] impl Pallet { /// Stake funds with a pool. The amount to bond is transferred from the member to the /// pools account and immediately increases the pools bond. @@ -1872,7 +1872,6 @@ pub mod pallet { /// `existential deposit + amount` in their account. /// * Only a pool with [`PoolState::Open`] can be joined #[pallet::call_index(0)] - #[pallet::weight(T::WeightInfo::join())] pub fn join( origin: OriginFor, #[pallet::compact] amount: BalanceOf, @@ -1953,7 +1952,6 @@ pub mod pallet { /// /// See `claim_payout_other` to caim rewards on bahalf of some `other` pool member. #[pallet::call_index(2)] - #[pallet::weight(T::WeightInfo::claim_payout())] pub fn claim_payout(origin: OriginFor) -> DispatchResult { let signer = ensure_signed(origin)?; Self::do_claim_payout(signer.clone(), signer) @@ -1991,7 +1989,6 @@ pub mod pallet { /// in which case, the result of this call will likely be the `NoMoreChunks` error from the /// staking system. #[pallet::call_index(3)] - #[pallet::weight(T::WeightInfo::unbond())] pub fn unbond( origin: OriginFor, member_account: AccountIdLookupOf, @@ -2230,7 +2227,6 @@ pub mod pallet { /// In addition to `amount`, the caller will transfer the existential deposit; so the caller /// needs at have at least `amount + existential_deposit` transferrable. #[pallet::call_index(6)] - #[pallet::weight(T::WeightInfo::create())] pub fn create( origin: OriginFor, #[pallet::compact] amount: BalanceOf, @@ -2303,7 +2299,6 @@ pub mod pallet { /// 2. if the pool conditions to be open are NOT met (as described by `ok_to_be_open`), and /// then the state of the pool can be permissionlessly changed to `Destroying`. #[pallet::call_index(9)] - #[pallet::weight(T::WeightInfo::set_state())] pub fn set_state( origin: OriginFor, pool_id: PoolId, @@ -2365,7 +2360,6 @@ pub mod pallet { /// * `max_members_per_pool` - Set [`MaxPoolMembersPerPool`]. /// * `global_max_commission` - Set [`GlobalMaxCommission`]. #[pallet::call_index(11)] - #[pallet::weight(T::WeightInfo::set_configs())] pub fn set_configs( origin: OriginFor, min_join_bond: ConfigOp>, @@ -2404,7 +2398,6 @@ pub mod pallet { /// It emits an event, notifying UIs of the role change. This event is quite relevant to /// most pool members and they should be informed of changes to pool roles. #[pallet::call_index(12)] - #[pallet::weight(T::WeightInfo::update_roles())] pub fn update_roles( origin: OriginFor, pool_id: PoolId, @@ -2457,7 +2450,6 @@ pub mod pallet { /// This directly forward the call to the staking pallet, on behalf of the pool bonded /// account. #[pallet::call_index(13)] - #[pallet::weight(T::WeightInfo::chill())] pub fn chill(origin: OriginFor, pool_id: PoolId) -> DispatchResult { let who = ensure_signed(origin)?; let bonded_pool = BondedPool::::get(pool_id).ok_or(Error::::PoolNotFound)?; @@ -2533,7 +2525,6 @@ pub mod pallet { /// /// - If a `None` is supplied to `new_commission`, existing commission will be removed. #[pallet::call_index(17)] - #[pallet::weight(T::WeightInfo::set_commission())] pub fn set_commission( origin: OriginFor, pool_id: PoolId, @@ -2569,7 +2560,6 @@ pub mod pallet { /// - Current commission will be lowered in the event it is higher than a new max /// commission. #[pallet::call_index(18)] - #[pallet::weight(T::WeightInfo::set_commission_max())] pub fn set_commission_max( origin: OriginFor, pool_id: PoolId, @@ -2591,7 +2581,6 @@ pub mod pallet { /// Initial change rate is not bounded, whereas subsequent updates can only be more /// restrictive than the current. #[pallet::call_index(19)] - #[pallet::weight(T::WeightInfo::set_commission_change_rate())] pub fn set_commission_change_rate( origin: OriginFor, pool_id: PoolId, @@ -2617,7 +2606,6 @@ pub mod pallet { /// commission is paid out and added to total claimed commission`. Total pending commission /// is reset to zero. the current. #[pallet::call_index(20)] - #[pallet::weight(T::WeightInfo::claim_commission())] pub fn claim_commission(origin: OriginFor, pool_id: PoolId) -> DispatchResult { let who = ensure_signed(origin)?; Self::do_claim_commission(who, pool_id) diff --git a/frame/preimage/src/lib.rs b/frame/preimage/src/lib.rs index 60208424db953..354a4c66fb7c8 100644 --- a/frame/preimage/src/lib.rs +++ b/frame/preimage/src/lib.rs @@ -146,7 +146,7 @@ pub mod pallet { pub(super) type PreimageFor = StorageMap<_, Identity, (T::Hash, u32), BoundedVec>>; - #[pallet::call] + #[pallet::call(weight = ::WeightInfo)] impl Pallet { /// Register a preimage on-chain. /// @@ -173,7 +173,6 @@ pub mod pallet { /// - `hash`: The hash of the preimage to be removed from the store. /// - `len`: The length of the preimage of `hash`. #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::unnote_preimage())] pub fn unnote_preimage(origin: OriginFor, hash: T::Hash) -> DispatchResult { let maybe_sender = Self::ensure_signed_or_manager(origin)?; Self::do_unnote_preimage(&hash, maybe_sender) @@ -184,7 +183,6 @@ pub mod pallet { /// If the preimage requests has already been provided on-chain, we unreserve any deposit /// a user may have paid, and take the control of the preimage out of their hands. #[pallet::call_index(2)] - #[pallet::weight(T::WeightInfo::request_preimage())] pub fn request_preimage(origin: OriginFor, hash: T::Hash) -> DispatchResult { T::ManagerOrigin::ensure_origin(origin)?; Self::do_request_preimage(&hash); @@ -195,7 +193,6 @@ pub mod pallet { /// /// NOTE: THIS MUST NOT BE CALLED ON `hash` MORE TIMES THAN `request_preimage`. #[pallet::call_index(3)] - #[pallet::weight(T::WeightInfo::unrequest_preimage())] pub fn unrequest_preimage(origin: OriginFor, hash: T::Hash) -> DispatchResult { T::ManagerOrigin::ensure_origin(origin)?; Self::do_unrequest_preimage(&hash) diff --git a/frame/ranked-collective/src/lib.rs b/frame/ranked-collective/src/lib.rs index 288fd78d6e718..f4ca9fe886482 100644 --- a/frame/ranked-collective/src/lib.rs +++ b/frame/ranked-collective/src/lib.rs @@ -428,7 +428,7 @@ pub mod pallet { NoPermission, } - #[pallet::call] + #[pallet::call(weight = >::WeightInfo)] impl, I: 'static> Pallet { /// Introduce a new member. /// @@ -438,7 +438,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(0)] - #[pallet::weight(T::WeightInfo::add_member())] pub fn add_member(origin: OriginFor, who: AccountIdLookupOf) -> DispatchResult { let _ = T::PromoteOrigin::ensure_origin(origin)?; let who = T::Lookup::lookup(who)?; @@ -517,7 +516,6 @@ pub mod pallet { /// /// Weight: `O(1)`, less if there was no previous vote on the poll by the member. #[pallet::call_index(4)] - #[pallet::weight(T::WeightInfo::vote())] pub fn vote( origin: OriginFor, poll: PollIndexOf, diff --git a/frame/recovery/src/lib.rs b/frame/recovery/src/lib.rs index d66b5725fd4f7..9d671ef4c5bd2 100644 --- a/frame/recovery/src/lib.rs +++ b/frame/recovery/src/lib.rs @@ -363,7 +363,7 @@ pub mod pallet { #[pallet::getter(fn proxy)] pub type Proxy = StorageMap<_, Blake2_128Concat, T::AccountId, T::AccountId>; - #[pallet::call] + #[pallet::call(weight = ::WeightInfo)] impl Pallet { /// Send a call through a recovered account. /// @@ -404,7 +404,6 @@ pub mod pallet { /// - `lost`: The "lost account" to be recovered. /// - `rescuer`: The "rescuer account" which can call as the lost account. #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::set_recovered())] pub fn set_recovered( origin: OriginFor, lost: AccountIdLookupOf, @@ -491,7 +490,6 @@ pub mod pallet { /// - `account`: The lost account that you want to recover. This account needs to be /// recoverable (i.e. have a recovery configuration). #[pallet::call_index(3)] - #[pallet::weight(T::WeightInfo::initiate_recovery())] pub fn initiate_recovery( origin: OriginFor, account: AccountIdLookupOf, @@ -689,7 +687,6 @@ pub mod pallet { /// Parameters: /// - `account`: The recovered account you are able to call on-behalf-of. #[pallet::call_index(8)] - #[pallet::weight(T::WeightInfo::cancel_recovered())] pub fn cancel_recovered( origin: OriginFor, account: AccountIdLookupOf, diff --git a/frame/referenda/src/lib.rs b/frame/referenda/src/lib.rs index 68837376c5b33..c34b90c98c756 100644 --- a/frame/referenda/src/lib.rs +++ b/frame/referenda/src/lib.rs @@ -411,7 +411,7 @@ pub mod pallet { PreimageNotExist, } - #[pallet::call] + #[pallet::call(weight = >::WeightInfo)] impl, I: 'static> Pallet { /// Propose a referendum on a privileged action. /// @@ -423,7 +423,6 @@ pub mod pallet { /// /// Emits `Submitted`. #[pallet::call_index(0)] - #[pallet::weight(T::WeightInfo::submit())] pub fn submit( origin: OriginFor, proposal_origin: Box>, @@ -499,7 +498,6 @@ pub mod pallet { /// /// Emits `DecisionDepositRefunded`. #[pallet::call_index(2)] - #[pallet::weight(T::WeightInfo::refund_decision_deposit())] pub fn refund_decision_deposit( origin: OriginFor, index: ReferendumIndex, @@ -529,7 +527,6 @@ pub mod pallet { /// /// Emits `Cancelled`. #[pallet::call_index(3)] - #[pallet::weight(T::WeightInfo::cancel())] pub fn cancel(origin: OriginFor, index: ReferendumIndex) -> DispatchResult { T::CancelOrigin::ensure_origin(origin)?; let status = Self::ensure_ongoing(index)?; @@ -554,7 +551,6 @@ pub mod pallet { /// /// Emits `Killed` and `DepositSlashed`. #[pallet::call_index(4)] - #[pallet::weight(T::WeightInfo::kill())] pub fn kill(origin: OriginFor, index: ReferendumIndex) -> DispatchResult { T::KillOrigin::ensure_origin(origin)?; let status = Self::ensure_ongoing(index)?; @@ -637,7 +633,6 @@ pub mod pallet { /// /// Emits `SubmissionDepositRefunded`. #[pallet::call_index(7)] - #[pallet::weight(T::WeightInfo::refund_submission_deposit())] pub fn refund_submission_deposit( origin: OriginFor, index: ReferendumIndex, diff --git a/frame/session/src/lib.rs b/frame/session/src/lib.rs index a9f89412a71c4..174da2ed6af8b 100644 --- a/frame/session/src/lib.rs +++ b/frame/session/src/lib.rs @@ -578,7 +578,7 @@ pub mod pallet { } } - #[pallet::call] + #[pallet::call(weight = ::WeightInfo)] impl Pallet { /// Sets the session key(s) of the function caller to `keys`. /// Allows an account to set its session key prior to becoming a validator. @@ -590,7 +590,6 @@ pub mod pallet { /// - `O(1)`. Actual cost depends on the number of length of `T::Keys::key_ids()` which is /// fixed. #[pallet::call_index(0)] - #[pallet::weight(T::WeightInfo::set_keys())] pub fn set_keys(origin: OriginFor, keys: T::Keys, proof: Vec) -> DispatchResult { let who = ensure_signed(origin)?; ensure!(keys.ownership_proof_is_valid(&proof), Error::::InvalidProof); @@ -612,7 +611,6 @@ pub mod pallet { /// - `O(1)` in number of key types. Actual cost depends on the number of length of /// `T::Keys::key_ids()` which is fixed. #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::purge_keys())] pub fn purge_keys(origin: OriginFor) -> DispatchResult { let who = ensure_signed(origin)?; Self::do_purge_keys(&who)?; diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index d8f1855da4bc0..a37783182b5d5 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -829,7 +829,7 @@ pub mod pallet { } } - #[pallet::call] + #[pallet::call(weight = ::WeightInfo)] impl Pallet { /// Take the origin account as a stash and lock up `value` of its balance. `controller` will /// be the account that controls it. @@ -847,7 +847,6 @@ pub mod pallet { /// NOTE: Two of the storage writes (`Self::bonded`, `Self::payee`) are _never_ cleaned /// unless the `origin` falls below _existential deposit_ and gets removed as dust. #[pallet::call_index(0)] - #[pallet::weight(T::WeightInfo::bond())] pub fn bond( origin: OriginFor, controller: AccountIdLookupOf, @@ -916,7 +915,6 @@ pub mod pallet { /// - Independent of the arguments. Insignificant complexity. /// - O(1). #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::bond_extra())] pub fn bond_extra( origin: OriginFor, #[pallet::compact] max_additional: BalanceOf, @@ -1093,7 +1091,6 @@ pub mod pallet { /// /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. #[pallet::call_index(4)] - #[pallet::weight(T::WeightInfo::validate())] pub fn validate(origin: OriginFor, prefs: ValidatorPrefs) -> DispatchResult { let controller = ensure_signed(origin)?; @@ -1204,7 +1201,6 @@ pub mod pallet { /// - Contains one read. /// - Writes are limited to the `origin` account key. #[pallet::call_index(6)] - #[pallet::weight(T::WeightInfo::chill())] pub fn chill(origin: OriginFor) -> DispatchResult { let controller = ensure_signed(origin)?; let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; @@ -1225,7 +1221,6 @@ pub mod pallet { /// - Writes are limited to the `origin` account key. /// --------- #[pallet::call_index(7)] - #[pallet::weight(T::WeightInfo::set_payee())] pub fn set_payee( origin: OriginFor, payee: RewardDestination, @@ -1249,7 +1244,6 @@ pub mod pallet { /// - Contains a limited number of reads. /// - Writes are limited to the `origin` account key. #[pallet::call_index(8)] - #[pallet::weight(T::WeightInfo::set_controller())] pub fn set_controller( origin: OriginFor, controller: AccountIdLookupOf, @@ -1276,7 +1270,6 @@ pub mod pallet { /// ## Complexity /// O(1) #[pallet::call_index(9)] - #[pallet::weight(T::WeightInfo::set_validator_count())] pub fn set_validator_count( origin: OriginFor, #[pallet::compact] new: u32, @@ -1354,7 +1347,6 @@ pub mod pallet { /// - No arguments. /// - Weight: O(1) #[pallet::call_index(12)] - #[pallet::weight(T::WeightInfo::force_no_eras())] pub fn force_no_eras(origin: OriginFor) -> DispatchResult { ensure_root(origin)?; Self::set_force_era(Forcing::ForceNone); @@ -1376,7 +1368,6 @@ pub mod pallet { /// - No arguments. /// - Weight: O(1) #[pallet::call_index(13)] - #[pallet::weight(T::WeightInfo::force_new_era())] pub fn force_new_era(origin: OriginFor) -> DispatchResult { ensure_root(origin)?; Self::set_force_era(Forcing::ForceNew); @@ -1427,7 +1418,6 @@ pub mod pallet { /// If this is called just before a new era is triggered, the election process may not /// have enough blocks to get a result. #[pallet::call_index(16)] - #[pallet::weight(T::WeightInfo::force_new_era_always())] pub fn force_new_era_always(origin: OriginFor) -> DispatchResult { ensure_root(origin)?; Self::set_force_era(Forcing::ForceAlways); @@ -1682,7 +1672,6 @@ pub mod pallet { /// This can be helpful if bond requirements are updated, and we need to remove old users /// who do not satisfy these requirements. #[pallet::call_index(23)] - #[pallet::weight(T::WeightInfo::chill_other())] pub fn chill_other(origin: OriginFor, controller: T::AccountId) -> DispatchResult { // Anyone can call this function. let caller = ensure_signed(origin)?; @@ -1745,7 +1734,6 @@ pub mod pallet { /// validator who already has a commission greater than or equal to the minimum. Any account /// can call this. #[pallet::call_index(24)] - #[pallet::weight(T::WeightInfo::force_apply_min_commission())] pub fn force_apply_min_commission( origin: OriginFor, validator_stash: T::AccountId, @@ -1769,7 +1757,6 @@ pub mod pallet { /// This call has lower privilege requirements than `set_staking_config` and can be called /// by the `T::AdminOrigin`. Root can always call this. #[pallet::call_index(25)] - #[pallet::weight(T::WeightInfo::set_min_commission())] pub fn set_min_commission(origin: OriginFor, new: Perbill) -> DispatchResult { T::AdminOrigin::ensure_origin(origin)?; MinCommission::::put(new); diff --git a/frame/transaction-storage/src/lib.rs b/frame/transaction-storage/src/lib.rs index 59662ee860541..a519a63a318a0 100644 --- a/frame/transaction-storage/src/lib.rs +++ b/frame/transaction-storage/src/lib.rs @@ -179,7 +179,7 @@ pub mod pallet { } } - #[pallet::call] + #[pallet::call(weight = ::WeightInfo)] impl Pallet { /// Index and store data off chain. Minimum data size is 1 bytes, maximum is /// `MaxTransactionSize`. Data will be removed after `STORAGE_PERIOD` blocks, unless `renew` @@ -235,7 +235,6 @@ pub mod pallet { /// ## Complexity /// - O(1). #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::renew())] pub fn renew( origin: OriginFor, block: T::BlockNumber, diff --git a/frame/treasury/src/lib.rs b/frame/treasury/src/lib.rs index 450aee51f2ce8..25eab73f486f1 100644 --- a/frame/treasury/src/lib.rs +++ b/frame/treasury/src/lib.rs @@ -343,7 +343,7 @@ pub mod pallet { spend_in_context: BTreeMap, } - #[pallet::call] + #[pallet::call(weight = >::WeightInfo)] impl, I: 'static> Pallet { /// Put forward a suggestion for spending. A deposit proportional to the value /// is reserved and slashed if the proposal is rejected. It is returned once the @@ -352,7 +352,6 @@ pub mod pallet { /// ## Complexity /// - O(1) #[pallet::call_index(0)] - #[pallet::weight(T::WeightInfo::propose_spend())] pub fn propose_spend( origin: OriginFor, #[pallet::compact] value: BalanceOf, @@ -430,7 +429,6 @@ pub mod pallet { /// NOTE: For record-keeping purposes, the proposer is deemed to be equivalent to the /// beneficiary. #[pallet::call_index(3)] - #[pallet::weight(T::WeightInfo::spend())] pub fn spend( origin: OriginFor, #[pallet::compact] amount: BalanceOf, diff --git a/frame/uniques/src/lib.rs b/frame/uniques/src/lib.rs index fd94bd3a9a7e4..0aeb8090047c5 100644 --- a/frame/uniques/src/lib.rs +++ b/frame/uniques/src/lib.rs @@ -432,7 +432,7 @@ pub mod pallet { } } - #[pallet::call] + #[pallet::call(weight = >::WeightInfo)] impl, I: 'static> Pallet { /// Issue a new collection of non-fungible items from a public origin. /// @@ -451,7 +451,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(0)] - #[pallet::weight(T::WeightInfo::create())] pub fn create( origin: OriginFor, collection: T::CollectionId, @@ -488,7 +487,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::force_create())] pub fn force_create( origin: OriginFor, collection: T::CollectionId, @@ -560,7 +558,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(3)] - #[pallet::weight(T::WeightInfo::mint())] pub fn mint( origin: OriginFor, collection: T::CollectionId, @@ -592,7 +589,6 @@ pub mod pallet { /// Weight: `O(1)` /// Modes: `check_owner.is_some()`. #[pallet::call_index(4)] - #[pallet::weight(T::WeightInfo::burn())] pub fn burn( origin: OriginFor, collection: T::CollectionId, @@ -631,7 +627,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(5)] - #[pallet::weight(T::WeightInfo::transfer())] pub fn transfer( origin: OriginFor, collection: T::CollectionId, @@ -729,7 +724,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(7)] - #[pallet::weight(T::WeightInfo::freeze())] pub fn freeze( origin: OriginFor, collection: T::CollectionId, @@ -761,7 +755,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(8)] - #[pallet::weight(T::WeightInfo::thaw())] pub fn thaw( origin: OriginFor, collection: T::CollectionId, @@ -792,7 +785,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(9)] - #[pallet::weight(T::WeightInfo::freeze_collection())] pub fn freeze_collection( origin: OriginFor, collection: T::CollectionId, @@ -820,7 +812,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(10)] - #[pallet::weight(T::WeightInfo::thaw_collection())] pub fn thaw_collection( origin: OriginFor, collection: T::CollectionId, @@ -850,7 +841,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(11)] - #[pallet::weight(T::WeightInfo::transfer_ownership())] pub fn transfer_ownership( origin: OriginFor, collection: T::CollectionId, @@ -899,7 +889,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(12)] - #[pallet::weight(T::WeightInfo::set_team())] pub fn set_team( origin: OriginFor, collection: T::CollectionId, @@ -940,7 +929,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(13)] - #[pallet::weight(T::WeightInfo::approve_transfer())] pub fn approve_transfer( origin: OriginFor, collection: T::CollectionId, @@ -994,7 +982,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(14)] - #[pallet::weight(T::WeightInfo::cancel_approval())] pub fn cancel_approval( origin: OriginFor, collection: T::CollectionId, @@ -1047,7 +1034,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(15)] - #[pallet::weight(T::WeightInfo::force_item_status())] pub fn force_item_status( origin: OriginFor, collection: T::CollectionId, @@ -1097,7 +1083,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(16)] - #[pallet::weight(T::WeightInfo::set_attribute())] pub fn set_attribute( origin: OriginFor, collection: T::CollectionId, @@ -1160,7 +1145,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(17)] - #[pallet::weight(T::WeightInfo::clear_attribute())] pub fn clear_attribute( origin: OriginFor, collection: T::CollectionId, @@ -1210,7 +1194,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(18)] - #[pallet::weight(T::WeightInfo::set_metadata())] pub fn set_metadata( origin: OriginFor, collection: T::CollectionId, @@ -1273,7 +1256,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(19)] - #[pallet::weight(T::WeightInfo::clear_metadata())] pub fn clear_metadata( origin: OriginFor, collection: T::CollectionId, @@ -1323,7 +1305,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(20)] - #[pallet::weight(T::WeightInfo::set_collection_metadata())] pub fn set_collection_metadata( origin: OriginFor, collection: T::CollectionId, @@ -1381,7 +1362,6 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(21)] - #[pallet::weight(T::WeightInfo::clear_collection_metadata())] pub fn clear_collection_metadata( origin: OriginFor, collection: T::CollectionId, @@ -1418,7 +1398,6 @@ pub mod pallet { /// /// Emits `OwnershipAcceptanceChanged`. #[pallet::call_index(22)] - #[pallet::weight(T::WeightInfo::set_accept_ownership())] pub fn set_accept_ownership( origin: OriginFor, maybe_collection: Option, @@ -1455,7 +1434,6 @@ pub mod pallet { /// /// Emits `CollectionMaxSupplySet` event when successful. #[pallet::call_index(23)] - #[pallet::weight(T::WeightInfo::set_collection_max_supply())] pub fn set_collection_max_supply( origin: OriginFor, collection: T::CollectionId, @@ -1495,7 +1473,6 @@ pub mod pallet { /// Emits `ItemPriceSet` on success if the price is not `None`. /// Emits `ItemPriceRemoved` on success if the price is `None`. #[pallet::call_index(24)] - #[pallet::weight(T::WeightInfo::set_price())] pub fn set_price( origin: OriginFor, collection: T::CollectionId, diff --git a/frame/whitelist/src/lib.rs b/frame/whitelist/src/lib.rs index decf010b06757..08828293e7551 100644 --- a/frame/whitelist/src/lib.rs +++ b/frame/whitelist/src/lib.rs @@ -116,10 +116,9 @@ pub mod pallet { pub type WhitelistedCall = StorageMap<_, Twox64Concat, PreimageHash, (), OptionQuery>; - #[pallet::call] + #[pallet::call(weight = ::WeightInfo)] impl Pallet { #[pallet::call_index(0)] - #[pallet::weight(T::WeightInfo::whitelist_call())] pub fn whitelist_call(origin: OriginFor, call_hash: PreimageHash) -> DispatchResult { T::WhitelistOrigin::ensure_origin(origin)?; @@ -137,7 +136,6 @@ pub mod pallet { } #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::remove_whitelisted_call())] pub fn remove_whitelisted_call( origin: OriginFor, call_hash: PreimageHash, From f83be2bc08df6c79d8e23e52795675ddc7fe5050 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Tue, 18 Apr 2023 18:16:00 +0200 Subject: [PATCH 09/17] Try to add some docs Signed-off-by: Oliver Tale-Yazdi --- .../procedural/src/pallet/parse/mod.rs | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/frame/support/procedural/src/pallet/parse/mod.rs b/frame/support/procedural/src/pallet/parse/mod.rs index 7a20558a9b077..8fd4312e21a0e 100644 --- a/frame/support/procedural/src/pallet/parse/mod.rs +++ b/frame/support/procedural/src/pallet/parse/mod.rs @@ -427,7 +427,35 @@ enum PalletAttr { Config(proc_macro2::Span), Pallet(proc_macro2::Span), Hooks(proc_macro2::Span), - /// A `#[pallet::call]` with or without `#[pallet::call(weight($type))]` attribute. + /// A `#[pallet::call]` with optional attribute. + /// + /// # Attributes + /// + /// All attributes can be assigned by calling or assigning to them. + /// + /// ## `weight` + /// + /// Can be used to reduce the repetitive weight annotation in the trivial case. Instead of + /// writing: + /// + /// ```ignore + /// #[pallet::call] + /// impl Pallet { + /// #[pallet::weight(T::WeightInfo::create())] + /// pub fn create( + /// ``` + /// you can now do: + /// + /// ```ignore + /// #[pallet::call(weight = ::WeightInfo)] + /// impl Pallet { + /// pub fn create( + /// ``` + /// + /// Both code snippets are equivalent. The passed type will be prepended to the name of the + /// call - if there is no `weight` attribute set on the call. This works together with + /// instanced pallets by using `Config`. This attribute takes precedence over the default + /// weight if the pallet is in dev-mode. RuntimeCall(Option, proc_macro2::Span), Error(proc_macro2::Span), RuntimeEvent(proc_macro2::Span), From 49eab30953c881242cefd5f0ef96dee574ff50ff Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Tue, 18 Apr 2023 18:18:04 +0200 Subject: [PATCH 10/17] 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 --- bin/node-template/pallets/template/src/lib.rs | 4 ++- frame/bags-list/src/lib.rs | 3 +- frame/contracts/src/lib.rs | 4 ++- frame/conviction-voting/src/lib.rs | 5 ++- frame/democracy/src/lib.rs | 12 ++++++- .../election-provider-multi-phase/src/lib.rs | 3 +- frame/elections-phragmen/src/lib.rs | 3 +- frame/glutton/src/lib.rs | 4 ++- frame/grandpa/src/lib.rs | 3 +- frame/indices/src/lib.rs | 7 +++- frame/lottery/src/lib.rs | 4 ++- frame/message-queue/src/lib.rs | 3 +- frame/nfts/src/lib.rs | 35 ++++++++++++++++++- frame/nis/src/lib.rs | 7 +++- frame/node-authorization/src/lib.rs | 7 +++- frame/nomination-pools/src/lib.rs | 14 +++++++- frame/preimage/src/lib.rs | 5 ++- frame/ranked-collective/src/lib.rs | 4 ++- frame/recovery/src/lib.rs | 5 ++- frame/referenda/src/lib.rs | 7 +++- frame/session/src/lib.rs | 4 ++- frame/staking/src/pallet/mod.rs | 15 +++++++- frame/transaction-storage/src/lib.rs | 3 +- frame/treasury/src/lib.rs | 4 ++- frame/uniques/src/lib.rs | 25 ++++++++++++- frame/whitelist/src/lib.rs | 4 ++- 26 files changed, 168 insertions(+), 26 deletions(-) diff --git a/bin/node-template/pallets/template/src/lib.rs b/bin/node-template/pallets/template/src/lib.rs index 1c40356f6f539..9550d3d546cca 100644 --- a/bin/node-template/pallets/template/src/lib.rs +++ b/bin/node-template/pallets/template/src/lib.rs @@ -64,11 +64,12 @@ pub mod pallet { // Dispatchable functions allows users to interact with the pallet and invoke state changes. // These functions materialize as "extrinsics", which are often compared to transactions. // Dispatchable functions must be annotated with a weight and must return a DispatchResult. - #[pallet::call(weight = ::WeightInfo)] + #[pallet::call] impl Pallet { /// An example dispatchable that takes a singles value as a parameter, writes the value to /// storage and emits an event. This function must be dispatched by a signed extrinsic. #[pallet::call_index(0)] + #[pallet::weight(T::WeightInfo::do_something())] pub fn do_something(origin: OriginFor, something: u32) -> DispatchResult { // Check that the extrinsic was signed and get the signer. // This function will return an error if the extrinsic is not signed. @@ -86,6 +87,7 @@ pub mod pallet { /// An example dispatchable that may throw a custom error. #[pallet::call_index(1)] + #[pallet::weight(T::WeightInfo::cause_error())] pub fn cause_error(origin: OriginFor) -> DispatchResult { let _who = ensure_signed(origin)?; diff --git a/frame/bags-list/src/lib.rs b/frame/bags-list/src/lib.rs index dd6aa5d39c0c7..87eb2d1b341aa 100644 --- a/frame/bags-list/src/lib.rs +++ b/frame/bags-list/src/lib.rs @@ -211,7 +211,7 @@ pub mod pallet { } } - #[pallet::call(weight = >::WeightInfo)] + #[pallet::call] impl, I: 'static> Pallet { /// Declare that some `dislocated` account has, through rewards or penalties, sufficiently /// changed its score that it should properly fall into a different bag than its current @@ -243,6 +243,7 @@ pub mod pallet { /// - both nodes are within the same bag, /// - and `origin` has a greater `Score` than `lighter`. #[pallet::call_index(1)] + #[pallet::weight(T::WeightInfo::put_in_front_of())] pub fn put_in_front_of( origin: OriginFor, lighter: AccountIdLookupOf, diff --git a/frame/contracts/src/lib.rs b/frame/contracts/src/lib.rs index 640bf3d63b477..26b16b3291a2f 100644 --- a/frame/contracts/src/lib.rs +++ b/frame/contracts/src/lib.rs @@ -374,7 +374,7 @@ pub mod pallet { } } - #[pallet::call(weight = ::WeightInfo)] + #[pallet::call] impl Pallet where as HasCompact>::Type: Clone + Eq + PartialEq + Debug + TypeInfo + Encode, @@ -497,6 +497,7 @@ pub mod pallet { /// A code can only be removed by its original uploader (its owner) and only if it is /// not used by any contract. #[pallet::call_index(4)] + #[pallet::weight(T::WeightInfo::remove_code())] pub fn remove_code( origin: OriginFor, code_hash: CodeHash, @@ -518,6 +519,7 @@ pub mod pallet { /// that the contract address is no longer derived from its code hash after calling /// this dispatchable. #[pallet::call_index(5)] + #[pallet::weight(T::WeightInfo::set_code())] pub fn set_code( origin: OriginFor, dest: AccountIdLookupOf, diff --git a/frame/conviction-voting/src/lib.rs b/frame/conviction-voting/src/lib.rs index 2e902dd4caa89..072e57035484d 100644 --- a/frame/conviction-voting/src/lib.rs +++ b/frame/conviction-voting/src/lib.rs @@ -196,7 +196,7 @@ pub mod pallet { BadClass, } - #[pallet::call(weight = >::WeightInfo)] + #[pallet::call] impl, I: 'static> Pallet { /// Vote in a poll. If `vote.is_aye()`, the vote is to enact the proposal; /// otherwise it is a vote to keep the status quo. @@ -296,6 +296,7 @@ pub mod pallet { /// /// Weight: `O(R)` with R number of vote of target. #[pallet::call_index(3)] + #[pallet::weight(T::WeightInfo::unlock())] pub fn unlock( origin: OriginFor, class: ClassOf, @@ -337,6 +338,7 @@ pub mod pallet { /// Weight: `O(R + log R)` where R is the number of polls that `target` has voted on. /// Weight is calculated for the maximum number of vote. #[pallet::call_index(4)] + #[pallet::weight(T::WeightInfo::remove_vote())] pub fn remove_vote( origin: OriginFor, class: Option>, @@ -363,6 +365,7 @@ pub mod pallet { /// Weight: `O(R + log R)` where R is the number of polls that `target` has voted on. /// Weight is calculated for the maximum number of vote. #[pallet::call_index(5)] + #[pallet::weight(T::WeightInfo::remove_other_vote())] pub fn remove_other_vote( origin: OriginFor, target: AccountIdLookupOf, diff --git a/frame/democracy/src/lib.rs b/frame/democracy/src/lib.rs index 954bb14033100..a3d7f103a98f3 100644 --- a/frame/democracy/src/lib.rs +++ b/frame/democracy/src/lib.rs @@ -576,7 +576,7 @@ pub mod pallet { } } - #[pallet::call(weight = ::WeightInfo)] + #[pallet::call] impl Pallet { /// Propose a sensitive action to be taken. /// @@ -588,6 +588,7 @@ pub mod pallet { /// /// Emits `Proposed`. #[pallet::call_index(0)] + #[pallet::weight(T::WeightInfo::propose())] pub fn propose( origin: OriginFor, proposal: BoundedCallOf, @@ -630,6 +631,7 @@ pub mod pallet { /// /// - `proposal`: The index of the proposal to second. #[pallet::call_index(1)] + #[pallet::weight(T::WeightInfo::second())] pub fn second( origin: OriginFor, #[pallet::compact] proposal: PropIndex, @@ -697,6 +699,7 @@ pub mod pallet { /// /// - `proposal_hash`: The preimage hash of the proposal. #[pallet::call_index(4)] + #[pallet::weight(T::WeightInfo::external_propose())] pub fn external_propose( origin: OriginFor, proposal: BoundedCallOf, @@ -725,6 +728,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(5)] + #[pallet::weight(T::WeightInfo::external_propose_majority())] pub fn external_propose_majority( origin: OriginFor, proposal: BoundedCallOf, @@ -746,6 +750,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(6)] + #[pallet::weight(T::WeightInfo::external_propose_default())] pub fn external_propose_default( origin: OriginFor, proposal: BoundedCallOf, @@ -772,6 +777,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(7)] + #[pallet::weight(T::WeightInfo::fast_track())] pub fn fast_track( origin: OriginFor, proposal_hash: H256, @@ -825,6 +831,7 @@ pub mod pallet { /// /// Weight: `O(V + log(V))` where V is number of `existing vetoers` #[pallet::call_index(8)] + #[pallet::weight(T::WeightInfo::veto_external())] pub fn veto_external(origin: OriginFor, proposal_hash: H256) -> DispatchResult { let who = T::VetoOrigin::ensure_origin(origin)?; @@ -860,6 +867,7 @@ pub mod pallet { /// /// # Weight: `O(1)`. #[pallet::call_index(9)] + #[pallet::weight(T::WeightInfo::cancel_referendum())] pub fn cancel_referendum( origin: OriginFor, #[pallet::compact] ref_index: ReferendumIndex, @@ -934,6 +942,7 @@ pub mod pallet { /// /// Weight: `O(1)`. #[pallet::call_index(12)] + #[pallet::weight(T::WeightInfo::clear_public_proposals())] pub fn clear_public_proposals(origin: OriginFor) -> DispatchResult { ensure_root(origin)?; >::kill(); @@ -1087,6 +1096,7 @@ pub mod pallet { /// /// Weight: `O(p)` where `p = PublicProps::::decode_len()` #[pallet::call_index(17)] + #[pallet::weight(T::WeightInfo::cancel_proposal())] pub fn cancel_proposal( origin: OriginFor, #[pallet::compact] prop_index: PropIndex, diff --git a/frame/election-provider-multi-phase/src/lib.rs b/frame/election-provider-multi-phase/src/lib.rs index 7444d5637d670..3599037104d18 100644 --- a/frame/election-provider-multi-phase/src/lib.rs +++ b/frame/election-provider-multi-phase/src/lib.rs @@ -883,7 +883,7 @@ pub mod pallet { } } - #[pallet::call(weight = ::WeightInfo)] + #[pallet::call] impl Pallet { /// Submit a solution for the unsigned phase. /// @@ -1009,6 +1009,7 @@ pub mod pallet { /// A deposit is reserved and recorded for the solution. Based on the outcome, the solution /// might be rewarded, slashed, or get all or a part of the deposit back. #[pallet::call_index(3)] + #[pallet::weight(T::WeightInfo::submit())] pub fn submit( origin: OriginFor, raw_solution: Box>>, diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index 956074653390b..d83c94db139a4 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -327,7 +327,7 @@ pub mod pallet { } } - #[pallet::call(weight = ::WeightInfo)] + #[pallet::call] impl Pallet { /// Vote for a set of candidates for the upcoming round of election. This can be called to /// set the initial votes, or update already existing votes. @@ -414,6 +414,7 @@ pub mod pallet { /// /// The dispatch origin of this call must be signed and be a voter. #[pallet::call_index(1)] + #[pallet::weight(T::WeightInfo::remove_voter())] pub fn remove_voter(origin: OriginFor) -> DispatchResult { let who = ensure_signed(origin)?; ensure!(Self::is_voter(&who), Error::::MustBeVoter); diff --git a/frame/glutton/src/lib.rs b/frame/glutton/src/lib.rs index 8882d4fc83c9a..e9a46374a5ade 100644 --- a/frame/glutton/src/lib.rs +++ b/frame/glutton/src/lib.rs @@ -139,7 +139,7 @@ pub mod pallet { } } - #[pallet::call(weight = ::WeightInfo)] + #[pallet::call] impl Pallet { /// Initializes the pallet by writing into `TrashData`. /// @@ -178,6 +178,7 @@ pub mod pallet { /// /// Only callable by Root. #[pallet::call_index(1)] + #[pallet::weight(T::WeightInfo::set_compute())] pub fn set_compute(origin: OriginFor, compute: Perbill) -> DispatchResult { ensure_root(origin)?; Compute::::set(compute); @@ -191,6 +192,7 @@ pub mod pallet { /// /// Only callable by Root. #[pallet::call_index(2)] + #[pallet::weight(T::WeightInfo::set_storage())] pub fn set_storage(origin: OriginFor, storage: Perbill) -> DispatchResult { ensure_root(origin)?; Storage::::set(storage); diff --git a/frame/grandpa/src/lib.rs b/frame/grandpa/src/lib.rs index d5c51f08d7819..f01c25e49edd4 100644 --- a/frame/grandpa/src/lib.rs +++ b/frame/grandpa/src/lib.rs @@ -181,7 +181,7 @@ pub mod pallet { } } - #[pallet::call(weight = ::WeightInfo)] + #[pallet::call] impl Pallet { /// Report voter equivocation/misbehavior. This method will verify the /// equivocation proof and validate the given key ownership proof @@ -242,6 +242,7 @@ pub mod pallet { /// /// Only callable by root. #[pallet::call_index(2)] + #[pallet::weight(T::WeightInfo::note_stalled())] pub fn note_stalled( origin: OriginFor, delay: T::BlockNumber, diff --git a/frame/indices/src/lib.rs b/frame/indices/src/lib.rs index d041a8808c312..74f86abb51914 100644 --- a/frame/indices/src/lib.rs +++ b/frame/indices/src/lib.rs @@ -77,7 +77,7 @@ pub mod pallet { #[pallet::pallet] pub struct Pallet(PhantomData); - #[pallet::call(weight = ::WeightInfo)] + #[pallet::call] impl Pallet { /// Assign an previously unassigned index. /// @@ -92,6 +92,7 @@ pub mod pallet { /// ## Complexity /// - `O(1)`. #[pallet::call_index(0)] + #[pallet::weight(T::WeightInfo::claim())] pub fn claim(origin: OriginFor, index: T::AccountIndex) -> DispatchResult { let who = ensure_signed(origin)?; @@ -117,6 +118,7 @@ pub mod pallet { /// ## Complexity /// - `O(1)`. #[pallet::call_index(1)] + #[pallet::weight(T::WeightInfo::transfer())] pub fn transfer( origin: OriginFor, new: AccountIdLookupOf, @@ -151,6 +153,7 @@ pub mod pallet { /// ## Complexity /// - `O(1)`. #[pallet::call_index(2)] + #[pallet::weight(T::WeightInfo::free())] pub fn free(origin: OriginFor, index: T::AccountIndex) -> DispatchResult { let who = ensure_signed(origin)?; @@ -179,6 +182,7 @@ pub mod pallet { /// ## Complexity /// - `O(1)`. #[pallet::call_index(3)] + #[pallet::weight(T::WeightInfo::force_transfer())] pub fn force_transfer( origin: OriginFor, new: AccountIdLookupOf, @@ -211,6 +215,7 @@ pub mod pallet { /// ## Complexity /// - `O(1)`. #[pallet::call_index(4)] + #[pallet::weight(T::WeightInfo::freeze())] pub fn freeze(origin: OriginFor, index: T::AccountIndex) -> DispatchResult { let who = ensure_signed(origin)?; diff --git a/frame/lottery/src/lib.rs b/frame/lottery/src/lib.rs index b17d40861e825..178f221a8946f 100644 --- a/frame/lottery/src/lib.rs +++ b/frame/lottery/src/lib.rs @@ -282,7 +282,7 @@ pub mod pallet { } } - #[pallet::call(weight = ::WeightInfo)] + #[pallet::call] impl Pallet { /// Buy a ticket to enter the lottery. /// @@ -346,6 +346,7 @@ pub mod pallet { /// * `delay`: How long after the lottery end we should wait before picking a winner. /// * `repeat`: If the lottery should repeat when completed. #[pallet::call_index(2)] + #[pallet::weight(T::WeightInfo::start_lottery())] pub fn start_lottery( origin: OriginFor, price: BalanceOf, @@ -378,6 +379,7 @@ pub mod pallet { /// /// This extrinsic must be called by the `ManagerOrigin`. #[pallet::call_index(3)] + #[pallet::weight(T::WeightInfo::stop_repeat())] pub fn stop_repeat(origin: OriginFor) -> DispatchResult { T::ManagerOrigin::ensure_origin(origin)?; Lottery::::mutate(|mut lottery| { diff --git a/frame/message-queue/src/lib.rs b/frame/message-queue/src/lib.rs index c08e7be90e2eb..c8e1976103ebf 100644 --- a/frame/message-queue/src/lib.rs +++ b/frame/message-queue/src/lib.rs @@ -576,10 +576,11 @@ pub mod pallet { } } - #[pallet::call(weight = ::WeightInfo)] + #[pallet::call] impl Pallet { /// Remove a page which has no more messages remaining to be processed or is stale. #[pallet::call_index(0)] + #[pallet::weight(T::WeightInfo::reap_page())] pub fn reap_page( origin: OriginFor, message_origin: MessageOriginOf, diff --git a/frame/nfts/src/lib.rs b/frame/nfts/src/lib.rs index 7d7f556ddf330..f4d0e41593476 100644 --- a/frame/nfts/src/lib.rs +++ b/frame/nfts/src/lib.rs @@ -639,7 +639,7 @@ pub mod pallet { CollectionNotEmpty, } - #[pallet::call(weight = >::WeightInfo)] + #[pallet::call] impl, I: 'static> Pallet { /// Issue a new collection of non-fungible items from a public origin. /// @@ -657,6 +657,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(0)] + #[pallet::weight(T::WeightInfo::create())] pub fn create( origin: OriginFor, admin: AccountIdLookupOf, @@ -700,6 +701,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(1)] + #[pallet::weight(T::WeightInfo::force_create())] pub fn force_create( origin: OriginFor, owner: AccountIdLookupOf, @@ -778,6 +780,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(3)] + #[pallet::weight(T::WeightInfo::mint())] pub fn mint( origin: OriginFor, collection: T::CollectionId, @@ -883,6 +886,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(4)] + #[pallet::weight(T::WeightInfo::force_mint())] pub fn force_mint( origin: OriginFor, collection: T::CollectionId, @@ -916,6 +920,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(5)] + #[pallet::weight(T::WeightInfo::burn())] pub fn burn( origin: OriginFor, collection: T::CollectionId, @@ -948,6 +953,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(6)] + #[pallet::weight(T::WeightInfo::transfer())] pub fn transfer( origin: OriginFor, collection: T::CollectionId, @@ -1048,6 +1054,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(8)] + #[pallet::weight(T::WeightInfo::lock_item_transfer())] pub fn lock_item_transfer( origin: OriginFor, collection: T::CollectionId, @@ -1068,6 +1075,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(9)] + #[pallet::weight(T::WeightInfo::unlock_item_transfer())] pub fn unlock_item_transfer( origin: OriginFor, collection: T::CollectionId, @@ -1090,6 +1098,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(10)] + #[pallet::weight(T::WeightInfo::lock_collection())] pub fn lock_collection( origin: OriginFor, collection: T::CollectionId, @@ -1111,6 +1120,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(11)] + #[pallet::weight(T::WeightInfo::transfer_ownership())] pub fn transfer_ownership( origin: OriginFor, collection: T::CollectionId, @@ -1138,6 +1148,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(12)] + #[pallet::weight(T::WeightInfo::set_team())] pub fn set_team( origin: OriginFor, collection: T::CollectionId, @@ -1165,6 +1176,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(13)] + #[pallet::weight(T::WeightInfo::force_collection_owner())] pub fn force_collection_owner( origin: OriginFor, collection: T::CollectionId, @@ -1186,6 +1198,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(14)] + #[pallet::weight(T::WeightInfo::force_collection_config())] pub fn force_collection_config( origin: OriginFor, collection: T::CollectionId, @@ -1210,6 +1223,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(15)] + #[pallet::weight(T::WeightInfo::approve_transfer())] pub fn approve_transfer( origin: OriginFor, collection: T::CollectionId, @@ -1245,6 +1259,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(16)] + #[pallet::weight(T::WeightInfo::cancel_approval())] pub fn cancel_approval( origin: OriginFor, collection: T::CollectionId, @@ -1272,6 +1287,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(17)] + #[pallet::weight(T::WeightInfo::clear_all_transfer_approvals())] pub fn clear_all_transfer_approvals( origin: OriginFor, collection: T::CollectionId, @@ -1301,6 +1317,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(18)] + #[pallet::weight(T::WeightInfo::lock_item_properties())] pub fn lock_item_properties( origin: OriginFor, collection: T::CollectionId, @@ -1343,6 +1360,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(19)] + #[pallet::weight(T::WeightInfo::set_attribute())] pub fn set_attribute( origin: OriginFor, collection: T::CollectionId, @@ -1378,6 +1396,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(20)] + #[pallet::weight(T::WeightInfo::force_set_attribute())] pub fn force_set_attribute( origin: OriginFor, set_as: Option, @@ -1407,6 +1426,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(21)] + #[pallet::weight(T::WeightInfo::clear_attribute())] pub fn clear_attribute( origin: OriginFor, collection: T::CollectionId, @@ -1430,6 +1450,7 @@ pub mod pallet { /// /// Emits `ItemAttributesApprovalAdded` on success. #[pallet::call_index(22)] + #[pallet::weight(T::WeightInfo::approve_item_attributes())] pub fn approve_item_attributes( origin: OriginFor, collection: T::CollectionId, @@ -1484,6 +1505,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(24)] + #[pallet::weight(T::WeightInfo::set_metadata())] pub fn set_metadata( origin: OriginFor, collection: T::CollectionId, @@ -1510,6 +1532,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(25)] + #[pallet::weight(T::WeightInfo::clear_metadata())] pub fn clear_metadata( origin: OriginFor, collection: T::CollectionId, @@ -1537,6 +1560,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(26)] + #[pallet::weight(T::WeightInfo::set_collection_metadata())] pub fn set_collection_metadata( origin: OriginFor, collection: T::CollectionId, @@ -1561,6 +1585,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(27)] + #[pallet::weight(T::WeightInfo::clear_collection_metadata())] pub fn clear_collection_metadata( origin: OriginFor, collection: T::CollectionId, @@ -1582,6 +1607,7 @@ pub mod pallet { /// /// Emits `OwnershipAcceptanceChanged`. #[pallet::call_index(28)] + #[pallet::weight(T::WeightInfo::set_accept_ownership())] pub fn set_accept_ownership( origin: OriginFor, maybe_collection: Option, @@ -1600,6 +1626,7 @@ pub mod pallet { /// /// Emits `CollectionMaxSupplySet` event when successful. #[pallet::call_index(29)] + #[pallet::weight(T::WeightInfo::set_collection_max_supply())] pub fn set_collection_max_supply( origin: OriginFor, collection: T::CollectionId, @@ -1621,6 +1648,7 @@ pub mod pallet { /// /// Emits `CollectionMintSettingsUpdated` event when successful. #[pallet::call_index(30)] + #[pallet::weight(T::WeightInfo::update_mint_settings())] pub fn update_mint_settings( origin: OriginFor, collection: T::CollectionId, @@ -1648,6 +1676,7 @@ pub mod pallet { /// Emits `ItemPriceSet` on success if the price is not `None`. /// Emits `ItemPriceRemoved` on success if the price is `None`. #[pallet::call_index(31)] + #[pallet::weight(T::WeightInfo::set_price())] pub fn set_price( origin: OriginFor, collection: T::CollectionId, @@ -1670,6 +1699,7 @@ pub mod pallet { /// /// Emits `ItemBought` on success. #[pallet::call_index(32)] + #[pallet::weight(T::WeightInfo::buy_item())] pub fn buy_item( origin: OriginFor, collection: T::CollectionId, @@ -1714,6 +1744,7 @@ pub mod pallet { /// /// Emits `SwapCreated` on success. #[pallet::call_index(34)] + #[pallet::weight(T::WeightInfo::create_swap())] pub fn create_swap( origin: OriginFor, offered_collection: T::CollectionId, @@ -1745,6 +1776,7 @@ pub mod pallet { /// /// Emits `SwapCancelled` on success. #[pallet::call_index(35)] + #[pallet::weight(T::WeightInfo::cancel_swap())] pub fn cancel_swap( origin: OriginFor, offered_collection: T::CollectionId, @@ -1767,6 +1799,7 @@ pub mod pallet { /// /// Emits `SwapClaimed` on success. #[pallet::call_index(36)] + #[pallet::weight(T::WeightInfo::claim_swap())] pub fn claim_swap( origin: OriginFor, send_collection: T::CollectionId, diff --git a/frame/nis/src/lib.rs b/frame/nis/src/lib.rs index c420d275ea7d0..c4d0d0d420290 100644 --- a/frame/nis/src/lib.rs +++ b/frame/nis/src/lib.rs @@ -537,7 +537,7 @@ pub mod pallet { } } - #[pallet::call(weight = ::WeightInfo)] + #[pallet::call] impl Pallet { /// Place a bid. /// @@ -655,6 +655,7 @@ pub mod pallet { /// /// - `origin`: Must be accepted by `FundOrigin`. #[pallet::call_index(2)] + #[pallet::weight(T::WeightInfo::fund_deficit())] pub fn fund_deficit(origin: OriginFor) -> DispatchResult { T::FundOrigin::ensure_origin(origin)?; let summary: SummaryRecordOf = Summary::::get(); @@ -676,6 +677,7 @@ pub mod pallet { /// - `portion`: If `Some`, then only the given portion of the receipt should be thawed. If /// `None`, then all of it should be. #[pallet::call_index(3)] + #[pallet::weight(T::WeightInfo::thaw_private())] pub fn thaw_private( origin: OriginFor, #[pallet::compact] index: ReceiptIndex, @@ -781,6 +783,7 @@ pub mod pallet { /// for receipt `index`. /// - `index`: The index of the receipt. #[pallet::call_index(4)] + #[pallet::weight(T::WeightInfo::thaw_communal())] pub fn thaw_communal( origin: OriginFor, #[pallet::compact] index: ReceiptIndex, @@ -831,6 +834,7 @@ pub mod pallet { /// Make a private receipt communal and create fungible counterparts for its owner. #[pallet::call_index(5)] + #[pallet::weight(T::WeightInfo::communify())] pub fn communify( origin: OriginFor, #[pallet::compact] index: ReceiptIndex, @@ -868,6 +872,7 @@ pub mod pallet { /// Make a communal receipt private and burn fungible counterparts from its owner. #[pallet::call_index(6)] + #[pallet::weight(T::WeightInfo::privatize())] pub fn privatize( origin: OriginFor, #[pallet::compact] index: ReceiptIndex, diff --git a/frame/node-authorization/src/lib.rs b/frame/node-authorization/src/lib.rs index 27cca7e9433ac..eaeda3cade9e9 100644 --- a/frame/node-authorization/src/lib.rs +++ b/frame/node-authorization/src/lib.rs @@ -201,7 +201,7 @@ pub mod pallet { } } - #[pallet::call(weight = ::WeightInfo)] + #[pallet::call] impl Pallet { /// Add a node to the set of well known nodes. If the node is already claimed, the owner /// will be updated and keep the existing additional connection unchanged. @@ -322,6 +322,7 @@ pub mod pallet { /// /// - `node`: identifier of the node. #[pallet::call_index(4)] + #[pallet::weight(T::WeightInfo::claim_node())] pub fn claim_node(origin: OriginFor, node: PeerId) -> DispatchResult { let sender = ensure_signed(origin)?; @@ -339,6 +340,7 @@ pub mod pallet { /// /// - `node`: identifier of the node. #[pallet::call_index(5)] + #[pallet::weight(T::WeightInfo::remove_claim())] pub fn remove_claim(origin: OriginFor, node: PeerId) -> DispatchResult { let sender = ensure_signed(origin)?; @@ -359,6 +361,7 @@ pub mod pallet { /// - `node`: identifier of the node. /// - `owner`: new owner of the node. #[pallet::call_index(6)] + #[pallet::weight(T::WeightInfo::transfer_node())] pub fn transfer_node( origin: OriginFor, node: PeerId, @@ -382,6 +385,7 @@ pub mod pallet { /// - `node`: identifier of the node. /// - `connections`: additonal nodes from which the connections are allowed. #[pallet::call_index(7)] + #[pallet::weight(T::WeightInfo::add_connections())] pub fn add_connections( origin: OriginFor, node: PeerId, @@ -416,6 +420,7 @@ pub mod pallet { /// - `node`: identifier of the node. /// - `connections`: additonal nodes from which the connections are not allowed anymore. #[pallet::call_index(8)] + #[pallet::weight(T::WeightInfo::remove_connections())] pub fn remove_connections( origin: OriginFor, node: PeerId, diff --git a/frame/nomination-pools/src/lib.rs b/frame/nomination-pools/src/lib.rs index d10ecf21e75ee..78f0c730ce5dd 100644 --- a/frame/nomination-pools/src/lib.rs +++ b/frame/nomination-pools/src/lib.rs @@ -1859,7 +1859,7 @@ pub mod pallet { } } - #[pallet::call(weight = ::WeightInfo)] + #[pallet::call] impl Pallet { /// Stake funds with a pool. The amount to bond is transferred from the member to the /// pools account and immediately increases the pools bond. @@ -1872,6 +1872,7 @@ pub mod pallet { /// `existential deposit + amount` in their account. /// * Only a pool with [`PoolState::Open`] can be joined #[pallet::call_index(0)] + #[pallet::weight(T::WeightInfo::join())] pub fn join( origin: OriginFor, #[pallet::compact] amount: BalanceOf, @@ -1952,6 +1953,7 @@ pub mod pallet { /// /// See `claim_payout_other` to caim rewards on bahalf of some `other` pool member. #[pallet::call_index(2)] + #[pallet::weight(T::WeightInfo::claim_payout())] pub fn claim_payout(origin: OriginFor) -> DispatchResult { let signer = ensure_signed(origin)?; Self::do_claim_payout(signer.clone(), signer) @@ -1989,6 +1991,7 @@ pub mod pallet { /// in which case, the result of this call will likely be the `NoMoreChunks` error from the /// staking system. #[pallet::call_index(3)] + #[pallet::weight(T::WeightInfo::unbond())] pub fn unbond( origin: OriginFor, member_account: AccountIdLookupOf, @@ -2227,6 +2230,7 @@ pub mod pallet { /// In addition to `amount`, the caller will transfer the existential deposit; so the caller /// needs at have at least `amount + existential_deposit` transferrable. #[pallet::call_index(6)] + #[pallet::weight(T::WeightInfo::create())] pub fn create( origin: OriginFor, #[pallet::compact] amount: BalanceOf, @@ -2299,6 +2303,7 @@ pub mod pallet { /// 2. if the pool conditions to be open are NOT met (as described by `ok_to_be_open`), and /// then the state of the pool can be permissionlessly changed to `Destroying`. #[pallet::call_index(9)] + #[pallet::weight(T::WeightInfo::set_state())] pub fn set_state( origin: OriginFor, pool_id: PoolId, @@ -2360,6 +2365,7 @@ pub mod pallet { /// * `max_members_per_pool` - Set [`MaxPoolMembersPerPool`]. /// * `global_max_commission` - Set [`GlobalMaxCommission`]. #[pallet::call_index(11)] + #[pallet::weight(T::WeightInfo::set_configs())] pub fn set_configs( origin: OriginFor, min_join_bond: ConfigOp>, @@ -2398,6 +2404,7 @@ pub mod pallet { /// It emits an event, notifying UIs of the role change. This event is quite relevant to /// most pool members and they should be informed of changes to pool roles. #[pallet::call_index(12)] + #[pallet::weight(T::WeightInfo::update_roles())] pub fn update_roles( origin: OriginFor, pool_id: PoolId, @@ -2450,6 +2457,7 @@ pub mod pallet { /// This directly forward the call to the staking pallet, on behalf of the pool bonded /// account. #[pallet::call_index(13)] + #[pallet::weight(T::WeightInfo::chill())] pub fn chill(origin: OriginFor, pool_id: PoolId) -> DispatchResult { let who = ensure_signed(origin)?; let bonded_pool = BondedPool::::get(pool_id).ok_or(Error::::PoolNotFound)?; @@ -2525,6 +2533,7 @@ pub mod pallet { /// /// - If a `None` is supplied to `new_commission`, existing commission will be removed. #[pallet::call_index(17)] + #[pallet::weight(T::WeightInfo::set_commission())] pub fn set_commission( origin: OriginFor, pool_id: PoolId, @@ -2560,6 +2569,7 @@ pub mod pallet { /// - Current commission will be lowered in the event it is higher than a new max /// commission. #[pallet::call_index(18)] + #[pallet::weight(T::WeightInfo::set_commission_max())] pub fn set_commission_max( origin: OriginFor, pool_id: PoolId, @@ -2581,6 +2591,7 @@ pub mod pallet { /// Initial change rate is not bounded, whereas subsequent updates can only be more /// restrictive than the current. #[pallet::call_index(19)] + #[pallet::weight(T::WeightInfo::set_commission_change_rate())] pub fn set_commission_change_rate( origin: OriginFor, pool_id: PoolId, @@ -2606,6 +2617,7 @@ pub mod pallet { /// commission is paid out and added to total claimed commission`. Total pending commission /// is reset to zero. the current. #[pallet::call_index(20)] + #[pallet::weight(T::WeightInfo::claim_commission())] pub fn claim_commission(origin: OriginFor, pool_id: PoolId) -> DispatchResult { let who = ensure_signed(origin)?; Self::do_claim_commission(who, pool_id) diff --git a/frame/preimage/src/lib.rs b/frame/preimage/src/lib.rs index 354a4c66fb7c8..60208424db953 100644 --- a/frame/preimage/src/lib.rs +++ b/frame/preimage/src/lib.rs @@ -146,7 +146,7 @@ pub mod pallet { pub(super) type PreimageFor = StorageMap<_, Identity, (T::Hash, u32), BoundedVec>>; - #[pallet::call(weight = ::WeightInfo)] + #[pallet::call] impl Pallet { /// Register a preimage on-chain. /// @@ -173,6 +173,7 @@ pub mod pallet { /// - `hash`: The hash of the preimage to be removed from the store. /// - `len`: The length of the preimage of `hash`. #[pallet::call_index(1)] + #[pallet::weight(T::WeightInfo::unnote_preimage())] pub fn unnote_preimage(origin: OriginFor, hash: T::Hash) -> DispatchResult { let maybe_sender = Self::ensure_signed_or_manager(origin)?; Self::do_unnote_preimage(&hash, maybe_sender) @@ -183,6 +184,7 @@ pub mod pallet { /// If the preimage requests has already been provided on-chain, we unreserve any deposit /// a user may have paid, and take the control of the preimage out of their hands. #[pallet::call_index(2)] + #[pallet::weight(T::WeightInfo::request_preimage())] pub fn request_preimage(origin: OriginFor, hash: T::Hash) -> DispatchResult { T::ManagerOrigin::ensure_origin(origin)?; Self::do_request_preimage(&hash); @@ -193,6 +195,7 @@ pub mod pallet { /// /// NOTE: THIS MUST NOT BE CALLED ON `hash` MORE TIMES THAN `request_preimage`. #[pallet::call_index(3)] + #[pallet::weight(T::WeightInfo::unrequest_preimage())] pub fn unrequest_preimage(origin: OriginFor, hash: T::Hash) -> DispatchResult { T::ManagerOrigin::ensure_origin(origin)?; Self::do_unrequest_preimage(&hash) diff --git a/frame/ranked-collective/src/lib.rs b/frame/ranked-collective/src/lib.rs index f4ca9fe886482..288fd78d6e718 100644 --- a/frame/ranked-collective/src/lib.rs +++ b/frame/ranked-collective/src/lib.rs @@ -428,7 +428,7 @@ pub mod pallet { NoPermission, } - #[pallet::call(weight = >::WeightInfo)] + #[pallet::call] impl, I: 'static> Pallet { /// Introduce a new member. /// @@ -438,6 +438,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(0)] + #[pallet::weight(T::WeightInfo::add_member())] pub fn add_member(origin: OriginFor, who: AccountIdLookupOf) -> DispatchResult { let _ = T::PromoteOrigin::ensure_origin(origin)?; let who = T::Lookup::lookup(who)?; @@ -516,6 +517,7 @@ pub mod pallet { /// /// Weight: `O(1)`, less if there was no previous vote on the poll by the member. #[pallet::call_index(4)] + #[pallet::weight(T::WeightInfo::vote())] pub fn vote( origin: OriginFor, poll: PollIndexOf, diff --git a/frame/recovery/src/lib.rs b/frame/recovery/src/lib.rs index 9d671ef4c5bd2..d66b5725fd4f7 100644 --- a/frame/recovery/src/lib.rs +++ b/frame/recovery/src/lib.rs @@ -363,7 +363,7 @@ pub mod pallet { #[pallet::getter(fn proxy)] pub type Proxy = StorageMap<_, Blake2_128Concat, T::AccountId, T::AccountId>; - #[pallet::call(weight = ::WeightInfo)] + #[pallet::call] impl Pallet { /// Send a call through a recovered account. /// @@ -404,6 +404,7 @@ pub mod pallet { /// - `lost`: The "lost account" to be recovered. /// - `rescuer`: The "rescuer account" which can call as the lost account. #[pallet::call_index(1)] + #[pallet::weight(T::WeightInfo::set_recovered())] pub fn set_recovered( origin: OriginFor, lost: AccountIdLookupOf, @@ -490,6 +491,7 @@ pub mod pallet { /// - `account`: The lost account that you want to recover. This account needs to be /// recoverable (i.e. have a recovery configuration). #[pallet::call_index(3)] + #[pallet::weight(T::WeightInfo::initiate_recovery())] pub fn initiate_recovery( origin: OriginFor, account: AccountIdLookupOf, @@ -687,6 +689,7 @@ pub mod pallet { /// Parameters: /// - `account`: The recovered account you are able to call on-behalf-of. #[pallet::call_index(8)] + #[pallet::weight(T::WeightInfo::cancel_recovered())] pub fn cancel_recovered( origin: OriginFor, account: AccountIdLookupOf, diff --git a/frame/referenda/src/lib.rs b/frame/referenda/src/lib.rs index c34b90c98c756..68837376c5b33 100644 --- a/frame/referenda/src/lib.rs +++ b/frame/referenda/src/lib.rs @@ -411,7 +411,7 @@ pub mod pallet { PreimageNotExist, } - #[pallet::call(weight = >::WeightInfo)] + #[pallet::call] impl, I: 'static> Pallet { /// Propose a referendum on a privileged action. /// @@ -423,6 +423,7 @@ pub mod pallet { /// /// Emits `Submitted`. #[pallet::call_index(0)] + #[pallet::weight(T::WeightInfo::submit())] pub fn submit( origin: OriginFor, proposal_origin: Box>, @@ -498,6 +499,7 @@ pub mod pallet { /// /// Emits `DecisionDepositRefunded`. #[pallet::call_index(2)] + #[pallet::weight(T::WeightInfo::refund_decision_deposit())] pub fn refund_decision_deposit( origin: OriginFor, index: ReferendumIndex, @@ -527,6 +529,7 @@ pub mod pallet { /// /// Emits `Cancelled`. #[pallet::call_index(3)] + #[pallet::weight(T::WeightInfo::cancel())] pub fn cancel(origin: OriginFor, index: ReferendumIndex) -> DispatchResult { T::CancelOrigin::ensure_origin(origin)?; let status = Self::ensure_ongoing(index)?; @@ -551,6 +554,7 @@ pub mod pallet { /// /// Emits `Killed` and `DepositSlashed`. #[pallet::call_index(4)] + #[pallet::weight(T::WeightInfo::kill())] pub fn kill(origin: OriginFor, index: ReferendumIndex) -> DispatchResult { T::KillOrigin::ensure_origin(origin)?; let status = Self::ensure_ongoing(index)?; @@ -633,6 +637,7 @@ pub mod pallet { /// /// Emits `SubmissionDepositRefunded`. #[pallet::call_index(7)] + #[pallet::weight(T::WeightInfo::refund_submission_deposit())] pub fn refund_submission_deposit( origin: OriginFor, index: ReferendumIndex, diff --git a/frame/session/src/lib.rs b/frame/session/src/lib.rs index 174da2ed6af8b..a9f89412a71c4 100644 --- a/frame/session/src/lib.rs +++ b/frame/session/src/lib.rs @@ -578,7 +578,7 @@ pub mod pallet { } } - #[pallet::call(weight = ::WeightInfo)] + #[pallet::call] impl Pallet { /// Sets the session key(s) of the function caller to `keys`. /// Allows an account to set its session key prior to becoming a validator. @@ -590,6 +590,7 @@ pub mod pallet { /// - `O(1)`. Actual cost depends on the number of length of `T::Keys::key_ids()` which is /// fixed. #[pallet::call_index(0)] + #[pallet::weight(T::WeightInfo::set_keys())] pub fn set_keys(origin: OriginFor, keys: T::Keys, proof: Vec) -> DispatchResult { let who = ensure_signed(origin)?; ensure!(keys.ownership_proof_is_valid(&proof), Error::::InvalidProof); @@ -611,6 +612,7 @@ pub mod pallet { /// - `O(1)` in number of key types. Actual cost depends on the number of length of /// `T::Keys::key_ids()` which is fixed. #[pallet::call_index(1)] + #[pallet::weight(T::WeightInfo::purge_keys())] pub fn purge_keys(origin: OriginFor) -> DispatchResult { let who = ensure_signed(origin)?; Self::do_purge_keys(&who)?; diff --git a/frame/staking/src/pallet/mod.rs b/frame/staking/src/pallet/mod.rs index a37783182b5d5..d8f1855da4bc0 100644 --- a/frame/staking/src/pallet/mod.rs +++ b/frame/staking/src/pallet/mod.rs @@ -829,7 +829,7 @@ pub mod pallet { } } - #[pallet::call(weight = ::WeightInfo)] + #[pallet::call] impl Pallet { /// Take the origin account as a stash and lock up `value` of its balance. `controller` will /// be the account that controls it. @@ -847,6 +847,7 @@ pub mod pallet { /// NOTE: Two of the storage writes (`Self::bonded`, `Self::payee`) are _never_ cleaned /// unless the `origin` falls below _existential deposit_ and gets removed as dust. #[pallet::call_index(0)] + #[pallet::weight(T::WeightInfo::bond())] pub fn bond( origin: OriginFor, controller: AccountIdLookupOf, @@ -915,6 +916,7 @@ pub mod pallet { /// - Independent of the arguments. Insignificant complexity. /// - O(1). #[pallet::call_index(1)] + #[pallet::weight(T::WeightInfo::bond_extra())] pub fn bond_extra( origin: OriginFor, #[pallet::compact] max_additional: BalanceOf, @@ -1091,6 +1093,7 @@ pub mod pallet { /// /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. #[pallet::call_index(4)] + #[pallet::weight(T::WeightInfo::validate())] pub fn validate(origin: OriginFor, prefs: ValidatorPrefs) -> DispatchResult { let controller = ensure_signed(origin)?; @@ -1201,6 +1204,7 @@ pub mod pallet { /// - Contains one read. /// - Writes are limited to the `origin` account key. #[pallet::call_index(6)] + #[pallet::weight(T::WeightInfo::chill())] pub fn chill(origin: OriginFor) -> DispatchResult { let controller = ensure_signed(origin)?; let ledger = Self::ledger(&controller).ok_or(Error::::NotController)?; @@ -1221,6 +1225,7 @@ pub mod pallet { /// - Writes are limited to the `origin` account key. /// --------- #[pallet::call_index(7)] + #[pallet::weight(T::WeightInfo::set_payee())] pub fn set_payee( origin: OriginFor, payee: RewardDestination, @@ -1244,6 +1249,7 @@ pub mod pallet { /// - Contains a limited number of reads. /// - Writes are limited to the `origin` account key. #[pallet::call_index(8)] + #[pallet::weight(T::WeightInfo::set_controller())] pub fn set_controller( origin: OriginFor, controller: AccountIdLookupOf, @@ -1270,6 +1276,7 @@ pub mod pallet { /// ## Complexity /// O(1) #[pallet::call_index(9)] + #[pallet::weight(T::WeightInfo::set_validator_count())] pub fn set_validator_count( origin: OriginFor, #[pallet::compact] new: u32, @@ -1347,6 +1354,7 @@ pub mod pallet { /// - No arguments. /// - Weight: O(1) #[pallet::call_index(12)] + #[pallet::weight(T::WeightInfo::force_no_eras())] pub fn force_no_eras(origin: OriginFor) -> DispatchResult { ensure_root(origin)?; Self::set_force_era(Forcing::ForceNone); @@ -1368,6 +1376,7 @@ pub mod pallet { /// - No arguments. /// - Weight: O(1) #[pallet::call_index(13)] + #[pallet::weight(T::WeightInfo::force_new_era())] pub fn force_new_era(origin: OriginFor) -> DispatchResult { ensure_root(origin)?; Self::set_force_era(Forcing::ForceNew); @@ -1418,6 +1427,7 @@ pub mod pallet { /// If this is called just before a new era is triggered, the election process may not /// have enough blocks to get a result. #[pallet::call_index(16)] + #[pallet::weight(T::WeightInfo::force_new_era_always())] pub fn force_new_era_always(origin: OriginFor) -> DispatchResult { ensure_root(origin)?; Self::set_force_era(Forcing::ForceAlways); @@ -1672,6 +1682,7 @@ pub mod pallet { /// This can be helpful if bond requirements are updated, and we need to remove old users /// who do not satisfy these requirements. #[pallet::call_index(23)] + #[pallet::weight(T::WeightInfo::chill_other())] pub fn chill_other(origin: OriginFor, controller: T::AccountId) -> DispatchResult { // Anyone can call this function. let caller = ensure_signed(origin)?; @@ -1734,6 +1745,7 @@ pub mod pallet { /// validator who already has a commission greater than or equal to the minimum. Any account /// can call this. #[pallet::call_index(24)] + #[pallet::weight(T::WeightInfo::force_apply_min_commission())] pub fn force_apply_min_commission( origin: OriginFor, validator_stash: T::AccountId, @@ -1757,6 +1769,7 @@ pub mod pallet { /// This call has lower privilege requirements than `set_staking_config` and can be called /// by the `T::AdminOrigin`. Root can always call this. #[pallet::call_index(25)] + #[pallet::weight(T::WeightInfo::set_min_commission())] pub fn set_min_commission(origin: OriginFor, new: Perbill) -> DispatchResult { T::AdminOrigin::ensure_origin(origin)?; MinCommission::::put(new); diff --git a/frame/transaction-storage/src/lib.rs b/frame/transaction-storage/src/lib.rs index a519a63a318a0..59662ee860541 100644 --- a/frame/transaction-storage/src/lib.rs +++ b/frame/transaction-storage/src/lib.rs @@ -179,7 +179,7 @@ pub mod pallet { } } - #[pallet::call(weight = ::WeightInfo)] + #[pallet::call] impl Pallet { /// Index and store data off chain. Minimum data size is 1 bytes, maximum is /// `MaxTransactionSize`. Data will be removed after `STORAGE_PERIOD` blocks, unless `renew` @@ -235,6 +235,7 @@ pub mod pallet { /// ## Complexity /// - O(1). #[pallet::call_index(1)] + #[pallet::weight(T::WeightInfo::renew())] pub fn renew( origin: OriginFor, block: T::BlockNumber, diff --git a/frame/treasury/src/lib.rs b/frame/treasury/src/lib.rs index 25eab73f486f1..450aee51f2ce8 100644 --- a/frame/treasury/src/lib.rs +++ b/frame/treasury/src/lib.rs @@ -343,7 +343,7 @@ pub mod pallet { spend_in_context: BTreeMap, } - #[pallet::call(weight = >::WeightInfo)] + #[pallet::call] impl, I: 'static> Pallet { /// Put forward a suggestion for spending. A deposit proportional to the value /// is reserved and slashed if the proposal is rejected. It is returned once the @@ -352,6 +352,7 @@ pub mod pallet { /// ## Complexity /// - O(1) #[pallet::call_index(0)] + #[pallet::weight(T::WeightInfo::propose_spend())] pub fn propose_spend( origin: OriginFor, #[pallet::compact] value: BalanceOf, @@ -429,6 +430,7 @@ pub mod pallet { /// NOTE: For record-keeping purposes, the proposer is deemed to be equivalent to the /// beneficiary. #[pallet::call_index(3)] + #[pallet::weight(T::WeightInfo::spend())] pub fn spend( origin: OriginFor, #[pallet::compact] amount: BalanceOf, diff --git a/frame/uniques/src/lib.rs b/frame/uniques/src/lib.rs index 0aeb8090047c5..fd94bd3a9a7e4 100644 --- a/frame/uniques/src/lib.rs +++ b/frame/uniques/src/lib.rs @@ -432,7 +432,7 @@ pub mod pallet { } } - #[pallet::call(weight = >::WeightInfo)] + #[pallet::call] impl, I: 'static> Pallet { /// Issue a new collection of non-fungible items from a public origin. /// @@ -451,6 +451,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(0)] + #[pallet::weight(T::WeightInfo::create())] pub fn create( origin: OriginFor, collection: T::CollectionId, @@ -487,6 +488,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(1)] + #[pallet::weight(T::WeightInfo::force_create())] pub fn force_create( origin: OriginFor, collection: T::CollectionId, @@ -558,6 +560,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(3)] + #[pallet::weight(T::WeightInfo::mint())] pub fn mint( origin: OriginFor, collection: T::CollectionId, @@ -589,6 +592,7 @@ pub mod pallet { /// Weight: `O(1)` /// Modes: `check_owner.is_some()`. #[pallet::call_index(4)] + #[pallet::weight(T::WeightInfo::burn())] pub fn burn( origin: OriginFor, collection: T::CollectionId, @@ -627,6 +631,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(5)] + #[pallet::weight(T::WeightInfo::transfer())] pub fn transfer( origin: OriginFor, collection: T::CollectionId, @@ -724,6 +729,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(7)] + #[pallet::weight(T::WeightInfo::freeze())] pub fn freeze( origin: OriginFor, collection: T::CollectionId, @@ -755,6 +761,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(8)] + #[pallet::weight(T::WeightInfo::thaw())] pub fn thaw( origin: OriginFor, collection: T::CollectionId, @@ -785,6 +792,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(9)] + #[pallet::weight(T::WeightInfo::freeze_collection())] pub fn freeze_collection( origin: OriginFor, collection: T::CollectionId, @@ -812,6 +820,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(10)] + #[pallet::weight(T::WeightInfo::thaw_collection())] pub fn thaw_collection( origin: OriginFor, collection: T::CollectionId, @@ -841,6 +850,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(11)] + #[pallet::weight(T::WeightInfo::transfer_ownership())] pub fn transfer_ownership( origin: OriginFor, collection: T::CollectionId, @@ -889,6 +899,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(12)] + #[pallet::weight(T::WeightInfo::set_team())] pub fn set_team( origin: OriginFor, collection: T::CollectionId, @@ -929,6 +940,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(13)] + #[pallet::weight(T::WeightInfo::approve_transfer())] pub fn approve_transfer( origin: OriginFor, collection: T::CollectionId, @@ -982,6 +994,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(14)] + #[pallet::weight(T::WeightInfo::cancel_approval())] pub fn cancel_approval( origin: OriginFor, collection: T::CollectionId, @@ -1034,6 +1047,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(15)] + #[pallet::weight(T::WeightInfo::force_item_status())] pub fn force_item_status( origin: OriginFor, collection: T::CollectionId, @@ -1083,6 +1097,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(16)] + #[pallet::weight(T::WeightInfo::set_attribute())] pub fn set_attribute( origin: OriginFor, collection: T::CollectionId, @@ -1145,6 +1160,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(17)] + #[pallet::weight(T::WeightInfo::clear_attribute())] pub fn clear_attribute( origin: OriginFor, collection: T::CollectionId, @@ -1194,6 +1210,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(18)] + #[pallet::weight(T::WeightInfo::set_metadata())] pub fn set_metadata( origin: OriginFor, collection: T::CollectionId, @@ -1256,6 +1273,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(19)] + #[pallet::weight(T::WeightInfo::clear_metadata())] pub fn clear_metadata( origin: OriginFor, collection: T::CollectionId, @@ -1305,6 +1323,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(20)] + #[pallet::weight(T::WeightInfo::set_collection_metadata())] pub fn set_collection_metadata( origin: OriginFor, collection: T::CollectionId, @@ -1362,6 +1381,7 @@ pub mod pallet { /// /// Weight: `O(1)` #[pallet::call_index(21)] + #[pallet::weight(T::WeightInfo::clear_collection_metadata())] pub fn clear_collection_metadata( origin: OriginFor, collection: T::CollectionId, @@ -1398,6 +1418,7 @@ pub mod pallet { /// /// Emits `OwnershipAcceptanceChanged`. #[pallet::call_index(22)] + #[pallet::weight(T::WeightInfo::set_accept_ownership())] pub fn set_accept_ownership( origin: OriginFor, maybe_collection: Option, @@ -1434,6 +1455,7 @@ pub mod pallet { /// /// Emits `CollectionMaxSupplySet` event when successful. #[pallet::call_index(23)] + #[pallet::weight(T::WeightInfo::set_collection_max_supply())] pub fn set_collection_max_supply( origin: OriginFor, collection: T::CollectionId, @@ -1473,6 +1495,7 @@ pub mod pallet { /// Emits `ItemPriceSet` on success if the price is not `None`. /// Emits `ItemPriceRemoved` on success if the price is `None`. #[pallet::call_index(24)] + #[pallet::weight(T::WeightInfo::set_price())] pub fn set_price( origin: OriginFor, collection: T::CollectionId, diff --git a/frame/whitelist/src/lib.rs b/frame/whitelist/src/lib.rs index 08828293e7551..decf010b06757 100644 --- a/frame/whitelist/src/lib.rs +++ b/frame/whitelist/src/lib.rs @@ -116,9 +116,10 @@ pub mod pallet { pub type WhitelistedCall = StorageMap<_, Twox64Concat, PreimageHash, (), OptionQuery>; - #[pallet::call(weight = ::WeightInfo)] + #[pallet::call] impl Pallet { #[pallet::call_index(0)] + #[pallet::weight(T::WeightInfo::whitelist_call())] pub fn whitelist_call(origin: OriginFor, call_hash: PreimageHash) -> DispatchResult { T::WhitelistOrigin::ensure_origin(origin)?; @@ -136,6 +137,7 @@ pub mod pallet { } #[pallet::call_index(1)] + #[pallet::weight(T::WeightInfo::remove_whitelisted_call())] pub fn remove_whitelisted_call( origin: OriginFor, call_hash: PreimageHash, From 191b7390f37c03cdd29dba36d0d8701130475af4 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Wed, 19 Apr 2023 17:29:13 +0200 Subject: [PATCH 11/17] Renames Signed-off-by: Oliver Tale-Yazdi --- .../procedural/src/pallet/expand/call.rs | 2 +- .../support/procedural/src/pallet/parse/call.rs | 17 ++++++++++------- .../support/procedural/src/pallet/parse/mod.rs | 8 ++++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/frame/support/procedural/src/pallet/expand/call.rs b/frame/support/procedural/src/pallet/expand/call.rs index 6fd9f2bdc5aec..71774c51e7d60 100644 --- a/frame/support/procedural/src/pallet/expand/call.rs +++ b/frame/support/procedural/src/pallet/expand/call.rs @@ -102,7 +102,7 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream { .call .as_ref() .expect("we have methods; we have calls; qed") - .call_weight + .inherited_call_weight .as_ref() .expect("the parser prevents this"); diff --git a/frame/support/procedural/src/pallet/parse/call.rs b/frame/support/procedural/src/pallet/parse/call.rs index fecbbec14053e..a5c99b1bf351e 100644 --- a/frame/support/procedural/src/pallet/parse/call.rs +++ b/frame/support/procedural/src/pallet/parse/call.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use super::{helper, RuntimeCallWeightAttr}; +use super::{helper, InheritedCallWeightAttr}; use frame_support_procedural_tools::get_doc_literals; use quote::ToTokens; use std::collections::HashMap; @@ -46,15 +46,18 @@ pub struct CallDef { pub attr_span: proc_macro2::Span, /// Docs, specified on the impl Block. pub docs: Vec, - pub call_weight: Option, + /// The optional `weight` attribute on the `pallet::call`. + pub inherited_call_weight: Option, } +/// The weight of a call. #[derive(Clone)] pub enum CallWeightDef { + /// Explicitly set on the call itself with `#[pallet::weight(…)]`. This value is used. + Immediate(syn::Expr), + /// The default value that should be set for dev-mode pallets. Usually zero. DevModeDefault, - /// Explicitly set on the call itself. This value is used. - Immediate(syn::Expr), /// Inherits whatever value is configured on the pallet level. /// @@ -165,7 +168,7 @@ impl CallDef { index: usize, item: &mut syn::Item, dev_mode: bool, - pallet_call_weight: Option, + inherited_call_weight: Option, ) -> syn::Result { let item_impl = if let syn::Item::Impl(item) = item { item @@ -244,7 +247,7 @@ impl CallDef { } let weight = match weight_attrs.len() { - 0 if pallet_call_weight.is_some() => CallWeightDef::Inherited, + 0 if inherited_call_weight.is_some() => CallWeightDef::Inherited, 0 if dev_mode => CallWeightDef::DevModeDefault, 0 => return Err(syn::Error::new( method.sig.span(), @@ -340,7 +343,7 @@ impl CallDef { methods, where_clause: item_impl.generics.where_clause.clone(), docs: get_doc_literals(&item_impl.attrs), - call_weight: pallet_call_weight, + inherited_call_weight, }) } } diff --git a/frame/support/procedural/src/pallet/parse/mod.rs b/frame/support/procedural/src/pallet/parse/mod.rs index 8fd4312e21a0e..f07d8b666d5d6 100644 --- a/frame/support/procedural/src/pallet/parse/mod.rs +++ b/frame/support/procedural/src/pallet/parse/mod.rs @@ -456,7 +456,7 @@ enum PalletAttr { /// call - if there is no `weight` attribute set on the call. This works together with /// instanced pallets by using `Config`. This attribute takes precedence over the default /// weight if the pallet is in dev-mode. - RuntimeCall(Option, proc_macro2::Span), + RuntimeCall(Option, proc_macro2::Span), Error(proc_macro2::Span), RuntimeEvent(proc_macro2::Span), RuntimeOrigin(proc_macro2::Span), @@ -511,7 +511,7 @@ impl syn::parse::Parse for PalletAttr { let span = content.parse::().expect("peeked").span(); let attr = match content.is_empty() { true => None, - false => Some(RuntimeCallWeightAttr::parse(&content)?), + false => Some(InheritedCallWeightAttr::parse(&content)?), }; Ok(PalletAttr::RuntimeCall(attr, span)) } else if lookahead.peek(keyword::error) { @@ -544,12 +544,12 @@ impl syn::parse::Parse for PalletAttr { /// The optional weight annotation on a `#[pallet::call]` like `#[pallet::call(weight($type))]`. #[derive(Clone)] -pub struct RuntimeCallWeightAttr { +pub struct InheritedCallWeightAttr { pub typename: syn::Type, pub span: proc_macro2::Span, } -impl syn::parse::Parse for RuntimeCallWeightAttr { +impl syn::parse::Parse for InheritedCallWeightAttr { // Parses `(weight($type))` or `(weight = $type)`. fn parse(input: syn::parse::ParseStream) -> syn::Result { let content; From 8edf2330ee79263000e32090a9cd66e9080e6350 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Thu, 20 Apr 2023 22:27:55 +0200 Subject: [PATCH 12/17] Review fixes Co-authored-by: Sam Johnson Signed-off-by: Oliver Tale-Yazdi --- frame/support/procedural/src/pallet/expand/call.rs | 6 ++---- frame/support/procedural/src/pallet/parse/call.rs | 4 +++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frame/support/procedural/src/pallet/expand/call.rs b/frame/support/procedural/src/pallet/expand/call.rs index 71774c51e7d60..f17fdc81a647c 100644 --- a/frame/support/procedural/src/pallet/expand/call.rs +++ b/frame/support/procedural/src/pallet/expand/call.rs @@ -80,11 +80,9 @@ pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream { let mut fn_weight = Vec::::new(); let mut weight_warnings = Vec::new(); - for method in methods.iter() { + for method in &methods { match &method.weight { - CallWeightDef::DevModeDefault => { - fn_weight.push(syn::parse_quote!(0)); - }, + CallWeightDef::DevModeDefault => fn_weight.push(syn::parse_quote!(0)), CallWeightDef::Immediate(e @ syn::Expr::Lit(lit)) if !def.dev_mode => { let warning = proc_macro_warning::Warning::new_deprecated("ConstantWeight") .index(weight_warnings.len()) diff --git a/frame/support/procedural/src/pallet/parse/call.rs b/frame/support/procedural/src/pallet/parse/call.rs index a5c99b1bf351e..90631f264b92a 100644 --- a/frame/support/procedural/src/pallet/parse/call.rs +++ b/frame/support/procedural/src/pallet/parse/call.rs @@ -251,7 +251,9 @@ impl CallDef { 0 if dev_mode => CallWeightDef::DevModeDefault, 0 => return Err(syn::Error::new( method.sig.span(), - "A pallet::call requires either a concrete `#[pallet::weight($expr)]` or an inherited weight from the `#[pallet:call(weight($type))]` attribute, but none were given.", + "A pallet::call requires either a concrete `#[pallet::weight($expr)]` or an + inherited weight from the `#[pallet:call(weight($type))]` attribute, but + none were given.", )), 1 => match weight_attrs.pop().unwrap() { FunctionAttr::Weight(w) => CallWeightDef::Immediate(w), From 8ba1c704e9543dc904faa6bca9581b93829d55a4 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Tue, 25 Apr 2023 17:47:00 +0200 Subject: [PATCH 13/17] Test weights Signed-off-by: Oliver Tale-Yazdi --- frame/alliance/src/tests.rs | 9 +++++++++ frame/assets/src/tests.rs | 10 ++++++++++ frame/balances/src/tests/mod.rs | 11 ++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/frame/alliance/src/tests.rs b/frame/alliance/src/tests.rs index 5942595469d5f..de7cda4710fc7 100644 --- a/frame/alliance/src/tests.rs +++ b/frame/alliance/src/tests.rs @@ -629,3 +629,12 @@ fn remove_unscrupulous_items_works() { assert_eq!(Alliance::unscrupulous_accounts(), Vec::::new()); }); } + +#[test] +fn weights_sane() { + let info = crate::Call::::join_alliance {}.get_dispatch_info(); + assert_eq!(<() as crate::WeightInfo>::join_alliance(), info.weight); + + let info = crate::Call::::nominate_ally { who: 10 }.get_dispatch_info(); + assert_eq!(<() as crate::WeightInfo>::nominate_ally(), info.weight); +} diff --git a/frame/assets/src/tests.rs b/frame/assets/src/tests.rs index afd224ad66642..83324dd75487e 100644 --- a/frame/assets/src/tests.rs +++ b/frame/assets/src/tests.rs @@ -21,6 +21,7 @@ use super::*; use crate::{mock::*, Error}; use frame_support::{ assert_noop, assert_ok, + dispatch::GetDispatchInfo, traits::{fungibles::InspectEnumerable, Currency}, }; use pallet_balances::Error as BalancesError; @@ -1322,3 +1323,12 @@ fn asset_create_and_destroy_is_reverted_if_callback_fails() { ); }); } + +#[test] +fn weights_sane() { + let info = crate::Call::::create { id: 10, admin: 4, min_balance: 3 }.get_dispatch_info(); + assert_eq!(<() as crate::WeightInfo>::create(), info.weight); + + let info = crate::Call::::finish_destroy { id: 10 }.get_dispatch_info(); + assert_eq!(<() as crate::WeightInfo>::finish_destroy(), info.weight); +} diff --git a/frame/balances/src/tests/mod.rs b/frame/balances/src/tests/mod.rs index 68e7e82035b0e..9b451f36d1d94 100644 --- a/frame/balances/src/tests/mod.rs +++ b/frame/balances/src/tests/mod.rs @@ -23,7 +23,7 @@ use crate::{self as pallet_balances, AccountData, Config, CreditOf, Error, Palle use codec::{Decode, Encode, MaxEncodedLen}; use frame_support::{ assert_err, assert_noop, assert_ok, assert_storage_noop, - dispatch::DispatchInfo, + dispatch::{DispatchInfo, GetDispatchInfo}, parameter_types, traits::{ tokens::fungible, ConstU32, ConstU64, ConstU8, Imbalance as ImbalanceT, OnUnbalanced, @@ -294,3 +294,12 @@ pub fn events() -> Vec { pub fn info_from_weight(w: Weight) -> DispatchInfo { DispatchInfo { weight: w, ..Default::default() } } + +#[test] +fn weights_sane() { + let info = crate::Call::::transfer_allow_death { dest: 10, value: 4 }.get_dispatch_info(); + assert_eq!(<() as crate::WeightInfo>::transfer_allow_death(), info.weight); + + let info = crate::Call::::force_unreserve { who: 10, amount: 4 }.get_dispatch_info(); + assert_eq!(<() as crate::WeightInfo>::force_unreserve(), info.weight); +} From bc847b05823b542baa4742b47d4fdd7f9c081762 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Tue, 25 Apr 2023 17:49:57 +0200 Subject: [PATCH 14/17] Update UI tests Signed-off-by: Oliver Tale-Yazdi --- frame/support/test/tests/pallet_ui/call_missing_weight.stderr | 4 +++- .../support/test/tests/pallet_ui/dev_mode_without_arg.stderr | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/frame/support/test/tests/pallet_ui/call_missing_weight.stderr b/frame/support/test/tests/pallet_ui/call_missing_weight.stderr index 2dd6c49df568b..0a6cf16571f95 100644 --- a/frame/support/test/tests/pallet_ui/call_missing_weight.stderr +++ b/frame/support/test/tests/pallet_ui/call_missing_weight.stderr @@ -1,4 +1,6 @@ -error: A pallet::call requires either a concrete `#[pallet::weight($expr)]` or an inherited weight from the `#[pallet:call(weight($type))]` attribute, but none were given. +error: A pallet::call requires either a concrete `#[pallet::weight($expr)]` or an + inherited weight from the `#[pallet:call(weight($type))]` attribute, but + none were given. --> tests/pallet_ui/call_missing_weight.rs:17:7 | 17 | pub fn foo(origin: OriginFor) -> DispatchResultWithPostInfo {} diff --git a/frame/support/test/tests/pallet_ui/dev_mode_without_arg.stderr b/frame/support/test/tests/pallet_ui/dev_mode_without_arg.stderr index 800def65f6bde..1e2011b2a30cf 100644 --- a/frame/support/test/tests/pallet_ui/dev_mode_without_arg.stderr +++ b/frame/support/test/tests/pallet_ui/dev_mode_without_arg.stderr @@ -1,4 +1,6 @@ -error: A pallet::call requires either a concrete `#[pallet::weight($expr)]` or an inherited weight from the `#[pallet:call(weight($type))]` attribute, but none were given. +error: A pallet::call requires either a concrete `#[pallet::weight($expr)]` or an + inherited weight from the `#[pallet:call(weight($type))]` attribute, but + none were given. --> tests/pallet_ui/dev_mode_without_arg.rs:22:7 | 22 | pub fn my_call(_origin: OriginFor) -> DispatchResult { From 37d347fd99efa1840c92f03730917f8c116d85c6 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Wed, 26 Apr 2023 17:50:10 +0200 Subject: [PATCH 15/17] Update frame/support/procedural/src/pallet/parse/mod.rs Co-authored-by: Muharem Ismailov --- frame/support/procedural/src/pallet/parse/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/frame/support/procedural/src/pallet/parse/mod.rs b/frame/support/procedural/src/pallet/parse/mod.rs index f07d8b666d5d6..3e4498626e512 100644 --- a/frame/support/procedural/src/pallet/parse/mod.rs +++ b/frame/support/procedural/src/pallet/parse/mod.rs @@ -403,7 +403,6 @@ mod keyword { syn::custom_keyword!(origin); syn::custom_keyword!(call); syn::custom_keyword!(weight); - syn::custom_keyword!(prefix); syn::custom_keyword!(event); syn::custom_keyword!(config); syn::custom_keyword!(hooks); From 7d9f78f16b76256c7148a23fe89096d35feb8fe2 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Wed, 26 Apr 2023 17:50:54 +0200 Subject: [PATCH 16/17] Remove old code Signed-off-by: Oliver Tale-Yazdi --- frame/support/procedural/src/pallet/parse/pallet_struct.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/frame/support/procedural/src/pallet/parse/pallet_struct.rs b/frame/support/procedural/src/pallet/parse/pallet_struct.rs index 122ec4eeaf4e3..f4af86aa3e993 100644 --- a/frame/support/procedural/src/pallet/parse/pallet_struct.rs +++ b/frame/support/procedural/src/pallet/parse/pallet_struct.rs @@ -52,7 +52,6 @@ pub struct PalletStructDef { /// * `#[pallet::generate_store($vis trait Store)]` /// * `#[pallet::without_storage_info]` /// * `#[pallet::storage_version(STORAGE_VERSION)]` -/// * `#[pallet::call_weight($weight_trait)]` pub enum PalletStructAttr { GenerateStore { span: proc_macro2::Span, vis: syn::Visibility, keyword: keyword::Store }, WithoutStorageInfoTrait(proc_macro2::Span), From 7bbea6e68b6f33a141b1edf36b4586d567228a31 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Thu, 27 Apr 2023 12:17:32 +0000 Subject: [PATCH 17/17] Update docs Signed-off-by: Oliver Tale-Yazdi --- .../procedural/src/pallet/parse/mod.rs | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/frame/support/procedural/src/pallet/parse/mod.rs b/frame/support/procedural/src/pallet/parse/mod.rs index 3e4498626e512..770cba68c1aad 100644 --- a/frame/support/procedural/src/pallet/parse/mod.rs +++ b/frame/support/procedural/src/pallet/parse/mod.rs @@ -426,16 +426,20 @@ enum PalletAttr { Config(proc_macro2::Span), Pallet(proc_macro2::Span), Hooks(proc_macro2::Span), - /// A `#[pallet::call]` with optional attribute. + /// A `#[pallet::call]` with optional attributes to specialize the behaviour. /// /// # Attributes /// - /// All attributes can be assigned by calling or assigning to them. + /// Each attribute `attr` can take the form of `#[pallet::call(attr = …)]` or + /// `#[pallet::call(attr(…))]`. The possible attributes are: /// /// ## `weight` /// - /// Can be used to reduce the repetitive weight annotation in the trivial case. Instead of - /// writing: + /// Can be used to reduce the repetitive weight annotation in the trivial case. It accepts one + /// argument that is expected to be an implementation of the `WeightInfo` or something that + /// behaves syntactically equivalent. This allows to annotate a `WeightInfo` for all the calls. + /// Now each call does not need to specify its own `#[pallet::weight]` but can instead use the + /// one from the `#[pallet::call]` definition. So instead of having to write it on each call: /// /// ```ignore /// #[pallet::call] @@ -443,7 +447,7 @@ enum PalletAttr { /// #[pallet::weight(T::WeightInfo::create())] /// pub fn create( /// ``` - /// you can now do: + /// you can now omit it on the call itself, if the name of the weigh function matches the call: /// /// ```ignore /// #[pallet::call(weight = ::WeightInfo)] @@ -451,10 +455,14 @@ enum PalletAttr { /// pub fn create( /// ``` /// - /// Both code snippets are equivalent. The passed type will be prepended to the name of the - /// call - if there is no `weight` attribute set on the call. This works together with - /// instanced pallets by using `Config`. This attribute takes precedence over the default - /// weight if the pallet is in dev-mode. + /// It is possible to use this syntax together with instantiated pallets by using `Config` + /// instead. + /// + /// ### Dev Mode + /// + /// Normally the `dev_mode` sets all weights of calls without a `#[pallet::weight]` annotation + /// to zero. Now when there is a `weight` attribute on the `#[pallet::call]`, then that is used + /// instead of the zero weight. So to say: it works together with `dev_mode`. RuntimeCall(Option, proc_macro2::Span), Error(proc_macro2::Span), RuntimeEvent(proc_macro2::Span),