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(distribution)!: use collections for ValidatorCurrentRewards #16459

Merged
merged 10 commits into from
Jun 9, 2023

Conversation

testinginprod
Copy link
Contributor

@testinginprod testinginprod commented Jun 8, 2023

Description

Closes: #16460


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 in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • 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 in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • 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)

@@ -179,50 +179,6 @@ func (k Keeper) GetValidatorHistoricalReferenceCount(ctx context.Context) (count
return
}

// get current rewards for a validator
func (k Keeper) GetValidatorCurrentRewards(ctx context.Context, val sdk.ValAddress) (rewards types.ValidatorCurrentRewards, err error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a small behavioural change for which:

  • Before: if reward did not exist, we do not error but return un-initialised types.ValidatorCurrentRewards
  • Now: if reward does not exist we error.

if err != nil {
currentRewards, err := k.ValidatorCurrentRewards.Get(ctx, val.GetOperator())
// if the rewards do not exist it's fine, we will just add to zero.
if err != nil && !errors.Is(err, collections.ErrNotFound) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is where the behavioural change had impact, so we explictly use zero coins in case the current rewards did not exist.

@@ -14,7 +14,7 @@ import (
// initialize starting info for a new delegation
func (k Keeper) initializeDelegation(ctx context.Context, val sdk.ValAddress, del sdk.AccAddress) error {
// period has already been incremented - we want to store the period ended by this delegation action
valCurrentRewards, err := k.GetValidatorCurrentRewards(ctx, val)
valCurrentRewards, err := k.ValidatorCurrentRewards.Get(ctx, val)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

returning a zeroed validator current rewards would have yielded to a uint64 underflow.

rewards, err := k.GetValidatorCurrentRewards(ctx, val.GetOperator())
if err != nil {
rewards, err := k.ValidatorCurrentRewards.Get(ctx, val.GetOperator())
if err != nil && !errors.Is(err, collections.ErrNotFound) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

retaining old behaviour

@testinginprod testinginprod marked this pull request as ready for review June 8, 2023 11:24
@testinginprod testinginprod requested a review from a team as a code owner June 8, 2023 11:24
@github-prbot github-prbot requested review from a team, kocubinski and julienrbrt and removed request for a team June 8, 2023 11:24
@facundomedica facundomedica self-assigned this Jun 8, 2023
Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

LGTM!

CHANGELOG.md Outdated Show resolved Hide resolved
@testinginprod testinginprod enabled auto-merge June 8, 2023 23:30
Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

lgtm!

@testinginprod testinginprod added this pull request to the merge queue Jun 9, 2023
Merged via the queue into main with commit 2d1d68d Jun 9, 2023
@testinginprod testinginprod deleted the tip/distribution/coll_validator_current_rewards branch June 9, 2023 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

refactor(distribution): use collections for ValidatorCurrentRewards state management.
5 participants