Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
fix weight for inner call with new origin
Browse files Browse the repository at this point in the history
  • Loading branch information
gui1117 committed Sep 24, 2020
1 parent 5f75688 commit 9f0731e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
5 changes: 3 additions & 2 deletions frame/multisig/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,9 @@ decl_module! {
/// # </weight>
#[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,
Expand Down
8 changes: 6 additions & 2 deletions frame/proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,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,
Expand Down Expand Up @@ -558,7 +560,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,
Expand Down
8 changes: 7 additions & 1 deletion frame/recovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
#[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<<T as Trait>::Call>
Expand Down
12 changes: 11 additions & 1 deletion frame/scheduler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -351,6 +351,16 @@ decl_module! {
*cumulative_weight = cumulative_weight
.saturating_add(s.call.get_dispatch_info().weight);

let origin = <<T as Trait>::Origin as From<T::PalletsOrigin>>::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));
Expand Down
8 changes: 7 additions & 1 deletion frame/sudo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,13 @@ decl_module! {
/// - One DB write (event).
/// - Weight of derivative `call` execution + 10,000.
/// # </weight>
#[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: <T::Lookup as StaticLookup>::Source,
call: Box<<T as Trait>::Call>
Expand Down
4 changes: 3 additions & 1 deletion frame/utility/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<<T as Trait>::Call>) -> DispatchResult {
Expand Down

0 comments on commit 9f0731e

Please sign in to comment.