Skip to content

Commit

Permalink
fix: RewardBallotWinners determinism (#1433)
Browse files Browse the repository at this point in the history
## Description

Fixes RC1 Canon consensus failure.

Bug was in: https://github.com/umee-network/umee/pull/1433/files#diff-971aeedb004816fd5770d86dfa2d9ee39c5e53d7802773dd9e81cbc2cf890f62L60

---

### Author Checklist

_All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues._

I have...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] added appropriate labels to the PR
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/umee-network/umee/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

_All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items._

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
robert-zaremba authored Sep 20, 2022
1 parent f8863d9 commit 09bbf02
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion x/oracle/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) error {
int64(params.VotePeriod),
int64(params.RewardDistributionWindow),
voteTargetDenoms,
validatorClaimMap,
claimSlice,
)

// Clear the ballot
Expand Down
3 changes: 2 additions & 1 deletion x/oracle/keeper/reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (k Keeper) RewardBallotWinners(
votePeriod int64,
rewardDistributionWindow int64,
voteTargets []string,
ballotWinners map[string]types.Claim,
ballotWinners []types.Claim,
) {
rewardDenoms := make([]string, len(voteTargets)+1)
rewardDenoms[0] = types.UmeeDenom
Expand Down Expand Up @@ -57,6 +57,7 @@ func (k Keeper) RewardBallotWinners(

// distribute rewards
var distributedReward sdk.Coins

for _, winner := range ballotWinners {
receiverVal := k.StakingKeeper.Validator(ctx, winner.Recipient)
// in case absence of the validator, we just skip distribution
Expand Down
9 changes: 5 additions & 4 deletions x/oracle/keeper/reward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
// Test the reward giving mechanism
func (s *IntegrationTestSuite) TestRewardBallotWinners() {
// Add claim pools
claims := map[string]types.Claim{
valAddr.String(): types.NewClaim(10, 10, 0, valAddr),
valAddr2.String(): types.NewClaim(20, 20, 0, valAddr2),
claims := []types.Claim{
types.NewClaim(10, 10, 0, valAddr),
types.NewClaim(20, 20, 0, valAddr2),
}

// Prepare reward pool
Expand All @@ -38,7 +38,8 @@ func (s *IntegrationTestSuite) TestRewardBallotWinners() {
}

func (s *IntegrationTestSuite) TestRewardBallotWinnersZeroPower() {
s.app.OracleKeeper.RewardBallotWinners(s.ctx, 0, 0, []string{}, map[string]types.Claim{valAddr.String(): {}})
zeroClaim := types.NewClaim(0, 0, 0, valAddr)
s.app.OracleKeeper.RewardBallotWinners(s.ctx, 0, 0, []string{}, []types.Claim{zeroClaim})
outstandingRewardsDec := s.app.DistrKeeper.GetValidatorOutstandingRewardsCoins(s.ctx, valAddr)
s.Require().Equal("", outstandingRewardsDec.String())
}

0 comments on commit 09bbf02

Please sign in to comment.