-
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: add block rewards to altair and centrifuge runtimes #1342
Conversation
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.
Very clean PR @wischli. I really like it! 🚀
I left some comments, but most of them are questions
@wischli looking good already but I will give it a proper review once the ToDos are addressed 👍 |
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.
LGTM! 🚀
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.
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.
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.
Some comments and suggestions but great work and looking great overall 🙌
src/chain_spec.rs
Outdated
}, | ||
block_rewards_base: altair_runtime::BlockRewardsBaseConfig { | ||
currency_id: CurrencyId::Native, | ||
amount: 1 * MICRO_AIR, |
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.
Is this correct that the reward for a block is 1 micro AIR?
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.
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.
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.
Just out of interest, we could use the ED defined in the runtime instead of hardcoding, right?
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. |
* refactor: remove rewards domain concept * refactor: rm dev migrations * refactor: remove DOM * bench: fix block rewards * fix: RewardsApi
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.
LGTM!
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.
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!
pallets/block-rewards/src/lib.rs
Outdated
.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)) |
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.
Genesis builds usually panic!
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.
src/chain_spec.rs
Outdated
}, | ||
block_rewards_base: altair_runtime::BlockRewardsBaseConfig { | ||
currency_id: CurrencyId::Native, | ||
amount: 1 * MICRO_AIR, |
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.
Just out of interest, we could use the ED defined in the runtime instead of hardcoding, right?
Co-authored-by: Frederik Gartenmeister <mustermeiszer@posteo.de>
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.
LGTM!
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.
Solid 🤘
Description
Reduces kick threshold for collators to 2 hours from 6 hoursUPDATE: In order for this to become effective, we would have to change the session duration as kicking is only applied on session transitionspallet_rewards
accounts which receive rewardsExistentialDeposit
CFG
orAIR
to thepallet_rewards
sovereign account viaGenesisConfig
for ephemeral networksFundExistentialDeposit
migration for running networksSessionKeys
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 equals30.4166666667
days.12000 AIR per month / 30.417 days per month / 4 sessions per day = 98.63 AIR = 98630 MILLI_AIR
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.pallet_block_rewards::Config::Beneficiary
is set to()
. We only need to ensure thatTotalRewards
will always be at leastCollatorReward * num_collators
. Of course,TotalRewards
can also be adjusted viaRootOrHalfOfCouncil
. However, I do not see any reason to set it toCollatorRewards * MaxCandidates
for now as the multiplication withMaxCandidates
just serves as a max bound. The remainder ofTotalRewards - 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
16.65 CFG per epoch / 2 sessions per epoch = 8.325 CFG = 8_325 * MILLI_CFG
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 withkeep_alive
enabled. This blocks any reward claims which would reduce the balance of the pallet's sovereign account below the existential deposit (ED). Thekeep_alive
should stay enabled. Thus, we need to fund thepallet_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 theblock_rewards
entry ofSessionKeys
is unset.TODO
SessionKeys
: Add newblock_rewards
entryDomain
inpallet-rewards
#1246 --> refactor: remove rewards domain concept #1344RewardsApi
for Tuple --> Can be done later whenLiquidityRewards
are pushed to prodChecklist: