From f99763256af048ff561cb2f0b9ed37a16ec8ca91 Mon Sep 17 00:00:00 2001 From: lumtis Date: Fri, 4 Oct 2024 12:31:20 +0200 Subject: [PATCH 1/3] update hook --- x/observer/keeper/hooks.go | 8 ++++---- x/observer/keeper/hooks_test.go | 9 +++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/x/observer/keeper/hooks.go b/x/observer/keeper/hooks.go index ec002b5a2f..631abd00e3 100644 --- a/x/observer/keeper/hooks.go +++ b/x/observer/keeper/hooks.go @@ -15,7 +15,7 @@ type Hooks struct { 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) } return nil } @@ -23,7 +23,7 @@ func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, _ sdk.ConsAddress, valAddr 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) } return nil } @@ -31,7 +31,7 @@ func (h Hooks) AfterValidatorBeginUnbonding(ctx sdk.Context, _ sdk.ConsAddress, 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) } return nil } @@ -39,7 +39,7 @@ func (h Hooks) AfterDelegationModified(ctx sdk.Context, delAddr sdk.AccAddress, 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 } diff --git a/x/observer/keeper/hooks_test.go b/x/observer/keeper/hooks_test.go index 7b5ef7ed64..09088bed44 100644 --- a/x/observer/keeper/hooks_test.go +++ b/x/observer/keeper/hooks_test.go @@ -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) { From 3d2adf311dd3d163527ce4bf7d2b3a38aa7f90c5 Mon Sep 17 00:00:00 2001 From: lumtis Date: Fri, 4 Oct 2024 12:32:19 +0200 Subject: [PATCH 2/3] update errors --- x/observer/keeper/voting.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x/observer/keeper/voting.go b/x/observer/keeper/voting.go index 1f624da5aa..51286665c8 100644 --- a/x/observer/keeper/voting.go +++ b/x/observer/keeper/voting.go @@ -2,6 +2,7 @@ package keeper import ( "fmt" + "github.com/pkg/errors" sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" @@ -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() From 2ffbb5aeda22d47ea66486b03ce0fc06a7459be7 Mon Sep 17 00:00:00 2001 From: lumtis Date: Fri, 4 Oct 2024 12:43:17 +0200 Subject: [PATCH 3/3] generate --- x/observer/keeper/voting.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/observer/keeper/voting.go b/x/observer/keeper/voting.go index 51286665c8..9314c1bca2 100644 --- a/x/observer/keeper/voting.go +++ b/x/observer/keeper/voting.go @@ -2,10 +2,10 @@ package keeper import ( "fmt" - "github.com/pkg/errors" 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"