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

fix: delegated amount double updates #534

Merged
merged 2 commits into from
Jun 19, 2023
Merged
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
11 changes: 6 additions & 5 deletions x/liquidstakeibc/keeper/icq.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ func ValidatorSetCallback(k Keeper, ctx sdk.Context, data []byte, query icqtypes
}

for _, validator := range response.Validators {
val, found := hc.GetValidator(validator.OperatorAddress)
val, exists := hc.GetValidator(validator.OperatorAddress)

// if it is a new validator or any of the attributes we track has changed, query for it
if !found || (val != nil && (validator.Status.String() != val.Status ||
if !exists || (val != nil && (validator.Status.String() != val.Status ||
!validator.DelegatorShares.Equal(val.DelegatorShares) || !validator.Tokens.Equal(val.TotalAmount))) {
if err := k.QueryHostChainValidator(ctx, hc, validator.OperatorAddress); err != nil {
return errorsmod.Wrapf(types.ErrFailedICQRequest, "error querying for validator: %s", err.Error())
Expand Down Expand Up @@ -147,6 +147,10 @@ func DelegationCallback(k Keeper, ctx sdk.Context, data []byte, query icqtypes.Q
"slashed-amount:", slashedAmount,
)

// update the delegated amount to the slashed amount
validator.DelegatedAmount = delegatedAmount
k.SetHostChainValidator(ctx, hc, validator)

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeSlashing,
Expand All @@ -157,9 +161,6 @@ func DelegationCallback(k Keeper, ctx sdk.Context, data []byte, query icqtypes.Q
)})
}

validator.DelegatedAmount = delegatedAmount
k.SetHostChainValidator(ctx, hc, validator)

return nil
}

Expand Down