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

Disable messages on consumer chain #272

Merged
merged 1 commit into from
Aug 30, 2022
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
31 changes: 31 additions & 0 deletions app/consumer/ante/disabled_modules_ante.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ante

import (
"fmt"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
)

type DisabledModulesDecorator struct {
prefixes []string
}

func NewDisabledModulesDecorator(disabledModules ...string) DisabledModulesDecorator {
return DisabledModulesDecorator{prefixes: disabledModules}
}

func (dmd DisabledModulesDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
currHeight := ctx.BlockHeight()
for _, msg := range tx.GetMsgs() {
msgTypeURL := sdk.MsgTypeURL(msg)

for _, prefix := range dmd.prefixes {
if strings.HasPrefix(msgTypeURL, prefix) {
return ctx, fmt.Errorf("tx contains message types from unsupported modules at height %d", currHeight)
}
}
}

return next(ctx, tx, simulate)
}
78 changes: 78 additions & 0 deletions app/consumer/ante/disabled_modules_ante_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package ante_test

import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
ibcclienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
appconsumer "github.com/cosmos/interchain-security/app/consumer"
"github.com/cosmos/interchain-security/app/consumer/ante"
"github.com/stretchr/testify/require"
"github.com/tendermint/spm/cosmoscmd"
)

func TestDisabledModulesDecorator(t *testing.T) {
txCfg := cosmoscmd.MakeEncodingConfig(appconsumer.ModuleBasics).TxConfig

testCases := []struct {
name string
ctx sdk.Context
msgs []sdk.Msg
expectErr bool
}{
{
name: "IBC module messages supported",
ctx: sdk.Context{},
msgs: []sdk.Msg{
&ibcclienttypes.MsgUpdateClient{},
},
expectErr: false,
},
{
name: "bank module messages supported",
ctx: sdk.Context{},
msgs: []sdk.Msg{
&banktypes.MsgSend{},
},
expectErr: false,
},
{
name: "evidence module messages not supported",
ctx: sdk.Context{},
msgs: []sdk.Msg{
&evidencetypes.MsgSubmitEvidence{},
},
expectErr: true,
},
{
name: "slashing module messages not supported",
ctx: sdk.Context{},
msgs: []sdk.Msg{
&slashingtypes.MsgUnjail{},
},
expectErr: true,
},
}

for _, tc := range testCases {
tc := tc

t.Run(tc.name, func(t *testing.T) {
handler := ante.NewDisabledModulesDecorator("/cosmos.evidence", "/cosmos.slashing")

txBuilder := txCfg.NewTxBuilder()
require.NoError(t, txBuilder.SetMsgs(tc.msgs...))

_, err := handler.AnteHandle(tc.ctx, txBuilder.GetTx(), false,
func(ctx sdk.Context, _ sdk.Tx, _ bool) (sdk.Context, error) { return ctx, nil })
if tc.expectErr {
require.Error(t, err)
} else {
require.NoError(t, err)
}
})
}
}
1 change: 1 addition & 0 deletions app/consumer/ante_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
ante.NewSetUpContextDecorator(),
ante.NewRejectExtensionOptionsDecorator(),
consumerante.NewMsgFilterDecorator(options.ConsumerKeeper),
consumerante.NewDisabledModulesDecorator("/cosmos.evidence", "/cosmos.slashing"),
ante.NewMempoolFeeDecorator(),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
Expand Down