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.7k
Pallets: Treasury spend() should use Pay trait
#13607
Closed
Closed
Changes from all commits
Commits
Show all changes
72 commits
Select commit
Hold shift + click to select a range
a027594
pallet_treasury: implement treasury pallet over the pay trait in pall…
tonyalaribe 29194c3
update the new spend logic to exist parallel to original spend logic
tonyalaribe 11cd988
clean up imports diffs
tonyalaribe 57aacbe
switch to using the pay trait in frame support
tonyalaribe 67b9f7a
remove the changes to the build genesis config method
tonyalaribe 2b20924
fix some type errors
tonyalaribe 3602844
add a test for the new spend workflow
tonyalaribe dd99d7c
implement initial tests for the new spend workflow
tonyalaribe 5f52015
remove unneeded Balance type from Confg
tonyalaribe 1925806
Update lib.rs
tonyalaribe f94e20a
introduce a unit implementation for BalanceConversion which behaves a…
tonyalaribe 293552f
Merge branch 'aa/multi-asset-support-in-treasury' of github.com:parit…
tonyalaribe a88fb24
Merge branch 'master' into aa/multi-asset-support-in-treasury
tonyalaribe 3aaed66
fix rebase introduced error
tonyalaribe a33d4dc
fix broken tests due to rebase
tonyalaribe 414e8e2
fix tests in tips and bounties
tonyalaribe 2f60a1b
fix lint error for unused fn argument in Pay trait
tonyalaribe 182c733
fix tests in child-bounties pallet
tonyalaribe 0916aff
remove unneeded DummyBalanceConverter
tonyalaribe fdcd66a
Update frame/bounties/src/tests.rs
tonyalaribe 5673e79
Update frame/bounties/src/tests.rs
tonyalaribe c6f9c5a
Update frame/treasury/src/lib.rs
tonyalaribe bb372a2
tiny cleanups
tonyalaribe a56897d
rename asset_id to asset_kind and proposal
tonyalaribe 69cc489
Merge branch 'aa/multi-asset-support-in-treasury' of github.com:parit…
tonyalaribe e07ee86
Update frame/treasury/src/lib.rs
tonyalaribe 304f536
implememt PR feedback
tonyalaribe e7ecdbf
update doc comments
tonyalaribe e689272
Merge branch 'aa/multi-asset-support-in-treasury' of github.com:parit…
tonyalaribe 3cd5760
include correct weight funchtion
tonyalaribe d97886d
add spend_local to weight.rs
tonyalaribe 805d595
benchmarking updates
tonyalaribe bbf83fa
rename Treasury1Account to TreasuryAccount1
tonyalaribe 8aa1c3c
update PendingPayment storage comment
tonyalaribe aabfadf
update PendingPayment storage comment
tonyalaribe 592b81b
adjust naming of Events to not mix PendingPayment and Proposal concepts
tonyalaribe b295ea7
adjust tests to check more cases
tonyalaribe 1e85a67
benchmarking update
tonyalaribe eb4b2fe
make benchmarks pass
tonyalaribe 1fdccb7
Merge remote-tracking branch 'origin/master' into aa/multi-asset-supp…
310578d
update BalanceConverter to use ConversionFromAssetBalance trait
tonyalaribe 22e43a1
Add BenchmarkHelper to runtimes in dependent pallets
tonyalaribe d96d541
Update frame/treasury/src/lib.rs
tonyalaribe dc891cb
Update frame/treasury/src/lib.rs
tonyalaribe 3bd3c8e
add benchmark helper to tips
tonyalaribe 1018464
Merge branch 'aa/multi-asset-support-in-treasury' of github.com:parit…
tonyalaribe c04955d
add From<u32> for ()
tonyalaribe b5b5d0e
introduce NilBenchmarkHelper for unit asset ids
tonyalaribe 65c71a0
remove comment
tonyalaribe 62b0901
Merge remote-tracking branch 'origin/master' into aa/multi-asset-supp…
5750f0b
add debug log for pay errors; Pay trait should support an error type
tonyalaribe e26dee6
add error associated type to Salary pallet test pay impl
tonyalaribe 0739c29
fix fmt error
tonyalaribe ac27c84
Merge remote-tracking branch 'origin/master' into aa/multi-asset-supp…
87b905c
Trigger CI
tonyalaribe 5bc0af9
Trigger CI
tonyalaribe 1fca0e9
add a debug log for when Paymaster::check_payment returns failure
tonyalaribe 7d712e2
add payment_id to events
tonyalaribe db02823
Merge remote-tracking branch 'origin/master' into aa/multi-asset-supp…
415561d
Trigger companion CI
tonyalaribe 449d484
Trigger companion CI
tonyalaribe 4741037
Trigger Companion CI
tonyalaribe 9cad108
Trigger Companion CI
tonyalaribe b644329
Trigger Companion CI
tonyalaribe 8a9903b
Trigger Companion CI
tonyalaribe f07e8b0
Trigger Companion CI
tonyalaribe 34c859b
support vector of assets for treasury spend
tonyalaribe 9237568
Merge branch 'master' into aa/multi-asset-support-in-treasury
tonyalaribe 1ecd8cc
Merge branch 'aa/multi-asset-support-in-treasury' of github.com:parit…
tonyalaribe c029123
fix types on child-bounties and tips
tonyalaribe 83a2097
switch node template to use SimpleAsset
tonyalaribe d79cab0
Merge branch 'master' into aa/multi-asset-support-in-treasury
gavofyork 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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 |
|---|---|---|
|
|
@@ -31,6 +31,10 @@ use frame_system::RawOrigin; | |
|
|
||
| const SEED: u32 = 0; | ||
|
|
||
| fn default_asset_kind<T: Config<I>, I: 'static>() -> T::AssetKind { | ||
| T::BenchmarkHelper::create_asset_kind(0) | ||
| } | ||
|
|
||
| // Create the pre-requisite information needed to create a treasury `propose_spend`. | ||
| fn setup_proposal<T: Config<I>, I: 'static>( | ||
| u: u32, | ||
|
|
@@ -43,6 +47,19 @@ fn setup_proposal<T: Config<I>, I: 'static>( | |
| (caller, value, beneficiary_lookup) | ||
| } | ||
|
|
||
| // Create the pre-requisite information needed to create a treasury `spend` call. | ||
| fn setup_spend_call<T: Config<I>, I: 'static>( | ||
| u: u32, | ||
| ) -> (T::AssetKind, T::AccountId, PayBalanceOf<T, I>, AccountIdLookupOf<T>) { | ||
| let caller = account("caller", u, SEED); | ||
|
|
||
| let value: PayBalanceOf<T, I> = SEED.into(); | ||
| let beneficiary = account("beneficiary", u, SEED); | ||
| let beneficiary_lookup = T::Lookup::unlookup(beneficiary); | ||
| let asset_kind = default_asset_kind::<T, I>(); | ||
| (asset_kind, caller, value, beneficiary_lookup) | ||
| } | ||
|
|
||
| // Create proposals that are approved for use in `on_initialize`. | ||
| fn create_approved_proposals<T: Config<I>, I: 'static>(n: u32) -> Result<(), &'static str> { | ||
| for i in 0..n { | ||
|
|
@@ -55,6 +72,16 @@ fn create_approved_proposals<T: Config<I>, I: 'static>(n: u32) -> Result<(), &'s | |
| Ok(()) | ||
| } | ||
|
|
||
| // Create pending payments that are approved for use in `on_initialize`. | ||
| fn create_pending_payments<T: Config<I>, I: 'static>(n: u32) -> Result<(), &'static str> { | ||
| for i in 0..n { | ||
| let (asset_kind, _, value, lookup) = setup_spend_call::<T, I>(i); | ||
| Treasury::<T, I>::spend(RawOrigin::Root.into(), asset_kind, value, lookup)?; | ||
| } | ||
| ensure!(<PendingPayments<T, I>>::count() == n, "Enpty pending payments storage"); | ||
| Ok(()) | ||
| } | ||
|
|
||
| fn setup_pot_account<T: Config<I>, I: 'static>() { | ||
| let pot_account = Treasury::<T, I>::account_id(); | ||
| let value = T::Currency::minimum_balance().saturating_mul(1_000_000_000u32.into()); | ||
|
|
@@ -68,11 +95,11 @@ fn assert_last_event<T: Config<I>, I: 'static>(generic_event: <T as Config<I>>:: | |
| benchmarks_instance_pallet! { | ||
| // This benchmark is short-circuited if `SpendOrigin` cannot provide | ||
| // a successful origin, in which case `spend` is un-callable and can use weight=0. | ||
| spend { | ||
| spend_local { | ||
| let (_, value, beneficiary_lookup) = setup_proposal::<T, _>(SEED); | ||
| let origin = T::SpendOrigin::try_successful_origin(); | ||
| let beneficiary = T::Lookup::lookup(beneficiary_lookup.clone()).unwrap(); | ||
| let call = Call::<T, I>::spend { amount: value, beneficiary: beneficiary_lookup }; | ||
| let call = Call::<T, I>::spend_local { amount: value, beneficiary: beneficiary_lookup }; | ||
| }: { | ||
| if let Ok(origin) = origin.clone() { | ||
| call.dispatch_bypass_filter(origin)?; | ||
|
|
@@ -84,6 +111,24 @@ benchmarks_instance_pallet! { | |
| } | ||
| } | ||
|
|
||
| // This benchmark is short-circuited if `SpendOrigin` cannot provide | ||
| // a successful origin, in which case `spend` is un-callable and can use weight=0. | ||
| spend { | ||
| let (asset_kind, _, value, beneficiary_lookup) = setup_spend_call::<T, I>(SEED); | ||
| let origin = T::SpendOrigin::try_successful_origin(); | ||
| let beneficiary: T::AccountId = T::Lookup::lookup(beneficiary_lookup.clone()).unwrap(); | ||
| let call = Call::<T, I>::spend { asset_kind, amount: value, beneficiary: beneficiary_lookup }; | ||
| }: { | ||
| if let Ok(origin) = origin.clone() { | ||
| call.dispatch_bypass_filter(origin)?; | ||
| } | ||
| } | ||
| verify { | ||
| if origin.is_ok() { | ||
| assert_last_event::<T, I>(Event::PaymentQueued{ pending_payment_index: 0, asset_kind, amount: value, beneficiary }.into()) | ||
| } | ||
| } | ||
|
|
||
| propose_spend { | ||
| let (caller, value, beneficiary_lookup) = setup_proposal::<T, _>(SEED); | ||
| // Whitelist caller account from further DB operations. | ||
|
|
@@ -138,5 +183,12 @@ benchmarks_instance_pallet! { | |
| Treasury::<T, _>::on_initialize(T::BlockNumber::zero()); | ||
| } | ||
|
|
||
| on_initialize_pending_payments { | ||
| let p in 0 .. T::MaxApprovals::get(); | ||
|
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.
|
||
| create_pending_payments::<T,_>(p)?; | ||
| }: { | ||
| Treasury::<T, _>::on_initialize(T::BlockNumber::zero()); | ||
| } | ||
|
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. we need some check here that pay was executed |
||
|
|
||
| impl_benchmark_test_suite!(Treasury, crate::tests::new_test_ext(), crate::tests::Test); | ||
| } | ||
Oops, something went wrong.
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.