Skip to content
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 10 commits into from
Feb 23, 2024
Merged

Conversation

wischli
Copy link
Contributor

@wischli wischli commented Feb 21, 2024

Description

Fixes #1495

The current treasury inflation is based on absolute numbers and thus diverging from the annual 3% on which the community decided both for Altair (-> RFC) as well as Centrifuge (-> CP6). This PR fills this gap by switching to a relative treasury inflation. As a result, all three runtimes have the exact same block rewards configuration now except for different collator reward amounts.

Now

Inside pallet-block-rewards, the annual treasury inflation rate is stored. On each new session, collators receive their reward. Moreover, the treasury is funded with the proration based on the configured rate and session duration in seconds:

treasury_inflation_per_session = annual_treasury_rate / SECONDS_PER_YEAR * session_duration_in_secs
session_duration_in_secs  = now - last_update

Before

Before, the rewards configuration revolved around an absolute total_amount per session which was first distributed to the collators and the remainder minted into the treasury, if configured in the runtime (true for Centrifuge, false for Altair). For Altair, we also need to burn 15,752,730 AIR (equivalent of annual Treasury block rewards) which can be batched with the runtime upgrade proposal

Checklist:

  • I have added Rust doc comments to structs, enums, traits and functions
  • I have made corresponding changes to the documentation
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or that my feature works

@wischli wischli added I6-refactoring Code needs refactoring. D8-migration Pull request touches storage and needs migration code. labels Feb 21, 2024
@wischli wischli added this to the Centrifuge 1025 milestone Feb 21, 2024
@wischli wischli self-assigned this Feb 21, 2024
@wischli wischli requested a review from lemunozm as a code owner February 21, 2024 08:33
lemunozm
lemunozm previously approved these changes Feb 22, 2024
Copy link
Contributor

@lemunozm lemunozm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see anything weird. Good job here William! I left mostly (super) NITs and some questions.

Comment on lines +669 to +672
last_update: std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.expect("SystemTime before UNIX EPOCH!")
.as_secs(),
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@@ -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::*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the benchmarking version!

+ Member
+ FixedPointNumberExtension
+ TypeInfo
+ MaybeSerializeDeserialize
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super NIT.

  • I think MaybeSerializeDeserialize is not needed.
  • TypeInfo is already inside of Parameter

pallets/block-rewards/src/lib.rs Show resolved Hide resolved
pallets/block-rewards/src/mock.rs Outdated Show resolved Hide resolved
pallets/block-rewards/src/mock.rs Outdated Show resolved Hide resolved
pallets/block-rewards/src/migrations.rs Show resolved Hide resolved
@wischli wischli requested a review from lemunozm February 22, 2024 16:31
lemunozm
lemunozm previously approved these changes Feb 23, 2024
Copy link
Contributor

@lemunozm lemunozm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if Frederik wants to also review this, but LGTM!

@wischli wischli merged commit 59f7f68 into main Feb 23, 2024
9 checks passed
@wischli wischli deleted the feat/relative-treasury-inflation branch February 23, 2024 14:23
@wischli wischli mentioned this pull request Apr 11, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D8-migration Pull request touches storage and needs migration code. I6-refactoring Code needs refactoring.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Altair] Mint treasury block rewards
2 participants