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: add block rewards to altair and centrifuge runtimes #1342

Merged
merged 30 commits into from
May 16, 2023

Conversation

wischli
Copy link
Contributor

@wischli wischli commented May 11, 2023

Description

  • Adds block rewards implementation introduced in feat: impl block rewards #1198 to the Altair and Centrifuge runtimes
  • Reduces kick threshold for collators to 2 hours from 6 hours UPDATE: In order for this to become effective, we would have to change the session duration as kicking is only applied on session transitions
    • Automatically removes collators which fail to produce a block within that threshold from the set of block authors
  • Fixes issue of of unfunded sovereign pallet_rewards accounts which receive rewards
    • Without the fix:
      • Rewards are not be minted into that account if they are below the ExistentialDeposit
      • Rewards can not be claimed by all parties as this would leave the account without balance
    • Adds funding of 1 CFG or AIR to the pallet_rewards sovereign account via
      • GenesisConfig for ephemeral networks
      • FundExistentialDeposit migration for running networks
  • Adds required migration for SessionKeys
  • Removes migrations for dev runtime as a result of the agreement made at the offsite

About the rewards values

Altair

Based on this RFC, Altair rewards are currently 12000 AIR per month. Looking at the time calculation of the Centrifuge block rewards proposal, a year is counted as 365 days. Thus, on average, a month equals 30.4166666667 days.

  • Collator rewards: 12000 AIR per month / 30.417 days per month / 4 sessions per day = 98.63 AIR = 98630 MILLI_AIR
  • Total rewards: In Altair, we transfer the rewards from the treasury and do not want to mint extra rewards into the treasury as the latter is already sufficiently funded.
    • UPDATE 2023-05-15: We actually want to mint the rewards here as well to be closer to Centrifuge. There will be a follow-up RFC to burn some of the treasury.
    • We could set this to infinity and it would have no effect because pallet_block_rewards::Config::Beneficiary is set to (). We only need to ensure that TotalRewards will always be at least CollatorReward * num_collators. Of course, TotalRewards can also be adjusted via RootOrHalfOfCouncil. However, I do not see any reason to set it to CollatorRewards * MaxCandidates for now as the multiplication with MaxCandidates just serves as a max bound. The remainder of TotalRewards - CollatorRewards will be dropped in Altair.

Centrifuge

In Centrifuge we mint rewards both for the collators as well as the treasury. These values have been pre-approved by https://gov.centrifuge.io/t/rfc-add-a-block-reward-and-improve-collators-cycle/4766

  • Collator rewards = 16.65 CFG per epoch / 2 sessions per epoch = 8.325 CFG = 8_325 * MILLI_CFG
  • Total rewards = 20,096 CFG per epoch / 2 sessions per epoch = 10048 CFG

About the migrations

Unfortunately, adding block rewards requires three migrations to Altair and Centrifuge. Here's a short summary:

Rewards

While testing block rewards on a local chain environment, I stumbled into a minor issue which needs to be fixed: When claiming rewards, we currently transfer from the pallet id of the base pallet_rewards instance to the recipient with keep_alive enabled. This blocks any reward claims which would reduce the balance of the pallet's sovereign account below the existential deposit (ED). The keep_alive should stay enabled. Thus, we need to fund the pallet_rewards sovereign account (at least) with the ED which is done by the migration added here.

Without this migration, not all rewards can be claimed from the reward recipients.

BlockRewards

This migration was introduced in #1198. It sets up the required block rewards storage for our current collators.

Without this migration, none of the collators would be eligible to claim rewards.

SessionKeys

Without this migration, all of our collators would have to update their session keys manually. E.g., none of the collators would actually be recognized by the session transition inside pallet_block_rewards because the block_rewards entry of SessionKeys is unset.

TODO

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 I9-release A specific release. P7-asap Issue should be addressed in the next days. D8-migration Pull request touches storage and needs migration code. labels May 11, 2023
@wischli wischli self-assigned this May 11, 2023
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.

Very clean PR @wischli. I really like it! 🚀
I left some comments, but most of them are questions

pallets/block-rewards/src/migrations.rs Show resolved Hide resolved
pallets/rewards/src/lib.rs Outdated Show resolved Hide resolved
pallets/rewards/src/migrations.rs Outdated Show resolved Hide resolved
pallets/rewards/src/migrations.rs Outdated Show resolved Hide resolved
pallets/rewards/src/mock.rs Outdated Show resolved Hide resolved
runtime/development/src/lib.rs Outdated Show resolved Hide resolved
runtime/centrifuge/src/lib.rs Outdated Show resolved Hide resolved
runtime/centrifuge/src/lib.rs Show resolved Hide resolved
runtime/centrifuge/src/lib.rs Outdated Show resolved Hide resolved
src/chain_spec.rs Outdated Show resolved Hide resolved
@NunoAlexandre
Copy link
Contributor

@wischli looking good already but I will give it a proper review once the ToDos are addressed 👍

src/chain_spec.rs Outdated Show resolved Hide resolved
thea-leake
thea-leake previously approved these changes May 12, 2023
Copy link
Contributor

@thea-leake thea-leake left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

@wischli wischli requested a review from lemunozm May 12, 2023 13:20
Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

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

Only one question regarding the ED minting in the migration, where I am not sure, it is working as we intend it to. But might be due to my improper understanding. If cleared, will approve.

Copy link
Contributor

@NunoAlexandre NunoAlexandre left a comment

Choose a reason for hiding this comment

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

Some comments and suggestions but great work and looking great overall 🙌

pallets/rewards/src/lib.rs Outdated Show resolved Hide resolved
runtime/altair/src/lib.rs Outdated Show resolved Hide resolved
runtime/altair/src/lib.rs Outdated Show resolved Hide resolved
runtime/altair/src/lib.rs Outdated Show resolved Hide resolved
runtime/altair/src/lib.rs Outdated Show resolved Hide resolved
runtime/altair/src/lib.rs Outdated Show resolved Hide resolved
runtime/altair/src/lib.rs Outdated Show resolved Hide resolved
},
block_rewards_base: altair_runtime::BlockRewardsBaseConfig {
currency_id: CurrencyId::Native,
amount: 1 * MICRO_AIR,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this correct that the reward for a block is 1 micro AIR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's not the block reward but the funding of the pallet_rewards::Instance sovereign account which holds all the rewards until they are claimed. As long as this account does not have the ED, not all rewards can be claimed at the same time as it would kill this account.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just out of interest, we could use the ED defined in the runtime instead of hardcoding, right?

@wischli
Copy link
Contributor Author

wischli commented May 16, 2023

There was a last-minute change to the Altair configuration: Lucas and Cassidy proposed to actually mint AIR instead of transferring from the treasury. There will be a follow-up proposal to burn some/all of the Altair treasury. The main reason is that we want to be more close to Centrifuge.

lemunozm
lemunozm previously approved these changes May 16, 2023
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.

LGTM!

mustermeiszer
mustermeiszer previously approved these changes May 16, 2023
Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

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

Would prefer to panic instead of logging an error in the genesis build. This is at least what Substrate is doing, IIRC and easier to spot. But no blocker.

Looks clean and nice!

.map_err(|e| log::error!("Failed to attach currency to collator group: {:?}", e))
.ok();
T::Rewards::attach_currency(T::StakeCurrencyId::get(), T::StakeGroupId::get())
.map_err(|e| log::error!("Failed to attach currency to collator group: {:?}", e))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Genesis builds usually panic!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pallets/rewards/src/lib.rs Outdated Show resolved Hide resolved
runtime/centrifuge/src/lib.rs Outdated Show resolved Hide resolved
},
block_rewards_base: altair_runtime::BlockRewardsBaseConfig {
currency_id: CurrencyId::Native,
amount: 1 * MICRO_AIR,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just out of interest, we could use the ED defined in the runtime instead of hardcoding, right?

@wischli wischli dismissed stale reviews from mustermeiszer and lemunozm via 1fb344e May 16, 2023 08:12
Co-authored-by: Frederik Gartenmeister <mustermeiszer@posteo.de>
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.

LGTM!

@wischli wischli enabled auto-merge (squash) May 16, 2023 08:38
Copy link
Contributor

@NunoAlexandre NunoAlexandre left a comment

Choose a reason for hiding this comment

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

Solid 🤘

@wischli wischli merged commit 629dcfd into main May 16, 2023
@NunoAlexandre NunoAlexandre deleted the feat/block-rewards-to-prod branch May 16, 2023 13:03
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. I9-release A specific release. P7-asap Issue should be addressed in the next days.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants