Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exempt system txs from min gas check and fee deduction #1605

Merged
merged 19 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 53 additions & 22 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

import (
"fmt"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"

Check failure on line 20 in app/ante/ante.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed (goimports)
"runtime/debug"

stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ethante "github.com/evmos/ethermint/app/ante"
cctxtypes "github.com/zeta-chain/zetacore/x/crosschain/types"

tmlog "github.com/tendermint/tendermint/libs/log"
Expand All @@ -29,9 +29,10 @@
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/authz"
)

func ValidateHandlerOptions(options ethante.HandlerOptions) error {
func ValidateHandlerOptions(options HandlerOptions) error {
if options.AccountKeeper == nil {
return errorsmod.Wrap(errortypes.ErrLogic, "account keeper is required for AnteHandler")
}
Expand All @@ -47,14 +48,17 @@
if options.EvmKeeper == nil {
return errorsmod.Wrap(errortypes.ErrLogic, "evm keeper is required for AnteHandler")
}
if options.ObserverKeeper == nil {
return errorsmod.Wrap(errortypes.ErrLogic, "observer keeper is required for AnteHandler")
}
return nil
}

// NewAnteHandler returns an ante handler responsible for attempting to route an
// Ethereum or SDK transaction to an internal ante handler for performing
// transaction-level processing (e.g. fee payment, signature verification) before
// being passed onto it's respective handler.
func NewAnteHandler(options ethante.HandlerOptions) (sdk.AnteHandler, error) {
func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if err := ValidateHandlerOptions(options); err != nil {
return nil, err
}
Expand Down Expand Up @@ -94,28 +98,55 @@
// handle as totally normal Cosmos SDK tx
switch tx.(type) {
case sdk.Tx:
found := false
for _, msg := range tx.GetMsgs() {
switch msg.(type) {
// treat these three msg types differently because they might call EVM which results in massive gas consumption
// For these two msg types, we don't check gas limit by using a different ante handler
case *cctxtypes.MsgGasPriceVoter, *cctxtypes.MsgVoteOnObservedInboundTx:
found = true
break
case *stakingtypes.MsgCreateValidator:
if ctx.BlockHeight() == 0 {
found = true
break
}
anteHandler = newCosmosAnteHandler(options)
if len(tx.GetMsgs()) != 1 {
break
}
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved

msg := tx.GetMsgs()[0] // now we must have len(tx.GetMsgs()) == 1
var innerMsg sdk.Msg
innerMsg = msg
if mm, ok := msg.(*authz.MsgExec); ok { // authz tx; look inside it
brewmaster012 marked this conversation as resolved.
Show resolved Hide resolved
msgs, err := mm.GetMessages()
if err == nil && len(msgs) == 1 {
innerMsg = msgs[0]
}
}
if len(tx.GetMsgs()) == 1 && found {
// this differs newCosmosAnteHandler only in that it doesn't check gas limit
// by using an Infinite Gas Meter.
anteHandler = newCosmosAnteHandlerNoGasLimit(options)
} else {
anteHandler = newCosmosAnteHandler(options)

isAuthorize := options.ObserverKeeper.IsAuthorized
brewmaster012 marked this conversation as resolved.
Show resolved Hide resolved
if mm, ok := innerMsg.(*cctxtypes.MsgGasPriceVoter); ok && isAuthorize(ctx, mm.Creator) {
brewmaster012 marked this conversation as resolved.
Show resolved Hide resolved
lumtis marked this conversation as resolved.
Show resolved Hide resolved
anteHandler = newCosmosAnteHandlerNoGasFee(options)
break
}
if mm, ok := innerMsg.(*cctxtypes.MsgVoteOnObservedInboundTx); ok && isAuthorize(ctx, mm.Creator) {
anteHandler = newCosmosAnteHandlerNoGasFee(options)
break
}
if mm, ok := innerMsg.(*cctxtypes.MsgVoteOnObservedOutboundTx); ok && isAuthorize(ctx, mm.Creator) {
anteHandler = newCosmosAnteHandlerNoGasFee(options)
break
}
if mm, ok := innerMsg.(*cctxtypes.MsgAddToOutTxTracker); ok && isAuthorize(ctx, mm.Creator) {
anteHandler = newCosmosAnteHandlerNoGasFee(options)
break
}
if mm, ok := innerMsg.(*cctxtypes.MsgCreateTSSVoter); ok && isAuthorize(ctx, mm.Creator) {
anteHandler = newCosmosAnteHandlerNoGasFee(options)
break
}
if mm, ok := innerMsg.(*observertypes.MsgAddBlockHeader); ok && isAuthorize(ctx, mm.Creator) {
anteHandler = newCosmosAnteHandlerNoGasFee(options)
break
}
if mm, ok := innerMsg.(*observertypes.MsgAddBlameVote); ok && isAuthorize(ctx, mm.Creator) {
anteHandler = newCosmosAnteHandlerNoGasFee(options)
break
}
if _, ok := innerMsg.(*stakingtypes.MsgCreateValidator); ok && ctx.BlockHeight() == 0 {
anteHandler = newCosmosAnteHandlerNoGasFee(options)
break
}

default:
return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid transaction type: %T", tx)
}
Expand Down
38 changes: 31 additions & 7 deletions app/ante/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,40 @@
package ante

import (
"fmt"

Check failure on line 20 in app/ante/handler_options.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed (goimports)
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
observerkeeper "github.com/zeta-chain/zetacore/x/observer/keeper"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
ibcante "github.com/cosmos/ibc-go/v6/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v6/modules/core/keeper"
ethante "github.com/evmos/ethermint/app/ante"
ethermint "github.com/evmos/ethermint/types"
)

func NewLegacyCosmosAnteHandlerEip712(options ethante.HandlerOptions) sdk.AnteHandler {
type HandlerOptions struct {
AccountKeeper evmtypes.AccountKeeper
BankKeeper evmtypes.BankKeeper
IBCKeeper *ibckeeper.Keeper
FeeMarketKeeper FeeMarketKeeper
EvmKeeper EVMKeeper
FeegrantKeeper ante.FeegrantKeeper
SignModeHandler authsigning.SignModeHandler
SigGasConsumer func(meter sdk.GasMeter, sig signing.SignatureV2, params authtypes.Params) error
MaxTxGasWanted uint64
ExtensionOptionChecker ante.ExtensionOptionChecker
TxFeeChecker ante.TxFeeChecker
DisabledAuthzMsgs []string
ObserverKeeper *observerkeeper.Keeper
}

func NewLegacyCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
ethante.RejectMessagesDecorator{}, // reject MsgEthereumTxs
NewAuthzLimiterDecorator(options.DisabledAuthzMsgs...),
Expand All @@ -52,7 +74,7 @@
)
}

func newEthAnteHandler(options ethante.HandlerOptions) sdk.AnteHandler {
func newEthAnteHandler(options HandlerOptions) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
ethante.NewEthSetUpContextDecorator(options.EvmKeeper), // outermost AnteDecorator. SetUpContext must be called first
ethante.NewEthMempoolFeeDecorator(options.EvmKeeper), // Check eth effective gas price against minimal-gas-prices
Expand All @@ -68,7 +90,7 @@
)
}

func newCosmosAnteHandler(options ethante.HandlerOptions) sdk.AnteHandler {
func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
ethante.RejectMessagesDecorator{}, // reject MsgEthereumTxs
NewAuthzLimiterDecorator(options.DisabledAuthzMsgs...),
Expand All @@ -92,19 +114,21 @@
}

// this applies to special cosmos tx that calls EVM, in which case the EVM overrides the gas limit
func newCosmosAnteHandlerNoGasLimit(options ethante.HandlerOptions) sdk.AnteHandler {
func newCosmosAnteHandlerNoGasFee(options HandlerOptions) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
ethante.RejectMessagesDecorator{}, // reject MsgEthereumTxs
NewAuthzLimiterDecorator(options.DisabledAuthzMsgs...),
NewVestingAccountDecorator(),
NewSetUpContextDecorator(),
ante.NewSetUpContextDecorator(),
brewmaster012 marked this conversation as resolved.
Show resolved Hide resolved
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
NewMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper),
// system txs are not subject to minimum gas price check
//NewMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
// the following decorators are disabled; so no fees are deducted for special system txs.
//ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
ante.NewValidateSigCountDecorator(options.AccountKeeper),
Expand Down
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ func New(
app.SetBeginBlocker(app.BeginBlocker)

maxGasWanted := cast.ToUint64(appOpts.Get(srvflags.EVMMaxTxGasWanted))
options := evmante.HandlerOptions{
options := ante.HandlerOptions{
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
EvmKeeper: app.EvmKeeper,
Expand All @@ -589,6 +589,7 @@ func New(
sdk.MsgTypeURL(&vestingtypes.MsgCreatePermanentLockedAccount{}),
sdk.MsgTypeURL(&vestingtypes.MsgCreatePeriodicVestingAccount{}),
},
ObserverKeeper: app.ZetaObserverKeeper,
}

anteHandler, err := ante.NewAnteHandler(options)
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

* [1535](https://github.com/zeta-chain/node/issues/1535) - Avoid voting on wrong ballots due to false blockNumber in EVM tx receipt
* [1588](https://github.com/zeta-chain/node/pull/1588) - fix chain params comparison logic
* [1650](https://github.com/zeta-chain/node/pull/1605) - exempt *system txs* from min gas price check and gas fee deduction

## Version: v12.0.0

Expand Down
Loading