Skip to content

Commit

Permalink
fix(slash): Fix no slash info (#199)
Browse files Browse the repository at this point in the history
* fix the issue regarding no slash info
  • Loading branch information
TimmyExogenous authored Sep 27, 2024
1 parent b7a9717 commit 70c8691
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions x/delegation/keeper/delegation_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,12 @@ func (k *Keeper) DeleteStakersListForOperator(ctx sdk.Context, operator, assetID
return nil
}

func (k Keeper) HasStakerList(ctx sdk.Context, operator, assetID string) bool {
store := prefix.NewStore(ctx.KVStore(k.storeKey), delegationtype.KeyPrefixStakersByOperator)
Key := assetstype.GetJoinedStoreKey(operator, assetID)
return store.Has(Key)
}

func (k Keeper) GetStakersByOperator(ctx sdk.Context, operator, assetID string) (delegationtype.StakerList, error) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), delegationtype.KeyPrefixStakersByOperator)
Key := assetstype.GetJoinedStoreKey(operator, assetID)
Expand Down
3 changes: 2 additions & 1 deletion x/operator/keeper/slash.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ func (k *Keeper) SlashAssets(ctx sdk.Context, parameter *types.SlashInputInfo) (
// all shares need to be cleared if the asset amount is slashed to zero,
// otherwise there will be a problem in updating the shares when handling
// the new delegations.
if remainingAmount.IsZero() {
if remainingAmount.IsZero() &&
k.delegationKeeper.HasStakerList(ctx, parameter.Operator.String(), assetID) {
// clear the share of other stakers
stakerList, err := k.delegationKeeper.GetStakersByOperator(ctx, parameter.Operator.String(), assetID)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions x/operator/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type DelegationKeeper interface {
IterateUndelegationsByOperator(
ctx sdk.Context, operator string, heightFilter *uint64, isUpdate bool,
opFunc func(undelegation *delegationtype.UndelegationRecord) error) error
HasStakerList(ctx sdk.Context, operator, assetID string) bool
GetStakersByOperator(
ctx sdk.Context, operator, assetID string,
) (delegationtype.StakerList, error)
Expand Down

0 comments on commit 70c8691

Please sign in to comment.