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

Commit f8265a5

Browse files
authored
Fix weight for inner call with new origin (#7196)
* fix weight for inner call with new origin * fix
1 parent 0264c74 commit f8265a5

6 files changed

Lines changed: 39 additions & 10 deletions

File tree

frame/multisig/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,9 @@ decl_module! {
237237
/// # </weight>
238238
#[weight = (
239239
T::WeightInfo::as_multi_threshold_1(call.using_encoded(|c| c.len() as u32))
240-
.saturating_add(call.get_dispatch_info().weight
241-
),
240+
.saturating_add(call.get_dispatch_info().weight)
241+
// AccountData for inner call origin accountdata.
242+
.saturating_add(T::DbWeight::get().reads_writes(1, 1)),
242243
call.get_dispatch_info().class,
243244
)]
244245
fn as_multi_threshold_1(origin,

frame/proxy/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ decl_module! {
244244
#[weight = {
245245
let di = call.get_dispatch_info();
246246
(T::WeightInfo::proxy(T::MaxProxies::get().into())
247-
.saturating_add(di.weight),
247+
.saturating_add(di.weight)
248+
// AccountData for inner call origin accountdata.
249+
.saturating_add(T::DbWeight::get().reads_writes(1, 1)),
248250
di.class)
249251
}]
250252
fn proxy(origin,
@@ -542,7 +544,9 @@ decl_module! {
542544
#[weight = {
543545
let di = call.get_dispatch_info();
544546
(T::WeightInfo::proxy_announced(T::MaxPending::get(), T::MaxProxies::get().into())
545-
.saturating_add(di.weight),
547+
.saturating_add(di.weight)
548+
// AccountData for inner call origin accountdata.
549+
.saturating_add(T::DbWeight::get().reads_writes(1, 1)),
546550
di.class)
547551
}]
548552
fn proxy_announced(origin,

frame/recovery/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,13 @@ decl_module! {
352352
/// - The weight of the `call` + 10,000.
353353
/// - One storage lookup to check account is recovered by `who`. O(1)
354354
/// # </weight>
355-
#[weight = (call.get_dispatch_info().weight + 10_000, call.get_dispatch_info().class)]
355+
#[weight = (
356+
call.get_dispatch_info().weight
357+
.saturating_add(10_000)
358+
// AccountData for inner call origin accountdata.
359+
.saturating_add(T::DbWeight::get().reads_writes(1, 1)),
360+
call.get_dispatch_info().class
361+
)]
356362
fn as_recovered(origin,
357363
account: T::AccountId,
358364
call: Box<<T as Trait>::Call>

frame/scheduler/src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ use frame_support::{
6363
traits::{Get, schedule::{self, DispatchTime}, OriginTrait, EnsureOrigin, IsType},
6464
weights::{GetDispatchInfo, Weight},
6565
};
66-
use frame_system::{self as system};
66+
use frame_system::{self as system, ensure_signed};
6767

6868
pub trait WeightInfo {
6969
fn schedule(s: u32, ) -> Weight;
@@ -351,6 +351,16 @@ decl_module! {
351351
*cumulative_weight = cumulative_weight
352352
.saturating_add(s.call.get_dispatch_info().weight);
353353

354+
let origin = <<T as Trait>::Origin as From<T::PalletsOrigin>>::from(
355+
s.origin.clone()
356+
).into();
357+
358+
if ensure_signed(origin).is_ok() {
359+
// AccountData for inner call origin accountdata.
360+
*cumulative_weight = cumulative_weight
361+
.saturating_add(T::DbWeight::get().reads_writes(1, 1));
362+
}
363+
354364
if s.maybe_id.is_some() {
355365
// Remove/Modify Lookup
356366
*cumulative_weight = cumulative_weight.saturating_add(T::DbWeight::get().writes(1));

frame/sudo/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ use frame_support::{
9595
};
9696
use frame_support::{
9797
weights::{Weight, GetDispatchInfo, Pays},
98-
traits::UnfilteredDispatchable,
98+
traits::{UnfilteredDispatchable, Get},
9999
dispatch::DispatchResultWithPostInfo,
100100
};
101101
use frame_system::ensure_signed;
@@ -197,7 +197,13 @@ decl_module! {
197197
/// - One DB write (event).
198198
/// - Weight of derivative `call` execution + 10,000.
199199
/// # </weight>
200-
#[weight = (call.get_dispatch_info().weight + 10_000, call.get_dispatch_info().class)]
200+
#[weight = (
201+
call.get_dispatch_info().weight
202+
.saturating_add(10_000)
203+
// AccountData for inner call origin accountdata.
204+
.saturating_add(T::DbWeight::get().reads_writes(1, 1)),
205+
call.get_dispatch_info().class
206+
)]
201207
fn sudo_as(origin,
202208
who: <T::Lookup as StaticLookup>::Source,
203209
call: Box<<T as Trait>::Call>

frame/utility/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ use sp_core::TypeId;
6161
use sp_io::hashing::blake2_256;
6262
use frame_support::{decl_module, decl_event, decl_storage, Parameter};
6363
use frame_support::{
64-
traits::{OriginTrait, UnfilteredDispatchable},
64+
traits::{OriginTrait, UnfilteredDispatchable, Get},
6565
weights::{Weight, GetDispatchInfo, DispatchClass}, dispatch::PostDispatchInfo,
6666
};
6767
use frame_system::{ensure_signed, ensure_root};
@@ -185,7 +185,9 @@ decl_module! {
185185
/// The dispatch origin for this call must be _Signed_.
186186
#[weight = (
187187
T::WeightInfo::as_derivative()
188-
.saturating_add(call.get_dispatch_info().weight),
188+
.saturating_add(call.get_dispatch_info().weight)
189+
// AccountData for inner call origin accountdata.
190+
.saturating_add(T::DbWeight::get().reads_writes(1, 1)),
189191
call.get_dispatch_info().class,
190192
)]
191193
fn as_derivative(origin, index: u16, call: Box<<T as Trait>::Call>) -> DispatchResult {

0 commit comments

Comments
 (0)