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

Update Weights for Utility Pallet #5787

Merged
merged 7 commits into from
Apr 29, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions frame/utility/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,25 @@ impl TypeId for IndexedUtilityModuleId {
const TYPE_ID: [u8; 4] = *b"suba";
}

mod weight_of {
use super::*;

/// - Base Weight:
/// - Create: 137.5 + 0.274 * S µs
/// - Approve: 103.8 + .266 * S µs
/// - Complete: 116.2 + .754 * S µs
/// - DB Weight:
/// - Reads: Multisig Storage, [Caller Account]
/// - Writes: Multisig Storage, [Caller Account]
/// - Plus Call Weight
pub fn as_multi<T: Trait>(other_sig_len: usize, call_weight: Weight) -> Weight {
call_weight
.saturating_add(150_000_000)
.saturating_add((other_sig_len as Weight).saturating_mul(750_000))
.saturating_add(T::DbWeight::get().reads_writes(1, 1))
}
}

decl_module! {
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
type Error = Error<T>;
Expand Down Expand Up @@ -330,10 +349,7 @@ decl_module! {
/// # </weight>
#[weight = FunctionOf(
|args: (&u16, &Vec<T::AccountId>, &Option<Timepoint<T::BlockNumber>>, &Box<<T as Trait>::Call>)| {
args.3.get_dispatch_info().weight
.saturating_add(150_000_000)
.saturating_add((args.1.len() as Weight).saturating_mul(500_000))
.saturating_add(T::DbWeight::get().reads_writes(1, 1))
weight_of::as_multi::<T>(args.1.len(),args.3.get_dispatch_info().weight)
},
|args: (&u16, &Vec<T::AccountId>, &Option<Timepoint<T::BlockNumber>>, &Box<<T as Trait>::Call>)| {
args.3.get_dispatch_info().class
Expand All @@ -350,7 +366,8 @@ decl_module! {
ensure!(threshold >= 1, Error::<T>::ZeroThreshold);
let max_sigs = T::MaxSignatories::get() as usize;
ensure!(!other_signatories.is_empty(), Error::<T>::TooFewSignatories);
ensure!(other_signatories.len() < max_sigs, Error::<T>::TooManySignatories);
let other_signatories_len = other_signatories.len();
ensure!(other_signatories_len < max_sigs, Error::<T>::TooManySignatories);
let signatories = Self::ensure_sorted_and_insert(other_signatories, who.clone())?;

let id = Self::multi_account_id(&signatories, threshold);
Expand All @@ -365,8 +382,8 @@ decl_module! {
m.approvals.insert(pos, who.clone());
<Multisigs<T>>::insert(&id, call_hash, m);
Self::deposit_event(RawEvent::MultisigApproval(who, timepoint, id, call_hash));
// Call is not made, so we can return that weight
return Ok(Some(call.get_dispatch_info().weight).into())
// Call is not made, so the actual weight does not include call
return Ok(Some(weight_of::as_multi::<T>(other_signatories_len, 0)).into())
}
} else {
if (m.approvals.len() as u16) < threshold {
Expand Down Expand Up @@ -395,10 +412,13 @@ decl_module! {
});
Self::deposit_event(RawEvent::NewMultisig(who, id, call_hash));
// Call is not made, so we can return that weight
return Ok(Some(call.get_dispatch_info().weight).into())
return Ok(Some(weight_of::as_multi::<T>(other_signatories_len, 0)).into())
} else {
return call.dispatch(frame_system::RawOrigin::Signed(id).into())
.map(|_| None.into()).map_err(|e| e.error.into())
let post_dispatch_info = call.dispatch(frame_system::RawOrigin::Signed(id).into())?;
shawntabrizi marked this conversation as resolved.
Show resolved Hide resolved
match post_dispatch_info.actual_weight {
Some(actual_weight) => return Ok(Some(weight_of::as_multi::<T>(other_signatories_len, actual_weight)).into()),
None => return Ok(None.into()),
}
}
}
}
Expand Down