From 9eb2c49bfda5838e5c2377f4e39c7f1e752d80e5 Mon Sep 17 00:00:00 2001 From: thiolliere Date: Mon, 20 Apr 2020 18:57:00 +0200 Subject: [PATCH 01/12] treasury weight formula --- frame/treasury/src/lib.rs | 132 +++++++++++++++++++++++++------------- 1 file changed, 87 insertions(+), 45 deletions(-) diff --git a/frame/treasury/src/lib.rs b/frame/treasury/src/lib.rs index af39985133c81..c6435f52c406c 100644 --- a/frame/treasury/src/lib.rs +++ b/frame/treasury/src/lib.rs @@ -91,6 +91,7 @@ use serde::{Serialize, Deserialize}; use sp_std::prelude::*; use frame_support::{decl_module, decl_storage, decl_event, ensure, print, decl_error, Parameter}; +use frame_support::dispatch::DispatchResultWithPostInfo; use frame_support::traits::{ Currency, Get, Imbalance, OnUnbalanced, ExistenceRequirement::KeepAlive, ReservableCurrency, WithdrawReason @@ -98,7 +99,7 @@ use frame_support::traits::{ use sp_runtime::{Permill, ModuleId, Percent, RuntimeDebug, traits::{ Zero, StaticLookup, AccountIdConversion, Saturating, Hash, BadOrigin }}; -use frame_support::weights::{Weight, MINIMUM_WEIGHT, SimpleDispatchInfo}; +use frame_support::weights::Weight; use frame_support::traits::{Contains, EnsureOrigin}; use codec::{Encode, Decode}; use frame_system::{self as system, ensure_signed, ensure_root}; @@ -113,6 +114,9 @@ type NegativeImbalanceOf = <::Currency as Currency< + ReservableCurrency; @@ -124,6 +128,8 @@ pub trait Trait: frame_system::Trait { type RejectOrigin: EnsureOrigin; /// Origin from which tippers must come. + /// The lenght must be less then [`MAX_TIPPERS_COUNT`](./constant.MAX_TIPPERS_COUNT.html). + /// Its cost it expected to be same as if it was stored sorted in a storage value. type Tippers: Contains; /// The period for which a tip remains open after is has achieved threshold tippers. @@ -323,11 +329,11 @@ decl_module! { /// proposal is awarded. /// /// # - /// - O(1). - /// - Limited storage reads. - /// - One DB change, one extra DB entry. + /// - Complexity: O(1) + /// - DbReads: `ProposalCount`, `sender account` + /// - DbWrites: `ProposalCount`, `Proposals`, `sender account` /// # - #[weight = SimpleDispatchInfo::FixedNormal(500_000_000)] + #[weight = 114_700_000 + T::DbWeight::get().reads_writes(1, 2)] fn propose_spend( origin, #[compact] value: BalanceOf, @@ -350,11 +356,11 @@ decl_module! { /// Reject a proposed spend. The original deposit will be slashed. /// /// # - /// - O(1). - /// - Limited storage reads. - /// - One DB clear. + /// - Complexity: O(1) + /// - DbReads: `Proposals`, `rejected proposer account` + /// - DbWrites: `Proposals`, `rejected proposer account` /// # - #[weight = SimpleDispatchInfo::FixedOperational(100_000_000)] + #[weight = 125_800_000 + T::DbWeight::get().reads_writes(2, 2)] fn reject_proposal(origin, #[compact] proposal_id: ProposalIndex) { T::RejectOrigin::try_origin(origin) .map(|_| ()) @@ -372,11 +378,11 @@ decl_module! { /// and the original deposit will be returned. /// /// # - /// - O(1). - /// - Limited storage reads. - /// - One DB change. + /// - Complexity: O(1). + /// - DbReads: `Proposals`, `Approvals` + /// - DbWrite: `Approvals` /// # - #[weight = SimpleDispatchInfo::FixedOperational(100_000_000)] + #[weight = 33_610_000 + T::DbWeight::get().reads_writes(2, 1)] fn approve_proposal(origin, #[compact] proposal_id: ProposalIndex) { T::ApproveOrigin::try_origin(origin) .map(|_| ()) @@ -400,12 +406,12 @@ decl_module! { /// Emits `NewTip` if successful. /// /// # - /// - `O(R)` where `R` length of `reason`. - /// - One balance operation. - /// - One storage mutation (codec `O(R)`). - /// - One event. + /// - Complexity: `O(R)` where `R` length of `reason`. + /// - encoding and hashing of 'reason' + /// - DbReads: `Reasons`, `Tips`, `who account data` + /// - DbWrites: `Tips`, `who account data` /// # - #[weight = SimpleDispatchInfo::FixedNormal(100_000_000)] + #[weight = 138_400_000 + 4_000 * reason.len() as u64 + T::DbWeight::get().reads_writes(3, 2)] fn report_awesome(origin, reason: Vec, who: T::AccountId) { let finder = ensure_signed(origin)?; @@ -442,12 +448,12 @@ decl_module! { /// Emits `TipRetracted` if successful. /// /// # - /// - `O(T)` - /// - One balance operation. - /// - Two storage removals (one read, codec `O(T)`). - /// - One event. + /// - Complexity: `O(1)` + /// - Depends on the length of `T::Hash` which is fixed. + /// - DbReads: `Tips`, `sender account data` + /// - DbWrites: `Reasons`, `Tips`, `sender account data` /// # - #[weight = SimpleDispatchInfo::FixedNormal(50_000_000)] + #[weight = 115_700_000 + T::DbWeight::get().reads_writes(1, 2)] fn retract_tip(origin, hash: T::Hash) { let who = ensure_signed(origin)?; let tip = Tips::::get(&hash).ok_or(Error::::UnknownTip)?; @@ -474,13 +480,20 @@ decl_module! { /// Emits `NewTip` if successful. /// /// # - /// - `O(R + T)` where `R` length of `reason`, `T` is the number of tippers. `T` is - /// naturally capped as a membership set, `R` is limited through transaction-size. - /// - Two storage insertions (codecs `O(R)`, `O(T)`), one read `O(1)`. - /// - One event. + /// - Complexity: `O(R + T)` where `R` length of `reason`, `T` is the number of tippers. + /// - `O(T)`: decoding `Tipper` vec of length `T` + /// `T` is less than `MAX_TIPPERS_COUNT`, it is charged as maximum and then refund. + /// The actual cost depends on the implementation of `T::Tippers`. + /// - `O(R)`: hashing and encoding of reason of length `R` + /// - DbReads: `Tippers`, `Reasons` + /// - DbWrites: `Reasons`, `Tips` /// # - #[weight = SimpleDispatchInfo::FixedNormal(150_000_000)] - fn tip_new(origin, reason: Vec, who: T::AccountId, tip_value: BalanceOf) { + #[weight = 107_700_000 + 4_000 * reason.len() as u64 + 481_000 * MAX_TIPPERS_COUNT + + T::DbWeight::get().reads_writes(2, 2)] + fn tip_new(origin, reason: Vec, who: T::AccountId, tip_value: BalanceOf) + -> DispatchResultWithPostInfo + { + // NOTE: we don't refund in case of error because checking cost too much. let tipper = ensure_signed(origin)?; ensure!(T::Tippers::contains(&tipper), BadOrigin); let reason_hash = T::Hashing::hash(&reason[..]); @@ -492,6 +505,8 @@ decl_module! { let tips = vec![(tipper, tip_value)]; let tip = OpenTip { reason: reason_hash, who, finder: None, closes: None, tips }; Tips::::insert(&hash, tip); + + Ok(Some(MAX_TIPPERS_COUNT.saturating_sub(T::Tippers::count() as u64) * 481_000).into()) } /// Declare a tip value for an already-open tip. @@ -509,12 +524,19 @@ decl_module! { /// has started. /// /// # - /// - `O(T)` - /// - One storage mutation (codec `O(T)`), one storage read `O(1)`. - /// - Up to one event. + /// - Complexity: `O(T)` where `T` is the number of tippers. + /// decoding `Tipper` vec of length `T`, insert tip and check closing, + /// `T` is less than `MAX_TIPPERS_COUNT`, it is charged as maximum and then refund. + /// The actual cost depends on the implementation of `T::Tippers`. + /// + /// Actually weight could be lower as it depends on how many tips are in `OpenTip` but it + /// is weighted as if almost full i.e of length `T-1`. + /// - DbReads: `Tippers`, `Tips` + /// - DbWrites: `Tips` /// # - #[weight = SimpleDispatchInfo::FixedNormal(50_000_000)] - fn tip(origin, hash: T::Hash, tip_value: BalanceOf) { + #[weight = 67_730_000 + 1_912_000 * MAX_TIPPERS_COUNT + T::DbWeight::get().reads_writes(2, 1)] + fn tip(origin, hash: T::Hash, tip_value: BalanceOf) -> DispatchResultWithPostInfo { + // NOTE: we don't refund in case of error because checking cost too much. let tipper = ensure_signed(origin)?; ensure!(T::Tippers::contains(&tipper), BadOrigin); @@ -523,6 +545,8 @@ decl_module! { Self::deposit_event(RawEvent::TipClosing(hash.clone())); } Tips::::insert(&hash, tip); + + Ok(Some(MAX_TIPPERS_COUNT.saturating_sub(T::Tippers::count() as u64) * 1_912_000).into()) } /// Close and payout a tip. @@ -535,12 +559,15 @@ decl_module! { /// as the hash of the tuple of the original tip `reason` and the beneficiary account ID. /// /// # - /// - `O(T)` - /// - One storage retrieval (codec `O(T)`) and two removals. - /// - Up to three balance operations. + /// - Complexity: `O(T)` where `T` is the number of tippers. + /// decoding `Tipper` vec of length `T`. + /// `T` is less than `MAX_TIPPERS_COUNT`, it is charged as maximum and then refund. + /// The actual cost depends on the implementation of `T::Tippers`. + /// - DbReads: `Tips`, `Tippers`, `tip finder` + /// - DbWrites: `Reasons`, `Tips`, `Tippers`, `tip finder` /// # - #[weight = SimpleDispatchInfo::FixedNormal(50_000_000)] - fn close_tip(origin, hash: T::Hash) { + #[weight = 211_000_000 + 1_094_000 * MAX_TIPPERS_COUNT + T::DbWeight::get().reads_writes(3, 3)] + fn close_tip(origin, hash: T::Hash) -> DispatchResultWithPostInfo { ensure_signed(origin)?; let tip = Tips::::get(hash).ok_or(Error::::UnknownTip)?; @@ -550,15 +577,26 @@ decl_module! { Reasons::::remove(&tip.reason); Tips::::remove(hash); Self::payout_tip(hash, tip); + + Ok(Some(MAX_TIPPERS_COUNT.saturating_sub(T::Tippers::count() as u64) * 1_094_000).into()) } + /// # + /// - Complexity: `O(A)` where `A` is the number of approvals + /// - Db reads and writes: `Approvals`, `pot account data` + /// - Db reads and writes per approval: + /// `Proposals`, `proposer account data`, `beneficiary account data` + /// # fn on_initialize(n: T::BlockNumber) -> Weight { // Check to see if we should spend some funds! if (n % T::SpendPeriod::get()).is_zero() { - Self::spend_funds(); - } + let approvals_len = Self::spend_funds(); - MINIMUM_WEIGHT + 263_500_000 * approvals_len + + T::DbWeight::get().reads_writes(2 + approvals_len * 3, 2 + approvals_len * 3) + } else { + 0 + } } } } @@ -650,14 +688,15 @@ impl Module { Self::deposit_event(RawEvent::TipClosed(hash, tip.who, payout)); } - // Spend some money! - fn spend_funds() { + /// Spend some money! returns number of approvals before spend. + fn spend_funds() -> u64 { let mut budget_remaining = Self::pot(); Self::deposit_event(RawEvent::Spending(budget_remaining)); let mut missed_any = false; let mut imbalance = >::zero(); - Approvals::mutate(|v| { + let prior_approvals_len = Approvals::mutate(|v| { + let prior_approvals_len = v.len() as u64; v.retain(|&index| { // Should always be true, but shouldn't panic if false or we're screwed. if let Some(p) = Self::proposals(index) { @@ -681,6 +720,7 @@ impl Module { false } }); + prior_approvals_len }); if !missed_any { @@ -707,6 +747,8 @@ impl Module { } Self::deposit_event(RawEvent::Rollover(budget_remaining)); + + prior_approvals_len } /// Return the amount of money in the pot. From 652ba4b44428ee7d1d4858885451fd20c8a0e209 Mon Sep 17 00:00:00 2001 From: thiolliere Date: Tue, 21 Apr 2020 15:34:40 +0200 Subject: [PATCH 02/12] use max tippers count --- frame/treasury/src/benchmarking.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/frame/treasury/src/benchmarking.rs b/frame/treasury/src/benchmarking.rs index f901576c95d4b..8b8334f57eaaf 100644 --- a/frame/treasury/src/benchmarking.rs +++ b/frame/treasury/src/benchmarking.rs @@ -107,7 +107,6 @@ fn create_approved_proposals(n: u32) -> Result<(), &'static str> { } const MAX_BYTES: u32 = 16384; -const MAX_TIPPERS: u32 = 100; benchmarks! { _ { } @@ -158,13 +157,13 @@ benchmarks! { tip_new { let r in 0 .. MAX_BYTES; - let t in 1 .. MAX_TIPPERS; + let t in 1 .. MAX_TIPPERS_COUNT; let (caller, reason, beneficiary, value) = setup_tip::(r, t)?; }: _(RawOrigin::Signed(caller), reason, beneficiary, value) tip { - let t in 1 .. MAX_TIPPERS; + let t in 1 .. MAX_TIPPERS_COUNT; let (member, reason, beneficiary, value) = setup_tip::(0, t)?; let value = T::Currency::minimum_balance().saturating_mul(100.into()); Treasury::::tip_new( @@ -181,7 +180,7 @@ benchmarks! { }: _(RawOrigin::Signed(caller), hash, value) close_tip { - let t in 1 .. MAX_TIPPERS; + let t in 1 .. MAX_TIPPERS_COUNT; // Make sure pot is funded let pot_account = Treasury::::account_id(); From d20cbc03595e3a46f734e2ec1b0db1f551327275 Mon Sep 17 00:00:00 2001 From: thiolliere Date: Tue, 21 Apr 2020 15:44:01 +0200 Subject: [PATCH 03/12] doc --- frame/treasury/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frame/treasury/src/lib.rs b/frame/treasury/src/lib.rs index c6435f52c406c..d072e1c6733b0 100644 --- a/frame/treasury/src/lib.rs +++ b/frame/treasury/src/lib.rs @@ -128,7 +128,7 @@ pub trait Trait: frame_system::Trait { type RejectOrigin: EnsureOrigin; /// Origin from which tippers must come. - /// The lenght must be less then [`MAX_TIPPERS_COUNT`](./constant.MAX_TIPPERS_COUNT.html). + /// The lenght must be less than [`MAX_TIPPERS_COUNT`](./constant.MAX_TIPPERS_COUNT.html). /// Its cost it expected to be same as if it was stored sorted in a storage value. type Tippers: Contains; @@ -586,6 +586,7 @@ decl_module! { /// - Db reads and writes: `Approvals`, `pot account data` /// - Db reads and writes per approval: /// `Proposals`, `proposer account data`, `beneficiary account data` + /// - The weight is overestimated if some approvals got missed. /// # fn on_initialize(n: T::BlockNumber) -> Weight { // Check to see if we should spend some funds! From a53b4d033aa33f797cae60e5be2464d541616a5f Mon Sep 17 00:00:00 2001 From: thiolliere Date: Wed, 22 Apr 2020 10:27:44 +0200 Subject: [PATCH 04/12] Fix upper bound --- frame/elections-phragmen/src/lib.rs | 8 ++++ frame/support/src/traits.rs | 11 ++++-- frame/treasury/src/benchmarking.rs | 7 ++-- frame/treasury/src/lib.rs | 58 +++++++++-------------------- frame/treasury/src/tests.rs | 5 +++ 5 files changed, 43 insertions(+), 46 deletions(-) diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index 9247d6f3215fb..056ec37641aac 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -93,6 +93,7 @@ use frame_support::{ traits::{ Currency, Get, LockableCurrency, LockIdentifier, ReservableCurrency, WithdrawReasons, ChangeMembers, OnUnbalanced, WithdrawReason, Contains, BalanceStatus, InitializeMembers, + ContainsCountUpperBound, } }; use sp_phragmen::{build_support_map, ExtendedBalance, VoteWeight, PhragmenResult}; @@ -878,6 +879,13 @@ impl Contains for Module { } } +/// Implementation uses a parameter type so calling is cost-free. +impl ContainsCountUpperBound for Module { + fn count_upper_bound() -> usize { + Self::desired_members() as usize + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/frame/support/src/traits.rs b/frame/support/src/traits.rs index 35e1231698a46..1513626622bd3 100644 --- a/frame/support/src/traits.rs +++ b/frame/support/src/traits.rs @@ -190,9 +190,7 @@ impl Get for () { fn get() -> T { T::default() } } -/// A trait for querying whether a type can be said to statically "contain" a value. Similar -/// in nature to `Get`, except it is designed to be lazy rather than active (you can't ask it to -/// enumerate all values that it contains) and work for multiple values rather than just one. +/// A trait for querying whether a type can be said to "contain" a value. pub trait Contains { /// Return `true` if this "contains" the given value `t`. fn contains(t: &T) -> bool { Self::sorted_members().binary_search(t).is_ok() } @@ -211,6 +209,13 @@ pub trait Contains { fn add(t: &T) { unimplemented!() } } +/// A trait for querying an upper bound on the number of element in a type that implements +/// `Contains`. +pub trait ContainsCountUpperBound { + /// An upper bound for the number of element contained. + fn count_upper_bound() -> usize; +} + /// Determiner to say whether a given account is unused. pub trait IsDeadAccount { /// Is the given account dead? diff --git a/frame/treasury/src/benchmarking.rs b/frame/treasury/src/benchmarking.rs index 8b8334f57eaaf..f901576c95d4b 100644 --- a/frame/treasury/src/benchmarking.rs +++ b/frame/treasury/src/benchmarking.rs @@ -107,6 +107,7 @@ fn create_approved_proposals(n: u32) -> Result<(), &'static str> { } const MAX_BYTES: u32 = 16384; +const MAX_TIPPERS: u32 = 100; benchmarks! { _ { } @@ -157,13 +158,13 @@ benchmarks! { tip_new { let r in 0 .. MAX_BYTES; - let t in 1 .. MAX_TIPPERS_COUNT; + let t in 1 .. MAX_TIPPERS; let (caller, reason, beneficiary, value) = setup_tip::(r, t)?; }: _(RawOrigin::Signed(caller), reason, beneficiary, value) tip { - let t in 1 .. MAX_TIPPERS_COUNT; + let t in 1 .. MAX_TIPPERS; let (member, reason, beneficiary, value) = setup_tip::(0, t)?; let value = T::Currency::minimum_balance().saturating_mul(100.into()); Treasury::::tip_new( @@ -180,7 +181,7 @@ benchmarks! { }: _(RawOrigin::Signed(caller), hash, value) close_tip { - let t in 1 .. MAX_TIPPERS_COUNT; + let t in 1 .. MAX_TIPPERS; // Make sure pot is funded let pot_account = Treasury::::account_id(); diff --git a/frame/treasury/src/lib.rs b/frame/treasury/src/lib.rs index eaea0341ffb36..0faf5078ad875 100644 --- a/frame/treasury/src/lib.rs +++ b/frame/treasury/src/lib.rs @@ -91,7 +91,6 @@ use serde::{Serialize, Deserialize}; use sp_std::prelude::*; use frame_support::{decl_module, decl_storage, decl_event, ensure, print, decl_error, Parameter}; -use frame_support::dispatch::DispatchResultWithPostInfo; use frame_support::traits::{ Currency, Get, Imbalance, OnUnbalanced, ExistenceRequirement::KeepAlive, ReservableCurrency, WithdrawReason @@ -100,7 +99,7 @@ use sp_runtime::{Permill, ModuleId, Percent, RuntimeDebug, traits::{ Zero, StaticLookup, AccountIdConversion, Saturating, Hash, BadOrigin }}; use frame_support::weights::Weight; -use frame_support::traits::{Contains, EnsureOrigin}; +use frame_support::traits::{Contains, ContainsCountUpperBound, EnsureOrigin}; use codec::{Encode, Decode}; use frame_system::{self as system, ensure_signed, ensure_root}; @@ -128,9 +127,10 @@ pub trait Trait: frame_system::Trait { type RejectOrigin: EnsureOrigin; /// Origin from which tippers must come. - /// The lenght must be less than [`MAX_TIPPERS_COUNT`](./constant.MAX_TIPPERS_COUNT.html). - /// Its cost it expected to be same as if it was stored sorted in a storage value. - type Tippers: Contains; + /// + /// `ContainsCountUpperBound::count_upper_bound` must be cost free. + /// (i.e. no storage read or heavy decoding) + type Tippers: Contains + ContainsCountUpperBound; /// The period for which a tip remains open after is has achieved threshold tippers. type TipCountdown: Get; @@ -333,11 +333,7 @@ decl_module! { /// - DbReads: `ProposalCount`, `sender account` /// - DbWrites: `ProposalCount`, `Proposals`, `sender account` /// # -<<<<<<< HEAD #[weight = 114_700_000 + T::DbWeight::get().reads_writes(1, 2)] -======= - #[weight = 500_000_000] ->>>>>>> origin/master fn propose_spend( origin, #[compact] value: BalanceOf, @@ -364,11 +360,7 @@ decl_module! { /// - DbReads: `Proposals`, `rejected proposer account` /// - DbWrites: `Proposals`, `rejected proposer account` /// # -<<<<<<< HEAD #[weight = 125_800_000 + T::DbWeight::get().reads_writes(2, 2)] -======= - #[weight = (100_000_000, DispatchClass::Operational)] ->>>>>>> origin/master fn reject_proposal(origin, #[compact] proposal_id: ProposalIndex) { T::RejectOrigin::try_origin(origin) .map(|_| ()) @@ -390,11 +382,7 @@ decl_module! { /// - DbReads: `Proposals`, `Approvals` /// - DbWrite: `Approvals` /// # -<<<<<<< HEAD #[weight = 33_610_000 + T::DbWeight::get().reads_writes(2, 1)] -======= - #[weight = (100_000_000, DispatchClass::Operational)] ->>>>>>> origin/master fn approve_proposal(origin, #[compact] proposal_id: ProposalIndex) { T::ApproveOrigin::try_origin(origin) .map(|_| ()) @@ -423,11 +411,7 @@ decl_module! { /// - DbReads: `Reasons`, `Tips`, `who account data` /// - DbWrites: `Tips`, `who account data` /// # -<<<<<<< HEAD #[weight = 138_400_000 + 4_000 * reason.len() as u64 + T::DbWeight::get().reads_writes(3, 2)] -======= - #[weight = 100_000_000] ->>>>>>> origin/master fn report_awesome(origin, reason: Vec, who: T::AccountId) { let finder = ensure_signed(origin)?; @@ -498,18 +482,17 @@ decl_module! { /// # /// - Complexity: `O(R + T)` where `R` length of `reason`, `T` is the number of tippers. /// - `O(T)`: decoding `Tipper` vec of length `T` - /// `T` is less than `MAX_TIPPERS_COUNT`, it is charged as maximum and then refund. + /// `T` is charged as upper bound given by `ContainsCountUpperBound`. /// The actual cost depends on the implementation of `T::Tippers`. /// - `O(R)`: hashing and encoding of reason of length `R` /// - DbReads: `Tippers`, `Reasons` /// - DbWrites: `Reasons`, `Tips` /// # - #[weight = 107_700_000 + 4_000 * reason.len() as u64 + 481_000 * MAX_TIPPERS_COUNT + #[weight = 107_700_000 + + 4_000 * reason.len() as u64 + + 481_000 * T::Tippers::count_upper_bound() as u64 + T::DbWeight::get().reads_writes(2, 2)] - fn tip_new(origin, reason: Vec, who: T::AccountId, tip_value: BalanceOf) - -> DispatchResultWithPostInfo - { - // NOTE: we don't refund in case of error because checking cost too much. + fn tip_new(origin, reason: Vec, who: T::AccountId, tip_value: BalanceOf) { let tipper = ensure_signed(origin)?; ensure!(T::Tippers::contains(&tipper), BadOrigin); let reason_hash = T::Hashing::hash(&reason[..]); @@ -521,8 +504,6 @@ decl_module! { let tips = vec![(tipper, tip_value)]; let tip = OpenTip { reason: reason_hash, who, finder: None, closes: None, tips }; Tips::::insert(&hash, tip); - - Ok(Some(MAX_TIPPERS_COUNT.saturating_sub(T::Tippers::count() as u64) * 481_000).into()) } /// Declare a tip value for an already-open tip. @@ -542,7 +523,7 @@ decl_module! { /// # /// - Complexity: `O(T)` where `T` is the number of tippers. /// decoding `Tipper` vec of length `T`, insert tip and check closing, - /// `T` is less than `MAX_TIPPERS_COUNT`, it is charged as maximum and then refund. + /// `T` is charged as upper bound given by `ContainsCountUpperBound`. /// The actual cost depends on the implementation of `T::Tippers`. /// /// Actually weight could be lower as it depends on how many tips are in `OpenTip` but it @@ -550,9 +531,9 @@ decl_module! { /// - DbReads: `Tippers`, `Tips` /// - DbWrites: `Tips` /// # - #[weight = 67_730_000 + 1_912_000 * MAX_TIPPERS_COUNT + T::DbWeight::get().reads_writes(2, 1)] - fn tip(origin, hash: T::Hash, tip_value: BalanceOf) -> DispatchResultWithPostInfo { - // NOTE: we don't refund in case of error because checking cost too much. + #[weight = 67_730_000 + 1_912_000 * T::Tippers::count_upper_bound() as u64 + + T::DbWeight::get().reads_writes(2, 1)] + fn tip(origin, hash: T::Hash, tip_value: BalanceOf) { let tipper = ensure_signed(origin)?; ensure!(T::Tippers::contains(&tipper), BadOrigin); @@ -561,8 +542,6 @@ decl_module! { Self::deposit_event(RawEvent::TipClosing(hash.clone())); } Tips::::insert(&hash, tip); - - Ok(Some(MAX_TIPPERS_COUNT.saturating_sub(T::Tippers::count() as u64) * 1_912_000).into()) } /// Close and payout a tip. @@ -577,13 +556,14 @@ decl_module! { /// # /// - Complexity: `O(T)` where `T` is the number of tippers. /// decoding `Tipper` vec of length `T`. - /// `T` is less than `MAX_TIPPERS_COUNT`, it is charged as maximum and then refund. + /// `T` is charged as upper bound given by `ContainsCountUpperBound`. /// The actual cost depends on the implementation of `T::Tippers`. /// - DbReads: `Tips`, `Tippers`, `tip finder` /// - DbWrites: `Reasons`, `Tips`, `Tippers`, `tip finder` /// # - #[weight = 211_000_000 + 1_094_000 * MAX_TIPPERS_COUNT + T::DbWeight::get().reads_writes(3, 3)] - fn close_tip(origin, hash: T::Hash) -> DispatchResultWithPostInfo { + #[weight = 211_000_000 + 1_094_000 * T::Tippers::count_upper_bound() as u64 + + T::DbWeight::get().reads_writes(3, 3)] + fn close_tip(origin, hash: T::Hash) { ensure_signed(origin)?; let tip = Tips::::get(hash).ok_or(Error::::UnknownTip)?; @@ -593,8 +573,6 @@ decl_module! { Reasons::::remove(&tip.reason); Tips::::remove(hash); Self::payout_tip(hash, tip); - - Ok(Some(MAX_TIPPERS_COUNT.saturating_sub(T::Tippers::count() as u64) * 1_094_000).into()) } /// # diff --git a/frame/treasury/src/tests.rs b/frame/treasury/src/tests.rs index 8752ba746b816..d02bbf32ee439 100644 --- a/frame/treasury/src/tests.rs +++ b/frame/treasury/src/tests.rs @@ -109,6 +109,11 @@ impl Contains for TenToFourteen { }) } } +impl ContainsCountUpperBound for TenToFourteen { + fn count_upper_bound() -> usize { + TEN_TO_FOURTEEN.with(|v| v.borrow().len()) + } +} parameter_types! { pub const ProposalBond: Permill = Permill::from_percent(5); pub const ProposalBondMinimum: u64 = 1; From fb289ccb6f8d20857045d6540b9a57ae478b16e3 Mon Sep 17 00:00:00 2001 From: thiolliere Date: Wed, 22 Apr 2020 10:41:33 +0200 Subject: [PATCH 05/12] rounding a bit --- frame/treasury/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frame/treasury/src/lib.rs b/frame/treasury/src/lib.rs index 0faf5078ad875..a8326b123f718 100644 --- a/frame/treasury/src/lib.rs +++ b/frame/treasury/src/lib.rs @@ -488,9 +488,9 @@ decl_module! { /// - DbReads: `Tippers`, `Reasons` /// - DbWrites: `Reasons`, `Tips` /// # - #[weight = 107_700_000 + #[weight = 110_000_000 + 4_000 * reason.len() as u64 - + 481_000 * T::Tippers::count_upper_bound() as u64 + + 480_000 * T::Tippers::count_upper_bound() as u64 + T::DbWeight::get().reads_writes(2, 2)] fn tip_new(origin, reason: Vec, who: T::AccountId, tip_value: BalanceOf) { let tipper = ensure_signed(origin)?; @@ -531,7 +531,7 @@ decl_module! { /// - DbReads: `Tippers`, `Tips` /// - DbWrites: `Tips` /// # - #[weight = 67_730_000 + 1_912_000 * T::Tippers::count_upper_bound() as u64 + #[weight = 68_000_000 + 1_900_000 * T::Tippers::count_upper_bound() as u64 + T::DbWeight::get().reads_writes(2, 1)] fn tip(origin, hash: T::Hash, tip_value: BalanceOf) { let tipper = ensure_signed(origin)?; @@ -561,7 +561,7 @@ decl_module! { /// - DbReads: `Tips`, `Tippers`, `tip finder` /// - DbWrites: `Reasons`, `Tips`, `Tippers`, `tip finder` /// # - #[weight = 211_000_000 + 1_094_000 * T::Tippers::count_upper_bound() as u64 + #[weight = 210_000_000 + 1_100_000 * T::Tippers::count_upper_bound() as u64 + T::DbWeight::get().reads_writes(3, 3)] fn close_tip(origin, hash: T::Hash) { ensure_signed(origin)?; @@ -587,7 +587,7 @@ decl_module! { if (n % T::SpendPeriod::get()).is_zero() { let approvals_len = Self::spend_funds(); - 263_500_000 * approvals_len + 260_000_000 * approvals_len + T::DbWeight::get().reads_writes(2 + approvals_len * 3, 2 + approvals_len * 3) } else { 0 From 8d2ccad6b0874b492c1eea00fe8ae77a202ca397 Mon Sep 17 00:00:00 2001 From: thiolliere Date: Wed, 22 Apr 2020 10:46:29 +0200 Subject: [PATCH 06/12] remove unused + doc --- frame/treasury/src/lib.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/frame/treasury/src/lib.rs b/frame/treasury/src/lib.rs index a8326b123f718..55a35db12cfe5 100644 --- a/frame/treasury/src/lib.rs +++ b/frame/treasury/src/lib.rs @@ -113,9 +113,6 @@ type NegativeImbalanceOf = <::Currency as Currency< + ReservableCurrency; @@ -129,7 +126,7 @@ pub trait Trait: frame_system::Trait { /// Origin from which tippers must come. /// /// `ContainsCountUpperBound::count_upper_bound` must be cost free. - /// (i.e. no storage read or heavy decoding) + /// (i.e. no storage read or heavy operation) type Tippers: Contains + ContainsCountUpperBound; /// The period for which a tip remains open after is has achieved threshold tippers. From fb0edfcdf058ccdfb7b9ef13307670bbc7511994 Mon Sep 17 00:00:00 2001 From: thiolliere Date: Wed, 22 Apr 2020 11:34:18 +0200 Subject: [PATCH 07/12] as u64 -> as Weight --- frame/treasury/src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frame/treasury/src/lib.rs b/frame/treasury/src/lib.rs index 55a35db12cfe5..88c2cecfc96e8 100644 --- a/frame/treasury/src/lib.rs +++ b/frame/treasury/src/lib.rs @@ -408,7 +408,7 @@ decl_module! { /// - DbReads: `Reasons`, `Tips`, `who account data` /// - DbWrites: `Tips`, `who account data` /// # - #[weight = 138_400_000 + 4_000 * reason.len() as u64 + T::DbWeight::get().reads_writes(3, 2)] + #[weight = 138_400_000 + 4_000 * reason.len() as Weight + T::DbWeight::get().reads_writes(3, 2)] fn report_awesome(origin, reason: Vec, who: T::AccountId) { let finder = ensure_signed(origin)?; @@ -486,8 +486,8 @@ decl_module! { /// - DbWrites: `Reasons`, `Tips` /// # #[weight = 110_000_000 - + 4_000 * reason.len() as u64 - + 480_000 * T::Tippers::count_upper_bound() as u64 + + 4_000 * reason.len() as Weight + + 480_000 * T::Tippers::count_upper_bound() as Weight + T::DbWeight::get().reads_writes(2, 2)] fn tip_new(origin, reason: Vec, who: T::AccountId, tip_value: BalanceOf) { let tipper = ensure_signed(origin)?; @@ -528,7 +528,7 @@ decl_module! { /// - DbReads: `Tippers`, `Tips` /// - DbWrites: `Tips` /// # - #[weight = 68_000_000 + 1_900_000 * T::Tippers::count_upper_bound() as u64 + #[weight = 68_000_000 + 1_900_000 * T::Tippers::count_upper_bound() as Weight + T::DbWeight::get().reads_writes(2, 1)] fn tip(origin, hash: T::Hash, tip_value: BalanceOf) { let tipper = ensure_signed(origin)?; @@ -558,7 +558,7 @@ decl_module! { /// - DbReads: `Tips`, `Tippers`, `tip finder` /// - DbWrites: `Reasons`, `Tips`, `Tippers`, `tip finder` /// # - #[weight = 210_000_000 + 1_100_000 * T::Tippers::count_upper_bound() as u64 + #[weight = 210_000_000 + 1_100_000 * T::Tippers::count_upper_bound() as Weight + T::DbWeight::get().reads_writes(3, 3)] fn close_tip(origin, hash: T::Hash) { ensure_signed(origin)?; @@ -584,7 +584,7 @@ decl_module! { if (n % T::SpendPeriod::get()).is_zero() { let approvals_len = Self::spend_funds(); - 260_000_000 * approvals_len + 265_000_000 * approvals_len + T::DbWeight::get().reads_writes(2 + approvals_len * 3, 2 + approvals_len * 3) } else { 0 From 60fd98a53e5e2fbda6d2308da84ce4af4143908e Mon Sep 17 00:00:00 2001 From: thiolliere Date: Wed, 22 Apr 2020 11:40:20 +0200 Subject: [PATCH 08/12] 2 significative digits rounded up --- frame/treasury/src/lib.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/frame/treasury/src/lib.rs b/frame/treasury/src/lib.rs index 88c2cecfc96e8..42925db6408fa 100644 --- a/frame/treasury/src/lib.rs +++ b/frame/treasury/src/lib.rs @@ -330,7 +330,7 @@ decl_module! { /// - DbReads: `ProposalCount`, `sender account` /// - DbWrites: `ProposalCount`, `Proposals`, `sender account` /// # - #[weight = 114_700_000 + T::DbWeight::get().reads_writes(1, 2)] + #[weight = 120_000_000 + T::DbWeight::get().reads_writes(1, 2)] fn propose_spend( origin, #[compact] value: BalanceOf, @@ -357,7 +357,7 @@ decl_module! { /// - DbReads: `Proposals`, `rejected proposer account` /// - DbWrites: `Proposals`, `rejected proposer account` /// # - #[weight = 125_800_000 + T::DbWeight::get().reads_writes(2, 2)] + #[weight = 130_000_000 + T::DbWeight::get().reads_writes(2, 2)] fn reject_proposal(origin, #[compact] proposal_id: ProposalIndex) { T::RejectOrigin::try_origin(origin) .map(|_| ()) @@ -379,7 +379,7 @@ decl_module! { /// - DbReads: `Proposals`, `Approvals` /// - DbWrite: `Approvals` /// # - #[weight = 33_610_000 + T::DbWeight::get().reads_writes(2, 1)] + #[weight = 34_000_000 + T::DbWeight::get().reads_writes(2, 1)] fn approve_proposal(origin, #[compact] proposal_id: ProposalIndex) { T::ApproveOrigin::try_origin(origin) .map(|_| ()) @@ -408,7 +408,7 @@ decl_module! { /// - DbReads: `Reasons`, `Tips`, `who account data` /// - DbWrites: `Tips`, `who account data` /// # - #[weight = 138_400_000 + 4_000 * reason.len() as Weight + T::DbWeight::get().reads_writes(3, 2)] + #[weight = 140_000_000 + 4_000 * reason.len() as Weight + T::DbWeight::get().reads_writes(3, 2)] fn report_awesome(origin, reason: Vec, who: T::AccountId) { let finder = ensure_signed(origin)?; @@ -450,7 +450,7 @@ decl_module! { /// - DbReads: `Tips`, `sender account data` /// - DbWrites: `Reasons`, `Tips`, `sender account data` /// # - #[weight = 115_700_000 + T::DbWeight::get().reads_writes(1, 2)] + #[weight = 120_000_000 + T::DbWeight::get().reads_writes(1, 2)] fn retract_tip(origin, hash: T::Hash) { let who = ensure_signed(origin)?; let tip = Tips::::get(&hash).ok_or(Error::::UnknownTip)?; @@ -528,7 +528,7 @@ decl_module! { /// - DbReads: `Tippers`, `Tips` /// - DbWrites: `Tips` /// # - #[weight = 68_000_000 + 1_900_000 * T::Tippers::count_upper_bound() as Weight + #[weight = 68_000_000 + 2_000_000 * T::Tippers::count_upper_bound() as Weight + T::DbWeight::get().reads_writes(2, 1)] fn tip(origin, hash: T::Hash, tip_value: BalanceOf) { let tipper = ensure_signed(origin)?; @@ -558,7 +558,7 @@ decl_module! { /// - DbReads: `Tips`, `Tippers`, `tip finder` /// - DbWrites: `Reasons`, `Tips`, `Tippers`, `tip finder` /// # - #[weight = 210_000_000 + 1_100_000 * T::Tippers::count_upper_bound() as Weight + #[weight = 220_000_000 + 1_100_000 * T::Tippers::count_upper_bound() as Weight + T::DbWeight::get().reads_writes(3, 3)] fn close_tip(origin, hash: T::Hash) { ensure_signed(origin)?; @@ -584,7 +584,7 @@ decl_module! { if (n % T::SpendPeriod::get()).is_zero() { let approvals_len = Self::spend_funds(); - 265_000_000 * approvals_len + 270_000_000 * approvals_len + T::DbWeight::get().reads_writes(2 + approvals_len * 3, 2 + approvals_len * 3) } else { 0 From 952afa85bc52f7bf9972c3f69f8057dcffdb6294 Mon Sep 17 00:00:00 2001 From: thiolliere Date: Wed, 22 Apr 2020 11:48:20 +0200 Subject: [PATCH 09/12] rename ContainsCountUpperBound -> ContainsLengthBound --- frame/elections-phragmen/src/lib.rs | 10 ++++++---- frame/support/src/traits.rs | 9 ++++----- frame/treasury/src/lib.rs | 19 +++++++++---------- frame/treasury/src/tests.rs | 5 +++-- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/frame/elections-phragmen/src/lib.rs b/frame/elections-phragmen/src/lib.rs index 056ec37641aac..6c9f092c34e1d 100644 --- a/frame/elections-phragmen/src/lib.rs +++ b/frame/elections-phragmen/src/lib.rs @@ -93,7 +93,7 @@ use frame_support::{ traits::{ Currency, Get, LockableCurrency, LockIdentifier, ReservableCurrency, WithdrawReasons, ChangeMembers, OnUnbalanced, WithdrawReason, Contains, BalanceStatus, InitializeMembers, - ContainsCountUpperBound, + ContainsLengthBound, } }; use sp_phragmen::{build_support_map, ExtendedBalance, VoteWeight, PhragmenResult}; @@ -879,9 +879,11 @@ impl Contains for Module { } } -/// Implementation uses a parameter type so calling is cost-free. -impl ContainsCountUpperBound for Module { - fn count_upper_bound() -> usize { +impl ContainsLengthBound for Module { + fn min_len() -> usize { 0 } + + /// Implementation uses a parameter type so calling is cost-free. + fn max_len() -> usize { Self::desired_members() as usize } } diff --git a/frame/support/src/traits.rs b/frame/support/src/traits.rs index 1513626622bd3..35f8d38ae73d5 100644 --- a/frame/support/src/traits.rs +++ b/frame/support/src/traits.rs @@ -209,11 +209,10 @@ pub trait Contains { fn add(t: &T) { unimplemented!() } } -/// A trait for querying an upper bound on the number of element in a type that implements -/// `Contains`. -pub trait ContainsCountUpperBound { - /// An upper bound for the number of element contained. - fn count_upper_bound() -> usize; +/// A trait for querying bound for the length of an implementation of `Contains` +pub trait ContainsLengthBound { + fn min_len() -> usize; + fn max_len() -> usize; } /// Determiner to say whether a given account is unused. diff --git a/frame/treasury/src/lib.rs b/frame/treasury/src/lib.rs index 42925db6408fa..e08346db0c197 100644 --- a/frame/treasury/src/lib.rs +++ b/frame/treasury/src/lib.rs @@ -99,7 +99,7 @@ use sp_runtime::{Permill, ModuleId, Percent, RuntimeDebug, traits::{ Zero, StaticLookup, AccountIdConversion, Saturating, Hash, BadOrigin }}; use frame_support::weights::Weight; -use frame_support::traits::{Contains, ContainsCountUpperBound, EnsureOrigin}; +use frame_support::traits::{Contains, ContainsLengthBound, EnsureOrigin}; use codec::{Encode, Decode}; use frame_system::{self as system, ensure_signed, ensure_root}; @@ -125,9 +125,8 @@ pub trait Trait: frame_system::Trait { /// Origin from which tippers must come. /// - /// `ContainsCountUpperBound::count_upper_bound` must be cost free. - /// (i.e. no storage read or heavy operation) - type Tippers: Contains + ContainsCountUpperBound; + /// `ContainsLengthBound::max_len` must be cost free (i.e. no storage read or heavy operation). + type Tippers: Contains + ContainsLengthBound; /// The period for which a tip remains open after is has achieved threshold tippers. type TipCountdown: Get; @@ -479,7 +478,7 @@ decl_module! { /// # /// - Complexity: `O(R + T)` where `R` length of `reason`, `T` is the number of tippers. /// - `O(T)`: decoding `Tipper` vec of length `T` - /// `T` is charged as upper bound given by `ContainsCountUpperBound`. + /// `T` is charged as upper bound given by `ContainsLengthBound`. /// The actual cost depends on the implementation of `T::Tippers`. /// - `O(R)`: hashing and encoding of reason of length `R` /// - DbReads: `Tippers`, `Reasons` @@ -487,7 +486,7 @@ decl_module! { /// # #[weight = 110_000_000 + 4_000 * reason.len() as Weight - + 480_000 * T::Tippers::count_upper_bound() as Weight + + 480_000 * T::Tippers::max_len() as Weight + T::DbWeight::get().reads_writes(2, 2)] fn tip_new(origin, reason: Vec, who: T::AccountId, tip_value: BalanceOf) { let tipper = ensure_signed(origin)?; @@ -520,7 +519,7 @@ decl_module! { /// # /// - Complexity: `O(T)` where `T` is the number of tippers. /// decoding `Tipper` vec of length `T`, insert tip and check closing, - /// `T` is charged as upper bound given by `ContainsCountUpperBound`. + /// `T` is charged as upper bound given by `ContainsLengthBound`. /// The actual cost depends on the implementation of `T::Tippers`. /// /// Actually weight could be lower as it depends on how many tips are in `OpenTip` but it @@ -528,7 +527,7 @@ decl_module! { /// - DbReads: `Tippers`, `Tips` /// - DbWrites: `Tips` /// # - #[weight = 68_000_000 + 2_000_000 * T::Tippers::count_upper_bound() as Weight + #[weight = 68_000_000 + 2_000_000 * T::Tippers::max_len() as Weight + T::DbWeight::get().reads_writes(2, 1)] fn tip(origin, hash: T::Hash, tip_value: BalanceOf) { let tipper = ensure_signed(origin)?; @@ -553,12 +552,12 @@ decl_module! { /// # /// - Complexity: `O(T)` where `T` is the number of tippers. /// decoding `Tipper` vec of length `T`. - /// `T` is charged as upper bound given by `ContainsCountUpperBound`. + /// `T` is charged as upper bound given by `ContainsLengthBound`. /// The actual cost depends on the implementation of `T::Tippers`. /// - DbReads: `Tips`, `Tippers`, `tip finder` /// - DbWrites: `Reasons`, `Tips`, `Tippers`, `tip finder` /// # - #[weight = 220_000_000 + 1_100_000 * T::Tippers::count_upper_bound() as Weight + #[weight = 220_000_000 + 1_100_000 * T::Tippers::max_len() as Weight + T::DbWeight::get().reads_writes(3, 3)] fn close_tip(origin, hash: T::Hash) { ensure_signed(origin)?; diff --git a/frame/treasury/src/tests.rs b/frame/treasury/src/tests.rs index d02bbf32ee439..46f3153c418d1 100644 --- a/frame/treasury/src/tests.rs +++ b/frame/treasury/src/tests.rs @@ -109,10 +109,11 @@ impl Contains for TenToFourteen { }) } } -impl ContainsCountUpperBound for TenToFourteen { - fn count_upper_bound() -> usize { +impl ContainsLengthBound for TenToFourteen { + fn max_len() -> usize { TEN_TO_FOURTEEN.with(|v| v.borrow().len()) } + fn min_len() -> usize { 0 } } parameter_types! { pub const ProposalBond: Permill = Permill::from_percent(5); From 73d5df2b346aaa864e5b07ec99715914a167d6a6 Mon Sep 17 00:00:00 2001 From: thiolliere Date: Wed, 22 Apr 2020 11:53:33 +0200 Subject: [PATCH 10/12] add doc --- frame/support/src/traits.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frame/support/src/traits.rs b/frame/support/src/traits.rs index 35f8d38ae73d5..85d74756b4de4 100644 --- a/frame/support/src/traits.rs +++ b/frame/support/src/traits.rs @@ -211,7 +211,9 @@ pub trait Contains { /// A trait for querying bound for the length of an implementation of `Contains` pub trait ContainsLengthBound { + /// Minimum number of elements contained fn min_len() -> usize; + /// Maximum number of elements contained fn max_len() -> usize; } From 753e32cd1405f668a553054fffbb3fdff7a7ae42 Mon Sep 17 00:00:00 2001 From: thiolliere Date: Wed, 22 Apr 2020 12:00:20 +0200 Subject: [PATCH 11/12] sender account -> origin account --- frame/treasury/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frame/treasury/src/lib.rs b/frame/treasury/src/lib.rs index e08346db0c197..8641f5f03ca80 100644 --- a/frame/treasury/src/lib.rs +++ b/frame/treasury/src/lib.rs @@ -326,8 +326,8 @@ decl_module! { /// /// # /// - Complexity: O(1) - /// - DbReads: `ProposalCount`, `sender account` - /// - DbWrites: `ProposalCount`, `Proposals`, `sender account` + /// - DbReads: `ProposalCount`, `origin account` + /// - DbWrites: `ProposalCount`, `Proposals`, `origin account` /// # #[weight = 120_000_000 + T::DbWeight::get().reads_writes(1, 2)] fn propose_spend( @@ -446,8 +446,8 @@ decl_module! { /// # /// - Complexity: `O(1)` /// - Depends on the length of `T::Hash` which is fixed. - /// - DbReads: `Tips`, `sender account data` - /// - DbWrites: `Reasons`, `Tips`, `sender account data` + /// - DbReads: `Tips`, `origin account` + /// - DbWrites: `Reasons`, `Tips`, `origin account` /// # #[weight = 120_000_000 + T::DbWeight::get().reads_writes(1, 2)] fn retract_tip(origin, hash: T::Hash) { From ea3a255a8952236b2a00f54b0b277abc71cbc835 Mon Sep 17 00:00:00 2001 From: thiolliere Date: Mon, 27 Apr 2020 18:02:20 +0200 Subject: [PATCH 12/12] fix --- frame/treasury/src/lib.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/frame/treasury/src/lib.rs b/frame/treasury/src/lib.rs index 8c8074c102017..270a710a2c29e 100644 --- a/frame/treasury/src/lib.rs +++ b/frame/treasury/src/lib.rs @@ -98,13 +98,8 @@ use frame_support::traits::{ use sp_runtime::{Permill, ModuleId, Percent, RuntimeDebug, traits::{ Zero, StaticLookup, AccountIdConversion, Saturating, Hash, BadOrigin }}; -<<<<<<< HEAD -use frame_support::weights::Weight; -use frame_support::traits::{Contains, ContainsLengthBound, EnsureOrigin}; -======= use frame_support::weights::{Weight, DispatchClass}; -use frame_support::traits::{Contains, EnsureOrigin}; ->>>>>>> origin/master +use frame_support::traits::{Contains, ContainsLengthBound, EnsureOrigin}; use codec::{Encode, Decode}; use frame_system::{self as system, ensure_signed, ensure_root}; @@ -364,7 +359,7 @@ decl_module! { /// - DbReads: `Proposals`, `rejected proposer account` /// - DbWrites: `Proposals`, `rejected proposer account` /// # - #[weight = 130_000_000 + T::DbWeight::get().reads_writes(2, 2)] + #[weight = (130_000_000 + T::DbWeight::get().reads_writes(2, 2), DispatchClass::Operational)] fn reject_proposal(origin, #[compact] proposal_id: ProposalIndex) { T::RejectOrigin::try_origin(origin) .map(|_| ()) @@ -386,7 +381,7 @@ decl_module! { /// - DbReads: `Proposals`, `Approvals` /// - DbWrite: `Approvals` /// # - #[weight = 34_000_000 + T::DbWeight::get().reads_writes(2, 1)] + #[weight = (34_000_000 + T::DbWeight::get().reads_writes(2, 1), DispatchClass::Operational)] fn approve_proposal(origin, #[compact] proposal_id: ProposalIndex) { T::ApproveOrigin::try_origin(origin) .map(|_| ())