Skip to content

Commit

Permalink
feat: use ante handler to filter msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
karzak committed Jun 7, 2021
1 parent 62e4344 commit a8ec141
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func NewAnteHandler(ak keeper.AccountKeeper, supplyKeeper types.SupplyKeeper, si
decorators = append(decorators, NewAuthenticatedMempoolDecorator(addressFetchers...))
}
decorators = append(decorators,
NewUpdateV142MempoolDecorator(),
ante.NewMempoolFeeDecorator(),
ante.NewValidateBasicDecorator(),
ante.NewValidateMemoDecorator(ak),
Expand Down
50 changes: 50 additions & 0 deletions app/ante/update_v014.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package ante

import (
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

"github.com/kava-labs/kava/x/kavadist"
)

var v0142UpgradeTime = time.Date(2021, 6, 14, 14, 0, 0, 0, time.UTC)

// UpdateV142MempoolDecorator blocks new tx types from reaching the mempool until after the upgrade time
type UpdateV142MempoolDecorator struct {
}

func NewUpdateV142MempoolDecorator() UpdateV142MempoolDecorator {
return UpdateV142MempoolDecorator{}
}

func (umd UpdateV142MempoolDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
if ctx.BlockTime().After(v0142UpgradeTime) {
return next(ctx, tx, simulate)
}
msgs := tx.GetMsgs()
for _, msg := range msgs {
if isUpdateMsgType(msg.Type()) {
return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "tx not valid until after upgrade")
}
proposalMsg, ok := msg.(govtypes.MsgSubmitProposal)
if ok {
switch proposalMsg.Content.(type) {
case kavadist.CommunityPoolMultiSpendProposal:
return ctx, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "tx not valid until after upgrade")
default:
continue
}
}
}
return next(ctx, tx, simulate)
}

func isUpdateMsgType(msgType string) bool {
if msgType == "claim_hard_reward_vvesting" || msgType == "claim_usdx_minting_reward_vvesting" {
return true
}
return false
}

0 comments on commit a8ec141

Please sign in to comment.