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 staking: increase reward amount denominator #3065

Merged
merged 3 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .changelog/3065.breaking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
go/staking: Increase reward amount denominator

This allows the genesis block writer to specify finer reward rates.

Associated genesis controls analysis:

```
RewardAmountDenominator
|- AddRewards
| |- RewardFactorEpochElectionAny
| '- RewardFactorEpochSigned
'- AddRewardSingleAttenuated
'- RewardFactorBlockProposed
```

Note to the genesis block writer: scale rewards factors **up** by a
factor of **1,000**.
8 changes: 4 additions & 4 deletions go/consensus/tendermint/apps/staking/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func TestRewardAndSlash(t *testing.T) {
require.NoError(err, "SetDebondingDelegation")

// Epoch 10 is during the first step.
require.NoError(s.AddRewards(ctx, 10, mustInitQuantityP(t, 100), escrowAddrAsList), "add rewards epoch 10")
require.NoError(s.AddRewards(ctx, 10, mustInitQuantityP(t, 100_000), escrowAddrAsList), "add rewards epoch 10")

// 100% gain.
delegatorAccount, err = s.Account(ctx, delegatorAddr)
Expand All @@ -233,7 +233,7 @@ func TestRewardAndSlash(t *testing.T) {
require.Equal(mustInitQuantityP(t, 9900), commonPool, "reward first step - common pool")

// Epoch 30 is in the second step.
require.NoError(s.AddRewards(ctx, 30, mustInitQuantityP(t, 100), escrowAddrAsList), "add rewards epoch 30")
require.NoError(s.AddRewards(ctx, 30, mustInitQuantityP(t, 100_000), escrowAddrAsList), "add rewards epoch 30")

// 50% gain.
escrowAccount, err = s.Account(ctx, escrowAddr)
Expand All @@ -244,7 +244,7 @@ func TestRewardAndSlash(t *testing.T) {
require.Equal(mustInitQuantityP(t, 9800), commonPool, "reward first step - common pool")

// Epoch 99 is after the end of the schedule
require.NoError(s.AddRewards(ctx, 99, mustInitQuantityP(t, 100), escrowAddrAsList), "add rewards epoch 99")
require.NoError(s.AddRewards(ctx, 99, mustInitQuantityP(t, 100_000), escrowAddrAsList), "add rewards epoch 99")

// No change.
escrowAccount, err = s.Account(ctx, escrowAddr)
Expand All @@ -268,7 +268,7 @@ func TestRewardAndSlash(t *testing.T) {
require.Equal(mustInitQuantityP(t, 9840), commonPool, "slash - common pool")

// Epoch 10 is during the first step.
require.NoError(s.AddRewardSingleAttenuated(ctx, 10, mustInitQuantityP(t, 10), 5, 10, escrowAddr), "add attenuated rewards epoch 30")
require.NoError(s.AddRewardSingleAttenuated(ctx, 10, mustInitQuantityP(t, 10_000), 5, 10, escrowAddr), "add attenuated rewards epoch 30")

// 5% gain.
escrowAccount, err = s.Account(ctx, escrowAddr)
Expand Down
4 changes: 2 additions & 2 deletions go/staking/api/rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ type RewardStep struct {
}

func init() {
// Denominated in 1000th of a percent.
// Denominated in one millionth of a percent.
RewardAmountDenominator = quantity.NewQuantity()
err := RewardAmountDenominator.FromBigInt(big.NewInt(100_000))
err := RewardAmountDenominator.FromBigInt(big.NewInt(100_000_000))
if err != nil {
panic(err)
}
Expand Down