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

[RFC-191]: EVM-740 - Move distribute rewards to first block in epoch #1735

Conversation

goran-ethernal
Copy link
Collaborator

@goran-ethernal goran-ethernal commented Jul 20, 2023

Description

ValidatorSet contract on supernet is used as a wrapper around staked tokens by validators on L2. For governance, it is used as a voting token as well, which makes sense, since we are only allowing validators to propose and vote for governance proposals.

But, to be able to use ValidatorSet as vote token in governance, we needed to change it to implement ERC20VotesUpgradable implementation, which changed how the contract checkpoints its total supply at a certain point in time, and how it returns totalSupplyAt, which is used by RewardPool contract to accurately distribute rewards.
Now totalSupplyAt has a check which prevents calling it for the last checkpointed total supply, if they happen in the same block, and because of that, reward distribution failed.

This PR moves reward distribution to the first block of epoch. So when an epoch completes, and gets committed (which will checkpoint total supply at ValidatorSet contract), the new epoch will start, and in the first block of new epoch, proposer will add the distribute rewards transaction for the previously completed epoch.

This has three benefits:

  1. It lowers gas consumption on epoch ending blocks.
  2. It enables more accurate reward distribution.
  3. We can use ValidatorSet as voting token for governance.

IMPORTANT NOTE:
Rewards will only be distributed in the first block of an epoch if governance fork is enabled. If it is not enabled, rewards will be distributed old way, at epoch ending block.

Changes include

  • Bugfix (non-breaking change that solves an issue)
  • Hotfix (change that solves an urgent issue, and requires immediate attention)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (change that is not backwards-compatible and/or changes current functionality)

Checklist

  • I have assigned this PR to myself
  • I have added at least 1 reviewer
  • I have added the relevant labels
  • I have updated the official documentation
  • I have added sufficient documentation in code

Testing

  • I have tested this code with the official test suite
  • I have tested this code manually

@goran-ethernal goran-ethernal changed the base branch from develop to feat/on-chain-governance July 20, 2023 10:28
@goran-ethernal goran-ethernal force-pushed the EVM-74-Move-distribute-rewards-to-first-block-in-epoch branch from 2c2648c to 83da308 Compare July 20, 2023 11:56
@goran-ethernal goran-ethernal requested a review from a team July 20, 2023 12:03
@goran-ethernal goran-ethernal self-assigned this Jul 20, 2023
@goran-ethernal goran-ethernal added the feature New update to Polygon Edge label Jul 20, 2023
@goran-ethernal goran-ethernal marked this pull request as ready for review July 20, 2023 12:04
@goran-ethernal goran-ethernal force-pushed the EVM-74-Move-distribute-rewards-to-first-block-in-epoch branch from f63f804 to 4ebb065 Compare July 20, 2023 12:44
Copy link
Collaborator

@Stefan-Ethernal Stefan-Ethernal left a comment

Choose a reason for hiding this comment

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

Overall looks good!

consensus/polybft/governance_fork.go Outdated Show resolved Hide resolved
consensus/polybft/consensus_runtime_test.go Outdated Show resolved Hide resolved
consensus/polybft/fsm.go Outdated Show resolved Hide resolved
consensus/polybft/fsm.go Outdated Show resolved Hide resolved
@goran-ethernal goran-ethernal merged commit 1e53432 into feat/on-chain-governance Jul 20, 2023
7 checks passed
@goran-ethernal goran-ethernal deleted the EVM-74-Move-distribute-rewards-to-first-block-in-epoch branch July 20, 2023 14:21
@github-actions github-actions bot locked and limited conversation to collaborators Jul 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New update to Polygon Edge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants