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(observer): remove error return on staking hooks #2968

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions x/observer/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@
func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, _ sdk.ConsAddress, valAddr sdk.ValAddress) error {
err := h.k.CleanObservers(ctx, valAddr)
if err != nil {
return err
ctx.Logger().Error("Error cleaning observer set", "error", err)

Check warning on line 18 in x/observer/keeper/hooks.go

View check run for this annotation

Codecov / codecov/patch

x/observer/keeper/hooks.go#L18

Added line #L18 was not covered by tests
}
return nil
lumtis marked this conversation as resolved.
Show resolved Hide resolved
}

func (h Hooks) AfterValidatorBeginUnbonding(ctx sdk.Context, _ sdk.ConsAddress, valAddr sdk.ValAddress) error {
err := h.k.CheckAndCleanObserver(ctx, valAddr)
if err != nil {
return err
ctx.Logger().Error("Error cleaning observer set", "error", err)

Check warning on line 26 in x/observer/keeper/hooks.go

View check run for this annotation

Codecov / codecov/patch

x/observer/keeper/hooks.go#L26

Added line #L26 was not covered by tests
}
return nil
lumtis marked this conversation as resolved.
Show resolved Hide resolved
}

func (h Hooks) AfterDelegationModified(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error {
err := h.k.CheckAndCleanObserverDelegator(ctx, valAddr, delAddr)
if err != nil {
return err
ctx.Logger().Error("Error cleaning observer set", "error", err)

Check warning on line 34 in x/observer/keeper/hooks.go

View check run for this annotation

Codecov / codecov/patch

x/observer/keeper/hooks.go#L34

Added line #L34 was not covered by tests
}
return nil
lumtis marked this conversation as resolved.
Show resolved Hide resolved
}

func (h Hooks) BeforeValidatorSlashed(ctx sdk.Context, valAddr sdk.ValAddress, fraction sdk.Dec) error {
err := h.k.CleanSlashedValidator(ctx, valAddr, fraction)
if err != nil {
return err
ctx.Logger().Error("Error cleaning observer set", "error", err)
}
return nil
}
Expand Down
9 changes: 7 additions & 2 deletions x/observer/keeper/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,20 @@ func TestKeeper_AfterDelegationModified(t *testing.T) {
}

func TestKeeper_BeforeValidatorSlashed(t *testing.T) {
t.Run("should error if validator not found", func(t *testing.T) {
t.Run("should not error if validator not found", func(t *testing.T) {
k, ctx, _, _ := keepertest.ObserverKeeper(t)

r := rand.New(rand.NewSource(9))
validator := sample.Validator(t, r)
os := sample.ObserverSet(10)
k.SetObserverSet(ctx, os)

hooks := k.Hooks()
err := hooks.BeforeValidatorSlashed(ctx, validator.GetOperator(), sdk.NewDec(1))
require.Error(t, err)
require.NoError(t, err)
storedOs, found := k.GetObserverSet(ctx)
require.True(t, found)
require.Equal(t, os, storedOs)
})

t.Run("should not error if observer set not found", func(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions x/observer/keeper/voting.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/pkg/errors"

"github.com/zeta-chain/node/pkg/chains"
"github.com/zeta-chain/node/x/observer/types"
Expand Down Expand Up @@ -134,12 +135,12 @@ func (k Keeper) CheckObserverSelfDelegation(ctx sdk.Context, accAddress string)
}
validator, found := k.stakingKeeper.GetValidator(ctx, valAddress)
if !found {
return types.ErrNotValidator
return errors.Wrapf(types.ErrNotValidator, "validator : %s", valAddress)
}

delegation, found := k.stakingKeeper.GetDelegation(ctx, selfdelAddr, valAddress)
if !found {
return types.ErrSelfDelegation
return errors.Wrapf(types.ErrSelfDelegation, "self delegation : %s , valAddres : %s", selfdelAddr, valAddress)
}

minDelegation, err := types.GetMinObserverDelegationDec()
Expand Down
Loading