Skip to content

Commit

Permalink
backport/fix epoching ante handler (#385) (#386)
Browse files Browse the repository at this point in the history
- fixes epoching ante handler that returned early from ante handler even
in case of success validation of staking message
  • Loading branch information
KonradStaniec authored Jan 6, 2025
1 parent f403d80 commit 0ad4cb2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
of the block in `TallyBlocks` function
- [#378](https://github.com/babylonlabs-io/babylon/pull/378) Fix give out rewards
with gaps of unfinalized blocks
- [#385](https://github.com/babylonlabs-io/babylon/pull/385) Fix epoching module
ante handler to return from antehandler chain only in case of error

## v1.0.0-rc2

Expand Down
5 changes: 3 additions & 2 deletions x/epoching/keeper/drop_validator_msg_decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ func (qmd DropValidatorMsgDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
}
// after genesis, if validator-related message, reject msg
for _, msg := range tx.GetMsgs() {
err := qmd.ValidateMsg(msg)
return ctx, err
if err := qmd.ValidateMsg(msg); err != nil {
return sdk.Context{}, err
}
}

return next(ctx, tx, simulate)
Expand Down
45 changes: 45 additions & 0 deletions x/epoching/keeper/drop_validator_msg_decorator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"testing"

appparams "github.com/babylonlabs-io/babylon/app/params"
"github.com/babylonlabs-io/babylon/x/epoching/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authz "github.com/cosmos/cosmos-sdk/x/authz"
Expand Down Expand Up @@ -55,3 +56,47 @@ func TestDropValidatorMsgDecorator(t *testing.T) {
}
}
}

func TestReturnNilErrorNotCallNext(t *testing.T) {
decorator := NewDropValidatorMsgDecorator(&Keeper{})
ctx := sdk.Context{}.WithBlockHeight(1)
createValidatorMsg := &stakingtypes.MsgCreateValidator{}
encCfg := appparams.DefaultEncodingConfig()

builder := encCfg.TxConfig.NewTxBuilder()
builder.SetMsgs(createValidatorMsg)
tx := builder.GetTx()

nextAnteHandlerCalled := false
next := func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) {
nextAnteHandlerCalled = true
return ctx, nil
}

ctx, err := decorator.AnteHandle(ctx, tx, false, next)
require.Error(t, err)
require.Equal(t, sdk.Context{}, ctx)
require.False(t, nextAnteHandlerCalled)
}

func TestReturnSuccessCallNext(t *testing.T) {
decorator := NewDropValidatorMsgDecorator(&Keeper{})
ctx := sdk.Context{}.WithBlockHeight(1)
createValidatorMsg := &stakingtypes.MsgEditValidator{}
encCfg := appparams.DefaultEncodingConfig()

builder := encCfg.TxConfig.NewTxBuilder()
builder.SetMsgs(createValidatorMsg)
tx := builder.GetTx()
nextAnteHandlerCalled := false

next := func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) {
nextAnteHandlerCalled = true
return ctx, nil
}

ctx, err := decorator.AnteHandle(ctx, tx, false, next)
require.NoError(t, err)
require.Equal(t, ctx, ctx)
require.True(t, nextAnteHandlerCalled)
}

0 comments on commit 0ad4cb2

Please sign in to comment.