Skip to content

Commit 5bd4e30

Browse files
authored
Store dispatch info of calls locally in weight calculation (#7849)
* utility * sudo * more * recovery * better formatting
1 parent 37d0b55 commit 5bd4e30

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/lib.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ decl_module! {
130130
/// - One DB write (event).
131131
/// - Weight of derivative `call` execution + 10,000.
132132
/// # </weight>
133-
#[weight = (call.get_dispatch_info().weight + 10_000, call.get_dispatch_info().class)]
133+
#[weight = {
134+
let dispatch_info = call.get_dispatch_info();
135+
(dispatch_info.weight.saturating_add(10_000), dispatch_info.class)
136+
}]
134137
fn sudo(origin, call: Box<<T as Config>::Call>) -> DispatchResultWithPostInfo {
135138
// This is a public call, so we ensure that the origin is some signed account.
136139
let sender = ensure_signed(origin)?;
@@ -197,13 +200,16 @@ decl_module! {
197200
/// - One DB write (event).
198201
/// - Weight of derivative `call` execution + 10,000.
199202
/// # </weight>
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-
)]
203+
#[weight = {
204+
let dispatch_info = call.get_dispatch_info();
205+
(
206+
dispatch_info.weight
207+
.saturating_add(10_000)
208+
// AccountData for inner call origin accountdata.
209+
.saturating_add(T::DbWeight::get().reads_writes(1, 1)),
210+
dispatch_info.class,
211+
)
212+
}]
207213
fn sudo_as(origin,
208214
who: <T::Lookup as StaticLookup>::Source,
209215
call: Box<<T as Config>::Call>

0 commit comments

Comments
 (0)