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

Go back to block based staking rounds and make inflation dynamic (slot based) #2690

Merged
merged 32 commits into from
Mar 4, 2024

Conversation

librelois
Copy link
Collaborator

@librelois librelois commented Mar 1, 2024

What does it do?

The initial goal of #2577 was to have a slot based inflation that is not impacted by block production issues. This PR achieve the same goal in a different way to keep to staking round fixed length in blocks.

⚠️ Breaking Changes

The storage item parachainStaking.staked was removed.

What important points reviewers should know?

This PR contains a migration that should work from both RT2700 and RT2800, and this is challenging becuase we don't use pallet versioning for the pallet parachain staking.
The trick to detect from what version the RoundInfo should be migrated is to measure the raw size of the data, it's 12 bytes on RT2700 and 15 bytes on RT2600.

Is there something left for follow-up PRs?

What alternative implementations were considered?

#2577, but dynamic-length rounds cause bugs and break external tools.

Are there relevant PRs or issues in other repositories (Substrate, Polkadot, Frontier, Cumulus)?

What value does it bring to the blockchain users?

More constant inflation rate.

TODO

  • Run try-runtime against stagenet (rt2800)
  • Run try-runtime against moonsama (rt2800)
  • Run try-runtime agaisnt moonbase alpha (rt2700)
  • Fix rust tests
  • Fix ts tests

@librelois librelois added A3-inprogress Pull request is in progress. No review needed at this stage. B7-runtimenoteworthy Changes should be noted in any runtime-upgrade release notes D9-needsaudit👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited breaking Needs to be mentioned in breaking changes labels Mar 1, 2024
Copy link
Contributor

@Agusrodri Agusrodri left a comment

Choose a reason for hiding this comment

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

Some small typos

pallets/parachain-staking/src/inflation.rs Outdated Show resolved Hide resolved
pallets/parachain-staking/src/lib.rs Outdated Show resolved Hide resolved
pallets/parachain-staking/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

github-actions bot commented Mar 3, 2024

Coverage Report

@@                       Coverage Diff                       @@
##           master   elois-rework-staking-rounds      +/-   ##
===============================================================
+ Coverage   80.43%                        80.44%   +0.01%     
+ Files         297                           299       +2     
+ Lines       91636                         91688      +52     
===============================================================
+ Hits        73702                         73751      +49     
+ Misses      17934                         17937       +3     
Files Changed Coverage
/pallets/parachain-staking/src/delegation_requests.rs 91.99% (+0.05%) 🔼
/pallets/parachain-staking/src/inflation.rs 87.57% (+0.07%) 🔼
/pallets/parachain-staking/src/lib.rs 90.77% (+0.15%) 🔼
/pallets/parachain-staking/src/tests.rs 91.62% (+0.03%) 🔼
/pallets/parachain-staking/src/types.rs 77.95% (+0.04%) 🔼
/precompiles/parachain-staking/src/mock.rs 97.82% (+0.01%) 🔼
/runtime/common/src/apis.rs 85.34% (-0.04%) 🔽
/runtime/common/src/migrations.rs 90.00% (+22.04%) 🔼
/runtime/moonbase/src/lib.rs 49.05% (-0.45%) 🔽
/runtime/moonbeam/src/lib.rs 46.45% (+0.40%) 🔼
/runtime/moonriver/src/lib.rs 46.44% (+0.40%) 🔼

Coverage generated Mon Mar 4 12:24:11 UTC 2024

let blocks_per_round = <Pallet<T>>::round().length;
T::SlotsPerYear::get() / blocks_per_round
let blocks_per_round = <Pallet<T>>::round().length as u64;
let blocks_per_year = MS_PER_YEAR / T::BlockTime::get();
Copy link
Contributor

Choose a reason for hiding this comment

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

We could probably have a new helper function named blocks_per_year and replace MS_PER_YEAR / T::BlockTime::get() by it everywhere.

librelois and others added 2 commits March 4, 2024 11:33
Co-authored-by: Rodrigo Quelhas <22591718+RomarQ@users.noreply.github.com>
@librelois librelois marked this pull request as ready for review March 4, 2024 10:39
@librelois librelois mentioned this pull request Mar 4, 2024
21 tasks
Co-authored-by: Rodrigo Quelhas <22591718+RomarQ@users.noreply.github.com>
@@ -84,7 +84,7 @@ describeSuite({
title: "should be under the limit of 3_500_000",
test: async () => {
// Moves to the next payout block
await jumpRounds(context, 1);
await jumpRounds(context, 2);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Was it an error or did something change ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There was a bug before this PR, the collators got rewards for the round 1 twice (at round 2 and at round 3), now it's fixed, so there is no rewards distribution at round 2.

@librelois librelois merged commit 3be4e9a into master Mar 4, 2024
27 checks passed
@librelois librelois deleted the elois-rework-staking-rounds branch March 4, 2024 13:34
librelois added a commit that referenced this pull request Mar 4, 2024
…t based) (#2690)

* make staking rounds block based again and inflation slot based

* remove unused imports

* create migration skeleton

* implement migration

* integrate round migration to common migrations

* apply proportion duration to the current round

* compile benchs and test

* add moonbase migration to multiply round length by 2

* compute round duration before round update

* fix some bugs

* fix some rust tests

* fix migration

* apply suggestions

* First staking rewards at round 3

* revert moonwall config local changes

* fix rounds per year

* fix periods calculation in reset_round()

* fix rustc warning

* fmt

* rework compute issuance

* Remove Staked storage item

* Remove Staked storage item on rust tests

* fix two rust tests more

* fix test_on_initialize_weights

* fix payouts_follow_delegation_changes test

* Update pallets/parachain-staking/src/lib.rs

Co-authored-by: Rodrigo Quelhas <22591718+RomarQ@users.noreply.github.com>

* Comment moonbase migration

* typo

* Update runtime/moonbase/src/migrations.rs

Co-authored-by: Rodrigo Quelhas <22591718+RomarQ@users.noreply.github.com>

* Update runtime/moonbase/src/migrations.rs

* Update pallets/parachain-staking/src/lib.rs

---------

Co-authored-by: Agusrodri <agusrodriguez2456@gmail.com>
Co-authored-by: Rodrigo Quelhas <22591718+RomarQ@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A3-inprogress Pull request is in progress. No review needed at this stage. B7-runtimenoteworthy Changes should be noted in any runtime-upgrade release notes breaking Needs to be mentioned in breaking changes D9-needsaudit👮 PR contains changes to fund-managing logic that should be properly reviewed and externally audited
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants