-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
refactor(distribution)!: use collections for ValidatorCurrentRewards #16459
Conversation
@@ -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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
retaining old behaviour
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
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...
!
to the type prefix if API or client breaking changeCHANGELOG.md
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...
!
in the type prefix if API or client breaking change