Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Add delegation rewards and commission #114

Merged
merged 5 commits into from
Jan 27, 2021

Conversation

adlerjohn
Copy link
Member

@adlerjohn adlerjohn commented Jan 26, 2021

Fixes #95, #104.

Major changes:

  • Remove stakedBalance for validators. Validators now have no balance and need to delegate to themselves. This can be abstracted away at the UI layer.
  • Delegation commission is computed and rewards (both block subsidy and fees) are dispersed to both validators and delegations. Commission rewards are stored in a new field in the validator object.

Currently validator commission rewards simply sit there until the validator unbonds. We should support delegating this reward #117.

@adlerjohn adlerjohn added documentation Improvements or additions to documentation enhancement New feature or request consensus labels Jan 26, 2021
@adlerjohn adlerjohn self-assigned this Jan 26, 2021
Remove validator staked balance in favor of only delegations.

Compute commission.
@adlerjohn adlerjohn linked an issue Jan 27, 2021 that may be closed by this pull request
@adlerjohn adlerjohn marked this pull request as ready for review January 27, 2021 02:03
Copy link
Member

@liamsi liamsi left a comment

Choose a reason for hiding this comment

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

LGTM!
I did not go through the state transition pseudo-code in detail though, as this part of the spec isn't immediately implementation critical, as we we will use the staking / distribution modules without any modifications at first.

validator.commissionRate = tx.commissionRate
validator.delegatedCount = 0
validator.votingPower = tx.amount
validator.votingPower = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the benefit here?

Copy link
Member Author

@adlerjohn adlerjohn Jan 27, 2021

Choose a reason for hiding this comment

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

This is part of the refactor of removing staked balance for validators:

Remove stakedBalance for validators. Validators now have no balance and need to delegate to themselves. This can be abstracted away at the UI layer.

(Note that this does introduce a divide-by-zero case when computing entries, but I'll take care of that in a future PR, issue in #115.)

@@ -585,7 +586,7 @@ Apply the following to the state:
state.accounts[sender].nonce += 1
state.accounts[sender].balance -= totalCost(tx.amount, bytesPaid)

state.activeValidatorSet[block.header.proposerAddress].pendingRewards += tipCost(bytesPaid)
state.activeValidatorSet.proposerBlockReward += tipCost(bytesPaid)
```

#### Begin Block
Copy link
Contributor

Choose a reason for hiding this comment

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

This spec assumes these computations will be done every block. Why not epoch it?

Copy link
Member

Choose a reason for hiding this comment

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

I guess this is because this is how it works in the SDK currently. While we want epochs on the long run I'm against putting more effort into this now. It is "just" an optimization (yeah, a really cool one but I think there are higher prio ones).

Copy link
Contributor

Choose a reason for hiding this comment

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

cosmos/cosmos-sdk#8328 😉 Should land in the sdk before launch. May be worth leaving a note that epochs are preferred.

Copy link
Member

Choose a reason for hiding this comment

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

Nice! Thanks for bringing this to our attention.

Copy link
Member Author

@adlerjohn adlerjohn Jan 27, 2021

Choose a reason for hiding this comment

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

The only real benefit to epochs for our usecase is reducing light client overhead since fewer block headers need to be downloaded. It'll probably be important long-term, but it's just an optimization and we can worry about those later.

@adlerjohn adlerjohn merged commit 665a77d into master Jan 27, 2021
@adlerjohn adlerjohn deleted the adlerjohn-delegation_commission branch January 27, 2021 16:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
consensus documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider adding rewards to voting power Handle delegation commission
3 participants