mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +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,14 +23,60 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
|||||||
|
|
||||||
decorator := ante.NewVestingAccountDecorator()
|
decorator := ante.NewVestingAccountDecorator()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
msg sdk.Msg
|
||||||
|
wantHasErr bool
|
||||||
|
wantErr string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"MsgCreateVestingAccount",
|
||||||
|
vesting.NewMsgCreateVestingAccount(
|
||||||
|
testAddresses[0], testAddresses[1],
|
||||||
|
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
||||||
|
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC).Unix(),
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
true,
|
||||||
|
"MsgTypeURL /cosmos.vesting.v1beta1.MsgCreateVestingAccount not supported",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"MsgCreateVestingAccount",
|
||||||
|
vesting.NewMsgCreatePermanentLockedAccount(
|
||||||
|
testAddresses[0], testAddresses[1],
|
||||||
|
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
||||||
|
),
|
||||||
|
true,
|
||||||
|
"MsgTypeURL /cosmos.vesting.v1beta1.MsgCreatePermanentLockedAccount not supported",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"MsgCreateVestingAccount",
|
||||||
|
vesting.NewMsgCreatePeriodicVestingAccount(
|
||||||
|
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(
|
tx, err := helpers.GenSignedMockTx(
|
||||||
rand.New(rand.NewSource(time.Now().UnixNano())),
|
rand.New(rand.NewSource(time.Now().UnixNano())),
|
||||||
txConfig,
|
txConfig,
|
||||||
[]sdk.Msg{
|
[]sdk.Msg{
|
||||||
vesting.NewMsgCreateVestingAccount(
|
tt.msg,
|
||||||
testAddresses[0], testAddresses[1],
|
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
|
||||||
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC).Unix(), false),
|
|
||||||
},
|
},
|
||||||
sdk.NewCoins(),
|
sdk.NewCoins(),
|
||||||
helpers.DefaultGenTxGas,
|
helpers.DefaultGenTxGas,
|
||||||
@ -39,9 +86,18 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
|||||||
testPrivKeys[0],
|
testPrivKeys[0],
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
mmd := MockAnteHandler{}
|
mmd := MockAnteHandler{}
|
||||||
ctx := sdk.Context{}.WithIsCheckTx(true)
|
ctx := sdk.Context{}.WithIsCheckTx(true)
|
||||||
|
|
||||||
_, err = decorator.AnteHandle(ctx, tx, false, mmd.AnteHandle)
|
_, err = decorator.AnteHandle(ctx, tx, false, mmd.AnteHandle)
|
||||||
|
|
||||||
|
if tt.wantHasErr {
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
require.Contains(t, err.Error(), "MsgCreateVestingAccount not supported")
|
require.Contains(t, err.Error(), tt.wantErr)
|
||||||
|
} else {
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user