-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: relative treasury inflation #1740
Merged
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
02b7fe6
feat: relative treasury inflation
wischli 195b14a
refactor: apply benchmarking v2 to block rewards
wischli 420b1d1
feat: add migration
wischli 45a5b09
fix: build + clippy
wischli 95dbeae
Update pallets/block-rewards/src/mock.rs
wischli 7d95ced
Merge remote-tracking branch 'origin/main' into feat/relative-treasur…
wischli 76cea1f
chore: minor fixes
wischli 24bc318
refactor: remove max changes per session
wischli 63d37d1
refactor: remove more redundant trait bounds
wischli add78d8
Merge remote-tracking branch 'origin/main' into feat/relative-treasur…
wischli 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 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 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 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
use cfg_primitives::CFG; | ||
use cfg_types::tokens::CurrencyId; | ||
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller}; | ||
use frame_benchmarking::v2::*; | ||
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. Thanks for updating the benchmarking version! |
||
use frame_support::{ | ||
assert_ok, | ||
traits::{fungibles::Inspect, Currency as CurrencyT}, | ||
|
@@ -14,56 +14,85 @@ use crate::{pallet::Config, Pallet as BlockRewards}; | |
const REWARD: u128 = 1 * CFG; | ||
const SEED: u32 = 0; | ||
|
||
benchmarks! { | ||
where_clause { | ||
where | ||
#[benchmarks( | ||
where | ||
T::Balance: From<u128>, | ||
T::BlockNumber: From<u32> + One, | ||
T::Weight: From<u32>, | ||
<T as Config>::Currency: frame_support::traits::fungibles::Inspect<T::AccountId> + CurrencyT<T::AccountId>, | ||
<T as Config>::Tokens: Inspect<T::AccountId> + CurrencyT<T::AccountId>, | ||
<T as Config>::CurrencyId: From<CurrencyId>, | ||
} | ||
)] | ||
mod benchmarks { | ||
use super::*; | ||
|
||
claim_reward { | ||
let caller = whitelisted_caller(); | ||
let beneficiary: T::AccountId = account("collator", 0, SEED); | ||
#[benchmark] | ||
fn claim_reward() -> Result<(), BenchmarkError> { | ||
let caller: T::AccountId = account("caller", 0, SEED); | ||
let beneficiary: T::AccountId = account("collator", 0, SEED); | ||
|
||
assert_ok!(BlockRewards::<T>::do_init_collator(&beneficiary)); | ||
assert_ok!(T::Rewards::reward_group(T::StakeGroupId::get(), REWARD.into())); | ||
assert_ok!(T::Rewards::reward_group( | ||
T::StakeGroupId::get(), | ||
REWARD.into() | ||
)); | ||
assert!(T::Rewards::is_ready(T::StakeGroupId::get())); | ||
assert!( | ||
!T::Rewards::compute_reward( | ||
T::StakeCurrencyId::get(), | ||
&beneficiary, | ||
).unwrap().is_zero() | ||
!T::Rewards::compute_reward(T::StakeCurrencyId::get(), &beneficiary,) | ||
.unwrap() | ||
.is_zero() | ||
); | ||
let before = | ||
<T::Tokens as Inspect<T::AccountId>>::balance(CurrencyId::Native.into(), &beneficiary); | ||
|
||
#[extrinsic_call] | ||
claim_reward(RawOrigin::Signed(caller), beneficiary.clone()); | ||
|
||
let num_collators: u128 = BlockRewards::<T>::next_session_changes() | ||
.collator_count | ||
.unwrap_or(BlockRewards::<T>::active_session_data().collator_count) | ||
.into(); | ||
// Does not get entire reward since another collator is auto-staked via genesis | ||
// config | ||
assert_eq!( | ||
<T::Tokens as Inspect<T::AccountId>>::balance(CurrencyId::Native.into(), &beneficiary) | ||
.saturating_sub(before), | ||
(REWARD / (num_collators + 1)).into() | ||
); | ||
let before = <T as Config>::Currency::balance(CurrencyId::Native.into(), &beneficiary); | ||
|
||
}: _(RawOrigin::Signed(caller), beneficiary.clone()) | ||
verify { | ||
let num_collators: u128 = BlockRewards::<T>::next_session_changes().collator_count.unwrap_or( | ||
BlockRewards::<T>::active_session_data().collator_count | ||
).into(); | ||
// Does not get entire reward since another collator is auto-staked via genesis config | ||
assert_eq!(<T as Config>::Currency::balance(CurrencyId::Native.into(), &beneficiary).saturating_sub(before), (REWARD / (num_collators + 1)).into()); | ||
|
||
Ok(()) | ||
} | ||
|
||
set_collator_reward { | ||
assert_ok!(BlockRewards::<T>::set_total_reward(RawOrigin::Root.into(), u128::MAX.into())); | ||
}: _(RawOrigin::Root, REWARD.into()) | ||
verify { | ||
assert_eq!(BlockRewards::<T>::next_session_changes().collator_reward, Some(REWARD.into())); | ||
#[benchmark] | ||
fn set_collator_reward_per_session() -> Result<(), BenchmarkError> { | ||
#[extrinsic_call] | ||
set_collator_reward_per_session(RawOrigin::Root, REWARD.into()); | ||
|
||
assert_eq!( | ||
BlockRewards::<T>::next_session_changes().collator_reward, | ||
Some(REWARD.into()) | ||
); | ||
|
||
Ok(()) | ||
} | ||
|
||
set_total_reward { | ||
}: _(RawOrigin::Root, u128::MAX.into()) | ||
verify { | ||
assert_eq!(BlockRewards::<T>::next_session_changes().total_reward, Some(u128::MAX.into())); | ||
#[benchmark] | ||
fn set_annual_treasury_inflation_rate() -> Result<(), BenchmarkError> { | ||
let rate = T::Rate::saturating_from_rational(1, 2); | ||
|
||
#[extrinsic_call] | ||
set_annual_treasury_inflation_rate(RawOrigin::Root, rate); | ||
|
||
assert_eq!( | ||
BlockRewards::<T>::next_session_changes().treasury_inflation_rate, | ||
Some(rate) | ||
); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl_benchmark_test_suite!( | ||
BlockRewards, | ||
crate::mock::ExtBuilder::default().build(), | ||
crate::mock::Test, | ||
); | ||
impl_benchmark_test_suite!( | ||
BlockRewards, | ||
crate::mock::ExtBuilder::default().build(), | ||
crate::mock::Test, | ||
); | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would mean that each node using this genesis will have a different configuration (different time machines). Is it ok or should they have the exact initial configuration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thats the implication. However, this only affects new networks, i.e. either Development if it needs to be reset or otherwise local ones. Therefore, it shouldn't have an impact. If we make it static, the first treasury inflation reward will huge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But you're using the system clock, not the clock used on-chain (that changed each block by 12 secs). I guess we're okay with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point but it should be fine here. It only affects the first treasury reward and should never affect live chains/production.