This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Update treasury weights. #5723
Merged
Merged
Update treasury weights. #5723
Changes from 7 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9eb2c49
treasury weight formula
gui1117 652ba4b
use max tippers count
gui1117 d20cbc0
doc
gui1117 e0fa300
Merge remote-tracking branch 'origin/master' into gui-treasury-weight
gui1117 a53b4d0
Fix upper bound
gui1117 fb289cc
rounding a bit
gui1117 8d2ccad
remove unused + doc
gui1117 fb0edfc
as u64 -> as Weight
gui1117 60fd98a
2 significative digits rounded up
gui1117 952afa8
rename ContainsCountUpperBound -> ContainsLengthBound
gui1117 73d5df2
add doc
gui1117 753e32c
sender account -> origin account
gui1117 166efe5
Merge remote-tracking branch 'origin/master' into gui-treasury-weight
gui1117 ea3a255
fix
gui1117 e0f5773
Merge remote-tracking branch 'origin/master' into gui-treasury-weight
gui1117 c03e1b0
Merge remote-tracking branch 'origin/master' into gui-treasury-weight
gui1117 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,8 +98,8 @@ 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, DispatchClass}; | ||
| use frame_support::traits::{Contains, EnsureOrigin}; | ||
| use frame_support::weights::Weight; | ||
| use frame_support::traits::{Contains, ContainsCountUpperBound, EnsureOrigin}; | ||
| use codec::{Encode, Decode}; | ||
| use frame_system::{self as system, ensure_signed, ensure_root}; | ||
|
|
||
|
|
@@ -124,7 +124,10 @@ pub trait Trait: frame_system::Trait { | |
| type RejectOrigin: EnsureOrigin<Self::Origin>; | ||
|
|
||
| /// Origin from which tippers must come. | ||
| type Tippers: Contains<Self::AccountId>; | ||
| /// | ||
| /// `ContainsCountUpperBound::count_upper_bound` must be cost free. | ||
| /// (i.e. no storage read or heavy operation) | ||
| type Tippers: Contains<Self::AccountId> + ContainsCountUpperBound; | ||
|
|
||
| /// The period for which a tip remains open after is has achieved threshold tippers. | ||
| type TipCountdown: Get<Self::BlockNumber>; | ||
|
|
@@ -323,11 +326,11 @@ decl_module! { | |
| /// proposal is awarded. | ||
| /// | ||
| /// # <weight> | ||
| /// - 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> | ||
| #[weight = 500_000_000] | ||
| #[weight = 114_700_000 + T::DbWeight::get().reads_writes(1, 2)] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so can you bring me up to speed, where are these numbers coming from? the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this number directly comes from the benchmark server at https://www.shawntabrizi.com/substrate-graph-benchmarks/?p=treasury&e=tip_new |
||
| fn propose_spend( | ||
| origin, | ||
| #[compact] value: BalanceOf<T>, | ||
|
|
@@ -350,11 +353,11 @@ decl_module! { | |
| /// Reject a proposed spend. The original deposit will be slashed. | ||
| /// | ||
| /// # <weight> | ||
| /// - O(1). | ||
| /// - Limited storage reads. | ||
| /// - One DB clear. | ||
| /// - Complexity: O(1) | ||
| /// - DbReads: `Proposals`, `rejected proposer account` | ||
| /// - DbWrites: `Proposals`, `rejected proposer account` | ||
| /// # </weight> | ||
| #[weight = (100_000_000, DispatchClass::Operational)] | ||
| #[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 +375,11 @@ decl_module! { | |
| /// and the original deposit will be returned. | ||
| /// | ||
| /// # <weight> | ||
| /// - O(1). | ||
| /// - Limited storage reads. | ||
| /// - One DB change. | ||
| /// - Complexity: O(1). | ||
| /// - DbReads: `Proposals`, `Approvals` | ||
| /// - DbWrite: `Approvals` | ||
| /// # </weight> | ||
| #[weight = (100_000_000, DispatchClass::Operational)] | ||
| #[weight = 33_610_000 + T::DbWeight::get().reads_writes(2, 1)] | ||
|
apopiak marked this conversation as resolved.
Outdated
|
||
| fn approve_proposal(origin, #[compact] proposal_id: ProposalIndex) { | ||
| T::ApproveOrigin::try_origin(origin) | ||
| .map(|_| ()) | ||
|
|
@@ -400,12 +403,12 @@ decl_module! { | |
| /// Emits `NewTip` if successful. | ||
| /// | ||
| /// # <weight> | ||
| /// - `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> | ||
| #[weight = 100_000_000] | ||
| #[weight = 138_400_000 + 4_000 * reason.len() as u64 + T::DbWeight::get().reads_writes(3, 2)] | ||
|
apopiak marked this conversation as resolved.
Outdated
gui1117 marked this conversation as resolved.
Outdated
|
||
| fn report_awesome(origin, reason: Vec<u8>, who: T::AccountId) { | ||
| let finder = ensure_signed(origin)?; | ||
|
|
||
|
|
@@ -442,12 +445,12 @@ decl_module! { | |
| /// Emits `TipRetracted` if successful. | ||
| /// | ||
| /// # <weight> | ||
| /// - `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> | ||
| #[weight = 50_000_000] | ||
| #[weight = 115_700_000 + T::DbWeight::get().reads_writes(1, 2)] | ||
|
apopiak marked this conversation as resolved.
Outdated
|
||
| fn retract_tip(origin, hash: T::Hash) { | ||
| let who = ensure_signed(origin)?; | ||
| let tip = Tips::<T>::get(&hash).ok_or(Error::<T>::UnknownTip)?; | ||
|
|
@@ -474,12 +477,18 @@ decl_module! { | |
| /// Emits `NewTip` if successful. | ||
| /// | ||
| /// # <weight> | ||
| /// - `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 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> | ||
| #[weight = 150_000_000] | ||
| #[weight = 110_000_000 | ||
| + 4_000 * reason.len() as u64 | ||
|
apopiak marked this conversation as resolved.
Outdated
gui1117 marked this conversation as resolved.
Outdated
|
||
| + 480_000 * T::Tippers::count_upper_bound() as u64 | ||
| + T::DbWeight::get().reads_writes(2, 2)] | ||
| fn tip_new(origin, reason: Vec<u8>, who: T::AccountId, tip_value: BalanceOf<T>) { | ||
| let tipper = ensure_signed(origin)?; | ||
| ensure!(T::Tippers::contains(&tipper), BadOrigin); | ||
|
|
@@ -509,11 +518,18 @@ decl_module! { | |
| /// has started. | ||
| /// | ||
| /// # <weight> | ||
| /// - `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 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 | ||
| /// is weighted as if almost full i.e of length `T-1`. | ||
| /// - DbReads: `Tippers`, `Tips` | ||
| /// - DbWrites: `Tips` | ||
| /// # </weight> | ||
| #[weight = 50_000_000] | ||
| #[weight = 68_000_000 + 1_900_000 * T::Tippers::count_upper_bound() as u64 | ||
|
gui1117 marked this conversation as resolved.
Outdated
|
||
| + T::DbWeight::get().reads_writes(2, 1)] | ||
| fn tip(origin, hash: T::Hash, tip_value: BalanceOf<T>) { | ||
| let tipper = ensure_signed(origin)?; | ||
| ensure!(T::Tippers::contains(&tipper), BadOrigin); | ||
|
|
@@ -535,11 +551,15 @@ decl_module! { | |
| /// as the hash of the tuple of the original tip `reason` and the beneficiary account ID. | ||
| /// | ||
| /// # <weight> | ||
| /// - `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 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> | ||
| #[weight = 50_000_000] | ||
| #[weight = 210_000_000 + 1_100_000 * T::Tippers::count_upper_bound() as u64 | ||
|
gui1117 marked this conversation as resolved.
Outdated
|
||
| + T::DbWeight::get().reads_writes(3, 3)] | ||
| fn close_tip(origin, hash: T::Hash) { | ||
| ensure_signed(origin)?; | ||
|
|
||
|
|
@@ -552,13 +572,23 @@ decl_module! { | |
| Self::payout_tip(hash, tip); | ||
| } | ||
|
|
||
| /// # <weight> | ||
| /// - 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` | ||
| /// - The weight is overestimated if some approvals got missed. | ||
| /// # </weight> | ||
| 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 | ||
| 260_000_000 * approvals_len | ||
|
gui1117 marked this conversation as resolved.
Outdated
|
||
| + T::DbWeight::get().reads_writes(2 + approvals_len * 3, 2 + approvals_len * 3) | ||
| } else { | ||
| 0 | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -650,14 +680,15 @@ impl<T: Trait> Module<T> { | |
| 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 = <PositiveImbalanceOf<T>>::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 +712,7 @@ impl<T: Trait> Module<T> { | |
| false | ||
| } | ||
| }); | ||
| prior_approvals_len | ||
| }); | ||
|
|
||
| if !missed_any { | ||
|
|
@@ -707,6 +739,8 @@ impl<T: Trait> Module<T> { | |
| } | ||
|
|
||
| Self::deposit_event(RawEvent::Rollover(budget_remaining)); | ||
|
|
||
| prior_approvals_len | ||
| } | ||
|
|
||
| /// Return the amount of money in the pot. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.