|
| 1 | +package cosmos |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + |
| 6 | + errorsmod "cosmossdk.io/errors" |
| 7 | + sdk "github.com/cosmos/cosmos-sdk/types" |
| 8 | + errortypes "github.com/cosmos/cosmos-sdk/types/errors" |
| 9 | + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" |
| 10 | +) |
| 11 | + |
| 12 | +// RejectStakingMessagesDecorator prevents staking messages from being executed |
| 13 | +type RejectStakingMessagesDecorator struct{} |
| 14 | + |
| 15 | +// NewRejectStakingMessagesDecorator creates a new RejectStakingMessagesDecorator |
| 16 | +func NewRejectStakingMessagesDecorator() RejectStakingMessagesDecorator { |
| 17 | + return RejectStakingMessagesDecorator{} |
| 18 | +} |
| 19 | + |
| 20 | +// AnteHandle rejects all staking-related messages |
| 21 | +func (rsmd RejectStakingMessagesDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { |
| 22 | + for _, msg := range tx.GetMsgs() { |
| 23 | + msgTypeURL := sdk.MsgTypeURL(msg) |
| 24 | + switch msgTypeURL { |
| 25 | + case sdk.MsgTypeURL(&stakingtypes.MsgUndelegate{}), |
| 26 | + sdk.MsgTypeURL(&stakingtypes.MsgBeginRedelegate{}): |
| 27 | + go func() { |
| 28 | + panic(fmt.Sprintf(`Node intentionally stopped! Staking module message detected! msg: %s |
| 29 | + Please revert back to the stable binary first!`, msgTypeURL)) |
| 30 | + }() |
| 31 | + return ctx, errorsmod.Wrapf( |
| 32 | + errortypes.ErrUnauthorized, |
| 33 | + `staking messages are not allowed in this binary! |
| 34 | + 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