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 (#7196)
Browse files Browse the repository at this point in the history
* fix weight for inner call with new origin

* fix
  • Loading branch information
gui1117 committed Oct 1, 2020
1 parent 0264c74 commit f8265a5
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 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 @@ -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,
Expand Down Expand Up @@ -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,
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
10 changes: 8 additions & 2 deletions frame/sudo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down 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
6 changes: 4 additions & 2 deletions frame/utility/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down 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 f8265a5

Please sign in to comment.