Revamp some of the weights (#4759)

* Remove free transaction dos vectors.

* Bump spec version

* Indentation.

* Update frame/support/src/weights.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Gavin Wood
2020-01-29 13:38:46 +01:00
committed by GitHub
parent 556c80e792
commit 5c1c31ccd4
8 changed files with 22 additions and 27 deletions
+1 -1
View File
@@ -385,7 +385,7 @@ mod tests {
fn some_root_operation(origin) {
let _ = frame_system::ensure_root(origin);
}
#[weight = SimpleDispatchInfo::FreeNormal]
#[weight = SimpleDispatchInfo::InsecureFreeNormal]
fn some_unsigned_message(origin) {
let _ = frame_system::ensure_none(origin);
}
+1 -1
View File
@@ -842,7 +842,7 @@ decl_module! {
/// - `S + 2` storage mutations.
/// - One event.
/// # </weight>
#[weight = SimpleDispatchInfo::FreeOperational]
#[weight = SimpleDispatchInfo::FixedNormal(100_000)]
fn kill_identity(origin, target: <T::Lookup as StaticLookup>::Source) {
T::ForceOrigin::try_origin(origin)
.map(|_| ())
+2 -2
View File
@@ -194,7 +194,7 @@ decl_module! {
/// - One storage read/write.
/// - One event.
/// # </weight>
#[weight = SimpleDispatchInfo::FreeOperational]
#[weight = SimpleDispatchInfo::FixedNormal(70_000)]
fn kill_name(origin, target: <T::Lookup as StaticLookup>::Source) {
T::ForceOrigin::try_origin(origin)
.map(|_| ())
@@ -222,7 +222,7 @@ decl_module! {
/// - One storage read/write.
/// - One event.
/// # </weight>
#[weight = SimpleDispatchInfo::FreeOperational]
#[weight = SimpleDispatchInfo::FixedNormal(70_000)]
fn force_name(origin, target: <T::Lookup as StaticLookup>::Source, name: Vec<u8>) {
T::ForceOrigin::try_origin(origin)
.map(|_| ())
+7 -7
View File
@@ -1150,7 +1150,7 @@ decl_module! {
}
/// The ideal number of validators.
#[weight = SimpleDispatchInfo::FreeOperational]
#[weight = SimpleDispatchInfo::FixedNormal(5_000)]
fn set_validator_count(origin, #[compact] new: u32) {
ensure_root(origin)?;
ValidatorCount::put(new);
@@ -1163,7 +1163,7 @@ decl_module! {
/// # <weight>
/// - No arguments.
/// # </weight>
#[weight = SimpleDispatchInfo::FreeOperational]
#[weight = SimpleDispatchInfo::FixedNormal(5_000)]
fn force_no_eras(origin) {
ensure_root(origin)?;
ForceEra::put(Forcing::ForceNone);
@@ -1175,21 +1175,21 @@ decl_module! {
/// # <weight>
/// - No arguments.
/// # </weight>
#[weight = SimpleDispatchInfo::FreeOperational]
#[weight = SimpleDispatchInfo::FixedNormal(5_000)]
fn force_new_era(origin) {
ensure_root(origin)?;
ForceEra::put(Forcing::ForceNew);
}
/// Set the validators who cannot be slashed (if any).
#[weight = SimpleDispatchInfo::FreeOperational]
#[weight = SimpleDispatchInfo::FixedNormal(5_000)]
fn set_invulnerables(origin, validators: Vec<T::AccountId>) {
ensure_root(origin)?;
<Invulnerables<T>>::put(validators);
}
/// Force a current staker to become completely unstaked, immediately.
#[weight = SimpleDispatchInfo::FreeOperational]
#[weight = SimpleDispatchInfo::FixedNormal(10_000)]
fn force_unstake(origin, stash: T::AccountId) {
ensure_root(origin)?;
@@ -1204,7 +1204,7 @@ decl_module! {
/// # <weight>
/// - One storage write
/// # </weight>
#[weight = SimpleDispatchInfo::FreeOperational]
#[weight = SimpleDispatchInfo::FixedNormal(5_000)]
fn force_new_era_always(origin) {
ensure_root(origin)?;
ForceEra::put(Forcing::ForceAlways);
@@ -1217,7 +1217,7 @@ decl_module! {
/// # <weight>
/// - One storage write.
/// # </weight>
#[weight = SimpleDispatchInfo::FreeOperational]
#[weight = SimpleDispatchInfo::FixedNormal(1_000_000)]
fn cancel_deferred_slash(origin, era: EraIndex, slash_indices: Vec<u32>) {
T::SlashCancelOrigin::try_origin(origin)
.map(|_| ())
+1 -1
View File
@@ -119,7 +119,7 @@ decl_module! {
/// - One DB write (event).
/// - Unknown weight of derivative `proposal` execution.
/// # </weight>
#[weight = SimpleDispatchInfo::FreeOperational]
#[weight = SimpleDispatchInfo::FixedNormal(50_000)]
fn sudo(origin, proposal: Box<T::Proposal>) {
// This is a public call, so we ensure that the origin is some signed account.
let sender = ensure_signed(origin)?;
+5 -10
View File
@@ -127,11 +127,10 @@ impl From<SimpleDispatchInfo> for DispatchClass {
match tx {
SimpleDispatchInfo::FixedOperational(_) => DispatchClass::Operational,
SimpleDispatchInfo::MaxOperational => DispatchClass::Operational,
SimpleDispatchInfo::FreeOperational => DispatchClass::Operational,
SimpleDispatchInfo::FixedNormal(_) => DispatchClass::Normal,
SimpleDispatchInfo::MaxNormal => DispatchClass::Normal,
SimpleDispatchInfo::FreeNormal => DispatchClass::Normal,
SimpleDispatchInfo::InsecureFreeNormal => DispatchClass::Normal,
}
}
}
@@ -178,14 +177,12 @@ pub enum SimpleDispatchInfo {
FixedNormal(Weight),
/// A normal dispatch with the maximum weight.
MaxNormal,
/// A normal dispatch with no weight.
FreeNormal,
/// A normal dispatch with no weight. Base and bytes fees still need to be paid.
InsecureFreeNormal,
/// An operational dispatch with fixed weight.
FixedOperational(Weight),
/// An operational dispatch with the maximum weight.
MaxOperational,
/// An operational dispatch with no weight.
FreeOperational,
}
impl<T> WeighData<T> for SimpleDispatchInfo {
@@ -193,11 +190,10 @@ impl<T> WeighData<T> for SimpleDispatchInfo {
match self {
SimpleDispatchInfo::FixedNormal(w) => *w,
SimpleDispatchInfo::MaxNormal => Bounded::max_value(),
SimpleDispatchInfo::FreeNormal => Bounded::min_value(),
SimpleDispatchInfo::InsecureFreeNormal => Bounded::min_value(),
SimpleDispatchInfo::FixedOperational(w) => *w,
SimpleDispatchInfo::MaxOperational => Bounded::max_value(),
SimpleDispatchInfo::FreeOperational => Bounded::min_value(),
}
}
}
@@ -213,11 +209,10 @@ impl<T> PaysFee<T> for SimpleDispatchInfo {
match self {
SimpleDispatchInfo::FixedNormal(_) => true,
SimpleDispatchInfo::MaxNormal => true,
SimpleDispatchInfo::FreeNormal => true,
SimpleDispatchInfo::InsecureFreeNormal => true,
SimpleDispatchInfo::FixedOperational(_) => true,
SimpleDispatchInfo::MaxOperational => true,
SimpleDispatchInfo::FreeOperational => false,
}
}
}
@@ -477,7 +477,7 @@ mod tests {
let len = 100;
// like a FreeOperational
// This is a completely free (and thus wholly insecure/DoS-ridden) transaction.
let operational_transaction = DispatchInfo {
weight: 0,
class: DispatchClass::Operational,
@@ -489,7 +489,7 @@ mod tests {
.is_ok()
);
// like a FreeNormal
// like a InsecureFreeNormal
let free_transaction = DispatchInfo {
weight: 0,
class: DispatchClass::Normal,