mirror of
				https://github.com/0glabs/0g-chain.git
				synced 2025-11-04 10:37:26 +00:00 
			
		
		
		
	feat: block new vesting create messages (#1539)
* Block new vesting create messages * doc: Update VestingAccountDecorator doc comment
This commit is contained in:
		
							parent
							
								
									1c09ae98ae
								
							
						
					
					
						commit
						82f5ed5c3c
					
				@ -143,6 +143,8 @@ func newCosmosAnteHandler(options cosmosHandlerOptions) sdk.AnteHandler {
 | 
				
			|||||||
		NewAuthzLimiterDecorator(
 | 
							NewAuthzLimiterDecorator(
 | 
				
			||||||
			sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}),
 | 
								sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}),
 | 
				
			||||||
			sdk.MsgTypeURL(&vesting.MsgCreateVestingAccount{}),
 | 
								sdk.MsgTypeURL(&vesting.MsgCreateVestingAccount{}),
 | 
				
			||||||
 | 
								sdk.MsgTypeURL(&vesting.MsgCreatePermanentLockedAccount{}),
 | 
				
			||||||
 | 
								sdk.MsgTypeURL(&vesting.MsgCreatePeriodicVestingAccount{}),
 | 
				
			||||||
		),
 | 
							),
 | 
				
			||||||
		authante.NewValidateBasicDecorator(),
 | 
							authante.NewValidateBasicDecorator(),
 | 
				
			||||||
		authante.NewTxTimeoutHeightDecorator(),
 | 
							authante.NewTxTimeoutHeightDecorator(),
 | 
				
			||||||
 | 
				
			|||||||
@ -9,17 +9,38 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
var _ sdk.AnteDecorator = VestingAccountDecorator{}
 | 
					var _ sdk.AnteDecorator = VestingAccountDecorator{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// VestingAccountDecorator blocks MsgCreateVestingAccount from reaching the mempool
 | 
					// VestingAccountDecorator blocks vesting messages from reaching the mempool
 | 
				
			||||||
type VestingAccountDecorator struct{}
 | 
					type VestingAccountDecorator struct {
 | 
				
			||||||
 | 
						disabledMsgTypeUrls []string
 | 
				
			||||||
func NewVestingAccountDecorator() VestingAccountDecorator {
 | 
					 | 
				
			||||||
	return VestingAccountDecorator{}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (vad VestingAccountDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
 | 
					func NewVestingAccountDecorator() VestingAccountDecorator {
 | 
				
			||||||
 | 
						return VestingAccountDecorator{
 | 
				
			||||||
 | 
							disabledMsgTypeUrls: []string{
 | 
				
			||||||
 | 
								sdk.MsgTypeURL(&vesting.MsgCreateVestingAccount{}),
 | 
				
			||||||
 | 
								sdk.MsgTypeURL(&vesting.MsgCreatePermanentLockedAccount{}),
 | 
				
			||||||
 | 
								sdk.MsgTypeURL(&vesting.MsgCreatePeriodicVestingAccount{}),
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (vad VestingAccountDecorator) AnteHandle(
 | 
				
			||||||
 | 
						ctx sdk.Context,
 | 
				
			||||||
 | 
						tx sdk.Tx,
 | 
				
			||||||
 | 
						simulate bool,
 | 
				
			||||||
 | 
						next sdk.AnteHandler,
 | 
				
			||||||
 | 
					) (newCtx sdk.Context, err error) {
 | 
				
			||||||
	for _, msg := range tx.GetMsgs() {
 | 
						for _, msg := range tx.GetMsgs() {
 | 
				
			||||||
		if _, ok := msg.(*vesting.MsgCreateVestingAccount); ok {
 | 
							typeUrl := sdk.MsgTypeURL(msg)
 | 
				
			||||||
			return ctx, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "MsgCreateVestingAccount not supported")
 | 
					
 | 
				
			||||||
 | 
							for _, disabledTypeUrl := range vad.disabledMsgTypeUrls {
 | 
				
			||||||
 | 
								if typeUrl == disabledTypeUrl {
 | 
				
			||||||
 | 
									return ctx, errorsmod.Wrapf(
 | 
				
			||||||
 | 
										sdkerrors.ErrUnauthorized,
 | 
				
			||||||
 | 
										"MsgTypeURL %s not supported",
 | 
				
			||||||
 | 
										typeUrl,
 | 
				
			||||||
 | 
									)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -10,6 +10,7 @@ import (
 | 
				
			|||||||
	"github.com/cosmos/cosmos-sdk/simapp/helpers"
 | 
						"github.com/cosmos/cosmos-sdk/simapp/helpers"
 | 
				
			||||||
	sdk "github.com/cosmos/cosmos-sdk/types"
 | 
						sdk "github.com/cosmos/cosmos-sdk/types"
 | 
				
			||||||
	vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
 | 
						vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
 | 
				
			||||||
 | 
						banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/kava-labs/kava/app"
 | 
						"github.com/kava-labs/kava/app"
 | 
				
			||||||
	"github.com/kava-labs/kava/app/ante"
 | 
						"github.com/kava-labs/kava/app/ante"
 | 
				
			||||||
@ -22,26 +23,81 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	decorator := ante.NewVestingAccountDecorator()
 | 
						decorator := ante.NewVestingAccountDecorator()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tx, err := helpers.GenSignedMockTx(
 | 
						tests := []struct {
 | 
				
			||||||
		rand.New(rand.NewSource(time.Now().UnixNano())),
 | 
							name       string
 | 
				
			||||||
		txConfig,
 | 
							msg        sdk.Msg
 | 
				
			||||||
		[]sdk.Msg{
 | 
							wantHasErr bool
 | 
				
			||||||
 | 
							wantErr    string
 | 
				
			||||||
 | 
						}{
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								"MsgCreateVestingAccount",
 | 
				
			||||||
			vesting.NewMsgCreateVestingAccount(
 | 
								vesting.NewMsgCreateVestingAccount(
 | 
				
			||||||
				testAddresses[0], testAddresses[1],
 | 
									testAddresses[0], testAddresses[1],
 | 
				
			||||||
				sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
 | 
									sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
 | 
				
			||||||
				time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC).Unix(), false),
 | 
									time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC).Unix(),
 | 
				
			||||||
 | 
									false,
 | 
				
			||||||
 | 
								),
 | 
				
			||||||
 | 
								true,
 | 
				
			||||||
 | 
								"MsgTypeURL /cosmos.vesting.v1beta1.MsgCreateVestingAccount not supported",
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		sdk.NewCoins(),
 | 
							{
 | 
				
			||||||
		helpers.DefaultGenTxGas,
 | 
								"MsgCreateVestingAccount",
 | 
				
			||||||
		"testing-chain-id",
 | 
								vesting.NewMsgCreatePermanentLockedAccount(
 | 
				
			||||||
		[]uint64{0},
 | 
									testAddresses[0], testAddresses[1],
 | 
				
			||||||
		[]uint64{0},
 | 
									sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
 | 
				
			||||||
		testPrivKeys[0],
 | 
								),
 | 
				
			||||||
	)
 | 
								true,
 | 
				
			||||||
	require.NoError(t, err)
 | 
								"MsgTypeURL /cosmos.vesting.v1beta1.MsgCreatePermanentLockedAccount not supported",
 | 
				
			||||||
	mmd := MockAnteHandler{}
 | 
							},
 | 
				
			||||||
	ctx := sdk.Context{}.WithIsCheckTx(true)
 | 
							{
 | 
				
			||||||
	_, err = decorator.AnteHandle(ctx, tx, false, mmd.AnteHandle)
 | 
								"MsgCreateVestingAccount",
 | 
				
			||||||
	require.Error(t, err)
 | 
								vesting.NewMsgCreatePeriodicVestingAccount(
 | 
				
			||||||
	require.Contains(t, err.Error(), "MsgCreateVestingAccount not supported")
 | 
									testAddresses[0], testAddresses[1],
 | 
				
			||||||
 | 
									time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC).Unix(),
 | 
				
			||||||
 | 
									nil,
 | 
				
			||||||
 | 
								),
 | 
				
			||||||
 | 
								true,
 | 
				
			||||||
 | 
								"MsgTypeURL /cosmos.vesting.v1beta1.MsgCreatePeriodicVestingAccount not supported",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								"other messages not affected",
 | 
				
			||||||
 | 
								banktypes.NewMsgSend(
 | 
				
			||||||
 | 
									testAddresses[0], testAddresses[1],
 | 
				
			||||||
 | 
									sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
 | 
				
			||||||
 | 
								),
 | 
				
			||||||
 | 
								false,
 | 
				
			||||||
 | 
								"",
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, tt := range tests {
 | 
				
			||||||
 | 
							t.Run(tt.name, func(t *testing.T) {
 | 
				
			||||||
 | 
								tx, err := helpers.GenSignedMockTx(
 | 
				
			||||||
 | 
									rand.New(rand.NewSource(time.Now().UnixNano())),
 | 
				
			||||||
 | 
									txConfig,
 | 
				
			||||||
 | 
									[]sdk.Msg{
 | 
				
			||||||
 | 
										tt.msg,
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
									sdk.NewCoins(),
 | 
				
			||||||
 | 
									helpers.DefaultGenTxGas,
 | 
				
			||||||
 | 
									"testing-chain-id",
 | 
				
			||||||
 | 
									[]uint64{0},
 | 
				
			||||||
 | 
									[]uint64{0},
 | 
				
			||||||
 | 
									testPrivKeys[0],
 | 
				
			||||||
 | 
								)
 | 
				
			||||||
 | 
								require.NoError(t, err)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								mmd := MockAnteHandler{}
 | 
				
			||||||
 | 
								ctx := sdk.Context{}.WithIsCheckTx(true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								_, err = decorator.AnteHandle(ctx, tx, false, mmd.AnteHandle)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if tt.wantHasErr {
 | 
				
			||||||
 | 
									require.Error(t, err)
 | 
				
			||||||
 | 
									require.Contains(t, err.Error(), tt.wantErr)
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									require.NoError(t, err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user