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

refactor!: use time-based queued staking and reserve unharvested rewards #305

Merged
merged 42 commits into from
May 16, 2022

Conversation

hallazzang
Copy link
Contributor

@hallazzang hallazzang commented Apr 28, 2022

Description

This PR changes queued stakings to be handled in time-based(24 hours) manner, rather than epoch-based.
Also, auto-withdrawn rewards due to changes of staked coin amount now accumulated in separate module account.
Farmers have to manually claim their unharvested rewards using MsgHarvest.
Note that unstaking whole staked coin results in withdrawal of all current rewards and unharvested rewards.

Background

Since ProcessQueuedCoins is being called at the end of epoch, when there are too many queued stakings it could impact the chain's performance(see #274). By handling queued staking at the moment it should be changed to staked, it mitigates the mentioned performance issue.

Also, automatic withdrawal of accrued rewards when there's a change in staking coin amount(by staking more or unstaking) could confuse many users. Our solution is to move rewards to a separate module account(UnharvestedRewardsReserveAcc) and make users to claim it through MsgHarvest. In this way, users can know how many rewards are still unharvested and claim rewards as they wish.
Note that when unstaking whole amount of coin for a specific denom, all previous unharvested rewards are automatically withdrawn for convenience.

Upgrading

When upgrading a chain which uses the farming module, set EndTime of new QueuedStaking to 24 * CurrentEpochDays hours after current (block)time. It'll result in smooth transition to new time-based staking logic.

Closes #302
Closes #274

Tasks

  • Provide detailed reasoning about this change and investigate potential risks
  • All tasks from refactor!: make queued staking to be handled time-based #282
  • Add UnharvestedRewards struct
  • Implement genesis functionalities and write tests
  • Fix CurrentEpoch preservation rule
  • Implement gRPC endpoints for UnharvestedRewards
  • Implement CLI query commands
  • Update spec doc
  • rebase(not merge) on the latest main branch
  • bump ConsensusVersion of farming module from 1 -> 2
  • add migration codes with test codes
  • add changelogs with breaking changes as unreleased on CHANGELOG.md
  • bump swagger version on clinet/docs/config.json

References

@hallazzang hallazzang self-assigned this Apr 28, 2022
@hallazzang hallazzang added f-sync and removed f-sync labels Apr 28, 2022
@dongsam dongsam mentioned this pull request Apr 29, 2022
4 tasks
@hallazzang hallazzang marked this pull request as ready for review May 3, 2022 13:19
@hallazzang hallazzang requested review from dongsam and jaybxyz as code owners May 3, 2022 13:19
@dongsam
Copy link
Contributor

dongsam commented May 4, 2022

@hallazzang Great works!
It would be better if you could below tasks

  • rebase(not merge) on the latest main branch
  • bump ConsensusVersion of farming module from 1 -> 2
  • add migration codes with test codes
  • bump swagger version on clinet/docs/config.json
  • add changelogs with breaking changes as unreleased on CHANGELOG.md

@dongsam dongsam added this to the v2.0 milestone May 4, 2022
Copy link
Contributor

@jaybxyz jaybxyz left a comment

Choose a reason for hiding this comment

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

Great work overall! I don't find any critical/major issue with the changes, but I request to update some documents and inline comments.

x/farming/keeper/staking.go Outdated Show resolved Hide resolved
proto/squad/farming/v1beta1/query.proto Show resolved Hide resolved
proto/squad/farming/v1beta1/query.proto Show resolved Hide resolved
x/farming/keeper/reward.go Show resolved Hide resolved
@github-actions github-actions bot added the documentation Improvements or additions to documentation label May 4, 2022
@jaybxyz jaybxyz self-requested a review May 4, 2022 07:48
CHANGELOG.md Show resolved Hide resolved
@hallazzang hallazzang requested a review from dongsam May 9, 2022 04:56
- add `rewards` field to `QueryPositionResponse`
- make `Rewards` query endpoint to return rewards by staking coin denom
@dongsam
Copy link
Contributor

dongsam commented May 11, 2022

@hallazzang looks TestCmdQueryPosition test failed, and could you remove the committed JSON files?

Copy link
Contributor

@dongsam dongsam left a comment

Choose a reason for hiding this comment

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

LGTM!

@dongsam dongsam merged commit 0a2b6d2 into main May 16, 2022
@dongsam dongsam removed the c-sync label Jun 16, 2022
dongsam pushed a commit that referenced this pull request Aug 31, 2022
dongsam pushed a commit that referenced this pull request Aug 31, 2022
refactor!: use time-based queued staking and reserve unharvested rewards #305
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation x/farming x/liquidstaking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unclaimed farming reward MA Too many queued stakings can cause slow block production
3 participants