From f8265a57ff91ff959205afabb6054ee3e46f3763 Mon Sep 17 00:00:00 2001 From: Guillaume Thiolliere Date: Thu, 1 Oct 2020 10:24:34 +0200 Subject: [PATCH] Fix weight for inner call with new origin (#7196) * fix weight for inner call with new origin * fix --- frame/multisig/src/lib.rs | 5 +++-- frame/proxy/src/lib.rs | 8 ++++++-- frame/recovery/src/lib.rs | 8 +++++++- frame/scheduler/src/lib.rs | 12 +++++++++++- frame/sudo/src/lib.rs | 10 ++++++++-- frame/utility/src/lib.rs | 6 ++++-- 6 files changed, 39 insertions(+), 10 deletions(-) diff --git a/frame/multisig/src/lib.rs b/frame/multisig/src/lib.rs index 1ce4e06a6e118..b0119984038a6 100644 --- a/frame/multisig/src/lib.rs +++ b/frame/multisig/src/lib.rs @@ -237,8 +237,9 @@ decl_module! { /// # #[weight = ( T::WeightInfo::as_multi_threshold_1(call.using_encoded(|c| c.len() as u32)) - .saturating_add(call.get_dispatch_info().weight - ), + .saturating_add(call.get_dispatch_info().weight) + // AccountData for inner call origin accountdata. + .saturating_add(T::DbWeight::get().reads_writes(1, 1)), call.get_dispatch_info().class, )] fn as_multi_threshold_1(origin, diff --git a/frame/proxy/src/lib.rs b/frame/proxy/src/lib.rs index 98d6ef47d3df2..21ae9a45a15b3 100644 --- a/frame/proxy/src/lib.rs +++ b/frame/proxy/src/lib.rs @@ -244,7 +244,9 @@ decl_module! { #[weight = { let di = call.get_dispatch_info(); (T::WeightInfo::proxy(T::MaxProxies::get().into()) - .saturating_add(di.weight), + .saturating_add(di.weight) + // AccountData for inner call origin accountdata. + .saturating_add(T::DbWeight::get().reads_writes(1, 1)), di.class) }] fn proxy(origin, @@ -542,7 +544,9 @@ decl_module! { #[weight = { let di = call.get_dispatch_info(); (T::WeightInfo::proxy_announced(T::MaxPending::get(), T::MaxProxies::get().into()) - .saturating_add(di.weight), + .saturating_add(di.weight) + // AccountData for inner call origin accountdata. + .saturating_add(T::DbWeight::get().reads_writes(1, 1)), di.class) }] fn proxy_announced(origin, diff --git a/frame/recovery/src/lib.rs b/frame/recovery/src/lib.rs index b3aad8433eb3c..c97824497fded 100644 --- a/frame/recovery/src/lib.rs +++ b/frame/recovery/src/lib.rs @@ -352,7 +352,13 @@ decl_module! { /// - The weight of the `call` + 10,000. /// - One storage lookup to check account is recovered by `who`. O(1) /// # - #[weight = (call.get_dispatch_info().weight + 10_000, call.get_dispatch_info().class)] + #[weight = ( + call.get_dispatch_info().weight + .saturating_add(10_000) + // AccountData for inner call origin accountdata. + .saturating_add(T::DbWeight::get().reads_writes(1, 1)), + call.get_dispatch_info().class + )] fn as_recovered(origin, account: T::AccountId, call: Box<::Call> diff --git a/frame/scheduler/src/lib.rs b/frame/scheduler/src/lib.rs index c91131005972b..272174a9965a9 100644 --- a/frame/scheduler/src/lib.rs +++ b/frame/scheduler/src/lib.rs @@ -63,7 +63,7 @@ use frame_support::{ traits::{Get, schedule::{self, DispatchTime}, OriginTrait, EnsureOrigin, IsType}, weights::{GetDispatchInfo, Weight}, }; -use frame_system::{self as system}; +use frame_system::{self as system, ensure_signed}; pub trait WeightInfo { fn schedule(s: u32, ) -> Weight; @@ -351,6 +351,16 @@ decl_module! { *cumulative_weight = cumulative_weight .saturating_add(s.call.get_dispatch_info().weight); + let origin = <::Origin as From>::from( + s.origin.clone() + ).into(); + + if ensure_signed(origin).is_ok() { + // AccountData for inner call origin accountdata. + *cumulative_weight = cumulative_weight + .saturating_add(T::DbWeight::get().reads_writes(1, 1)); + } + if s.maybe_id.is_some() { // Remove/Modify Lookup *cumulative_weight = cumulative_weight.saturating_add(T::DbWeight::get().writes(1)); diff --git a/frame/sudo/src/lib.rs b/frame/sudo/src/lib.rs index 83e73d2ce4349..0d21e44326668 100644 --- a/frame/sudo/src/lib.rs +++ b/frame/sudo/src/lib.rs @@ -95,7 +95,7 @@ use frame_support::{ }; use frame_support::{ weights::{Weight, GetDispatchInfo, Pays}, - traits::UnfilteredDispatchable, + traits::{UnfilteredDispatchable, Get}, dispatch::DispatchResultWithPostInfo, }; use frame_system::ensure_signed; @@ -197,7 +197,13 @@ decl_module! { /// - One DB write (event). /// - Weight of derivative `call` execution + 10,000. /// # - #[weight = (call.get_dispatch_info().weight + 10_000, call.get_dispatch_info().class)] + #[weight = ( + call.get_dispatch_info().weight + .saturating_add(10_000) + // AccountData for inner call origin accountdata. + .saturating_add(T::DbWeight::get().reads_writes(1, 1)), + call.get_dispatch_info().class + )] fn sudo_as(origin, who: ::Source, call: Box<::Call> diff --git a/frame/utility/src/lib.rs b/frame/utility/src/lib.rs index c39526ac0a7df..d0bb99d917455 100644 --- a/frame/utility/src/lib.rs +++ b/frame/utility/src/lib.rs @@ -61,7 +61,7 @@ use sp_core::TypeId; use sp_io::hashing::blake2_256; use frame_support::{decl_module, decl_event, decl_storage, Parameter}; use frame_support::{ - traits::{OriginTrait, UnfilteredDispatchable}, + traits::{OriginTrait, UnfilteredDispatchable, Get}, weights::{Weight, GetDispatchInfo, DispatchClass}, dispatch::PostDispatchInfo, }; use frame_system::{ensure_signed, ensure_root}; @@ -185,7 +185,9 @@ decl_module! { /// The dispatch origin for this call must be _Signed_. #[weight = ( T::WeightInfo::as_derivative() - .saturating_add(call.get_dispatch_info().weight), + .saturating_add(call.get_dispatch_info().weight) + // AccountData for inner call origin accountdata. + .saturating_add(T::DbWeight::get().reads_writes(1, 1)), call.get_dispatch_info().class, )] fn as_derivative(origin, index: u16, call: Box<::Call>) -> DispatchResult {