|
| 1 | +package cosmos |
| 2 | + |
| 3 | +import ( |
| 4 | + errorsmod "cosmossdk.io/errors" |
| 5 | + sdk "github.com/cosmos/cosmos-sdk/types" |
| 6 | + errortypes "github.com/cosmos/cosmos-sdk/types/errors" |
| 7 | + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" |
| 8 | +) |
| 9 | + |
| 10 | +// RejectStakingMessagesDecorator prevents staking messages from being executed |
| 11 | +type RejectStakingMessagesDecorator struct{} |
| 12 | + |
| 13 | +// NewRejectStakingMessagesDecorator creates a new RejectStakingMessagesDecorator |
| 14 | +func NewRejectStakingMessagesDecorator() RejectStakingMessagesDecorator { |
| 15 | + return RejectStakingMessagesDecorator{} |
| 16 | +} |
| 17 | + |
| 18 | +// AnteHandle rejects all staking-related messages |
| 19 | +func (rsmd RejectStakingMessagesDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { |
| 20 | + for _, msg := range tx.GetMsgs() { |
| 21 | + msgTypeURL := sdk.MsgTypeURL(msg) |
| 22 | + |
| 23 | + // Check if the message is a staking message |
| 24 | + switch msgTypeURL { |
| 25 | + case sdk.MsgTypeURL(&stakingtypes.MsgCreateValidator{}), |
| 26 | + sdk.MsgTypeURL(&stakingtypes.MsgDelegate{}), |
| 27 | + sdk.MsgTypeURL(&stakingtypes.MsgUndelegate{}), |
| 28 | + sdk.MsgTypeURL(&stakingtypes.MsgBeginRedelegate{}), |
| 29 | + sdk.MsgTypeURL(&stakingtypes.MsgCancelUnbondingDelegation{}), |
| 30 | + sdk.MsgTypeURL(&stakingtypes.MsgEditValidator{}), |
| 31 | + sdk.MsgTypeURL(&stakingtypes.MsgUpdateParams{}): |
| 32 | + return ctx, errorsmod.Wrapf( |
| 33 | + errortypes.ErrUnauthorized, |
| 34 | + "staking messages are not allowed in this binary! impending app hash mismatch on this node! revert back to the previous version first! msg: %s", msgTypeURL, |
| 35 | + ) |
| 36 | + } |
| 37 | + } |
| 38 | + return next(ctx, tx, simulate) |
| 39 | +} |
0 commit comments