Skip to content

Commit

Permalink
Merge pull request #107 from plex/reject-vesting-msg
Browse files Browse the repository at this point in the history
feat: add decorator to reject msgCreateClawbackVestingAccount in anteHandler
  • Loading branch information
tkkwon1998 authored Jul 18, 2023
2 parents eeb000f + 18640b4 commit c7c0964
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 7 deletions.
6 changes: 4 additions & 2 deletions app/ante/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
cosmosante.NewAuthzLimiterDecorator(
sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}),
sdk.MsgTypeURL(&sdkvesting.MsgCreateVestingAccount{}),
sdk.MsgTypeURL(&vestingtypes.MsgCreateClawbackVestingAccount{}),
),
ante.NewSetUpContextDecorator(),
ante.NewRejectExtensionOptionsDecorator(),
Expand All @@ -94,7 +95,7 @@ func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper),
NewVestingDelegationDecorator(options.AccountKeeper, options.StakingKeeper, options.Cdc),
NewRejectClawbackVestingAccount(),
NewValidatorCommissionDecorator(options.Cdc),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
Expand All @@ -114,6 +115,7 @@ func newCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {
cosmosante.NewAuthzLimiterDecorator(
sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}),
sdk.MsgTypeURL(&sdkvesting.MsgCreateVestingAccount{}),
sdk.MsgTypeURL(&vestingtypes.MsgCreateClawbackVestingAccount{}),
),
ante.NewSetUpContextDecorator(),
ante.NewMempoolFeeDecorator(),
Expand All @@ -123,7 +125,7 @@ func newCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper),
NewVestingDelegationDecorator(options.AccountKeeper, options.StakingKeeper, options.Cdc),
NewRejectClawbackVestingAccount(),
NewValidatorCommissionDecorator(options.Cdc),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
Expand Down
30 changes: 25 additions & 5 deletions app/ante/vesting.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ func NewEthVestingTransactionDecorator(ak evmtypes.AccountKeeper) EthVestingTran
// vesting cliff and lockup period.
//
// This AnteHandler decorator will fail if:
// - the message is not a MsgEthereumTx
// - sender account cannot be found
// - sender account is not a ClawbackvestingAccount
// - blocktime is before surpassing vesting cliff end (with zero vested coins) AND
// - blocktime is before surpassing all lockup periods (with non-zero locked coins)
// - the message is not a MsgEthereumTx
// - sender account cannot be found
// - sender account is not a ClawbackvestingAccount
// - blocktime is before surpassing vesting cliff end (with zero vested coins) AND
// - blocktime is before surpassing all lockup periods (with non-zero locked coins)
func (vtd EthVestingTransactionDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
for _, msg := range tx.GetMsgs() {
msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx)
Expand Down Expand Up @@ -174,3 +174,23 @@ func (vdd VestingDelegationDecorator) validateMsg(ctx sdk.Context, msg sdk.Msg)

return nil
}

// RejectClawbackVestingAccount prevents MsgCreateClawbackVestingAccount from being executed
type RejectClawbackVestingAccount struct{}

func (rvd RejectClawbackVestingAccount) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
for _, msg := range tx.GetMsgs() {
if _, ok := msg.(*vestingtypes.MsgCreateClawbackVestingAccount); ok {
return ctx, sdkerrors.Wrapf(
sdkerrors.ErrInvalidType,
"cannot create clawback vesting account with MsgCreateClawbackVestingAccount",
)
}
}
return next(ctx, tx, simulate)
}

// NewVestingDelegationDecorator creates a new VestingDelegationDecorator
func NewRejectClawbackVestingAccount() RejectClawbackVestingAccount {
return RejectClawbackVestingAccount{}
}
9 changes: 9 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ import (
v3 "github.com/Canto-Network/Canto/v6/app/upgrades/v3"
v4 "github.com/Canto-Network/Canto/v6/app/upgrades/v4"
v5 "github.com/Canto-Network/Canto/v6/app/upgrades/v5"
v6 "github.com/Canto-Network/Canto/v6/app/upgrades/v6"
)

func init() {
Expand Down Expand Up @@ -1076,6 +1077,12 @@ func (app *Canto) setupUpgradeHandlers() {
v5.CreateUpgradeHandler(app.mm, app.configurator),
)

// v6 upgrade handler
app.UpgradeKeeper.SetUpgradeHandler(
v6.UpgradeName,
v6.CreateUpgradeHandler(app.mm, app.configurator),
)

// When a planned update height is reached, the old binary will panic
// writing on disk the height and name of the update that triggered it
// This will read that value, and execute the preparations for the upgrade.
Expand Down Expand Up @@ -1104,6 +1111,8 @@ func (app *Canto) setupUpgradeHandlers() {
storeUpgrades = &storetypes.StoreUpgrades{
Added: []string{csrtypes.StoreKey},
}
case v6.UpgradeName:
// no store upgrades in v6
}

if storeUpgrades != nil {
Expand Down
6 changes: 6 additions & 0 deletions app/upgrades/v6/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package v6

const (
//UpgradeName is the name of the upgrade to be associated with the chain upgrade
UpgradeName = "v6.0.0"
)
21 changes: 21 additions & 0 deletions app/upgrades/v6/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package v6

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

// CreateUpgradeHandler creates an SDK upgrade handler for v6
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
logger := ctx.Logger().With("upgrade: ", UpgradeName)

// Leave modules are as-is to avoid running InitGenesis.
logger.Debug("running module migrations ...")
return mm.RunMigrations(ctx, configurator, vm)
}
}

0 comments on commit c7c0964

Please sign in to comment.