2022-01-02 22:44:46 +00:00
|
|
|
package ante
|
|
|
|
|
|
|
|
import (
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
|
|
"github.com/cosmos/cosmos-sdk/types/tx/signing"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth/ante"
|
|
|
|
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
|
|
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
|
|
|
2022-01-03 16:30:28 +00:00
|
|
|
ibcante "github.com/cosmos/ibc-go/v3/modules/core/ante"
|
2022-03-11 10:31:16 +00:00
|
|
|
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"
|
2022-01-02 22:44:46 +00:00
|
|
|
|
|
|
|
evmtypes "github.com/tharsis/ethermint/x/evm/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
|
|
|
|
// channel keeper, EVM Keeper and Fee Market Keeper.
|
|
|
|
type HandlerOptions struct {
|
2022-03-11 10:31:16 +00:00
|
|
|
AccountKeeper evmtypes.AccountKeeper
|
|
|
|
BankKeeper evmtypes.BankKeeper
|
|
|
|
IBCKeeper *ibckeeper.Keeper
|
|
|
|
FeeMarketKeeper evmtypes.FeeMarketKeeper
|
|
|
|
EvmKeeper EVMKeeper
|
|
|
|
FeegrantKeeper ante.FeegrantKeeper
|
|
|
|
SignModeHandler authsigning.SignModeHandler
|
|
|
|
SigGasConsumer func(meter sdk.GasMeter, sig signing.SignatureV2, params authtypes.Params) error
|
2022-03-21 09:01:21 +00:00
|
|
|
MaxTxGasWanted uint64
|
2022-01-02 22:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (options HandlerOptions) Validate() error {
|
|
|
|
if options.AccountKeeper == nil {
|
|
|
|
return sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
|
|
|
|
}
|
|
|
|
if options.BankKeeper == nil {
|
|
|
|
return sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
|
|
|
|
}
|
|
|
|
if options.SignModeHandler == nil {
|
|
|
|
return sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
|
|
|
|
}
|
|
|
|
if options.FeeMarketKeeper == nil {
|
|
|
|
return sdkerrors.Wrap(sdkerrors.ErrLogic, "fee market keeper is required for AnteHandler")
|
|
|
|
}
|
|
|
|
if options.EvmKeeper == nil {
|
|
|
|
return sdkerrors.Wrap(sdkerrors.ErrLogic, "evm keeper is required for AnteHandler")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func newEthAnteHandler(options HandlerOptions) sdk.AnteHandler {
|
|
|
|
return sdk.ChainAnteDecorators(
|
2022-01-26 10:44:41 +00:00
|
|
|
NewEthSetUpContextDecorator(options.EvmKeeper), // outermost AnteDecorator. SetUpContext must be called first
|
|
|
|
NewEthMempoolFeeDecorator(options.EvmKeeper), // Check eth effective gas price against minimal-gas-prices
|
2022-01-02 22:44:46 +00:00
|
|
|
NewEthValidateBasicDecorator(options.EvmKeeper),
|
|
|
|
NewEthSigVerificationDecorator(options.EvmKeeper),
|
2022-05-02 16:48:40 +00:00
|
|
|
NewEthAccountVerificationDecorator(options.AccountKeeper, options.EvmKeeper),
|
2022-03-21 09:01:21 +00:00
|
|
|
NewEthGasConsumeDecorator(options.EvmKeeper, options.MaxTxGasWanted),
|
2022-01-26 10:44:41 +00:00
|
|
|
NewCanTransferDecorator(options.EvmKeeper),
|
2022-01-02 22:44:46 +00:00
|
|
|
NewEthIncrementSenderSequenceDecorator(options.AccountKeeper), // innermost AnteDecorator.
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
|
|
|
|
return sdk.ChainAnteDecorators(
|
|
|
|
RejectMessagesDecorator{}, // reject MsgEthereumTxs
|
|
|
|
ante.NewSetUpContextDecorator(),
|
|
|
|
ante.NewRejectExtensionOptionsDecorator(),
|
|
|
|
ante.NewMempoolFeeDecorator(),
|
|
|
|
ante.NewValidateBasicDecorator(),
|
|
|
|
ante.NewTxTimeoutHeightDecorator(),
|
|
|
|
ante.NewValidateMemoDecorator(options.AccountKeeper),
|
|
|
|
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
|
|
|
|
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper),
|
|
|
|
// SetPubKeyDecorator must be called before all signature verification decorators
|
|
|
|
ante.NewSetPubKeyDecorator(options.AccountKeeper),
|
|
|
|
ante.NewValidateSigCountDecorator(options.AccountKeeper),
|
|
|
|
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
|
|
|
|
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
|
|
|
|
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
|
2022-03-11 10:31:16 +00:00
|
|
|
ibcante.NewAnteDecorator(options.IBCKeeper),
|
2022-01-02 22:44:46 +00:00
|
|
|
)
|
|
|
|
}
|
2022-02-26 16:34:43 +00:00
|
|
|
|
|
|
|
func newCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {
|
|
|
|
return sdk.ChainAnteDecorators(
|
|
|
|
RejectMessagesDecorator{}, // reject MsgEthereumTxs
|
|
|
|
ante.NewSetUpContextDecorator(),
|
|
|
|
// NOTE: extensions option decorator removed
|
|
|
|
// ante.NewRejectExtensionOptionsDecorator(),
|
|
|
|
ante.NewMempoolFeeDecorator(),
|
|
|
|
ante.NewValidateBasicDecorator(),
|
|
|
|
ante.NewTxTimeoutHeightDecorator(),
|
|
|
|
ante.NewValidateMemoDecorator(options.AccountKeeper),
|
|
|
|
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
|
|
|
|
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper),
|
|
|
|
// SetPubKeyDecorator must be called before all signature verification decorators
|
|
|
|
ante.NewSetPubKeyDecorator(options.AccountKeeper),
|
|
|
|
ante.NewValidateSigCountDecorator(options.AccountKeeper),
|
|
|
|
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
|
|
|
|
// Note: signature verification uses EIP instead of the cosmos signature validator
|
|
|
|
NewEip712SigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
|
|
|
|
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
|
2022-03-11 10:31:16 +00:00
|
|
|
ibcante.NewAnteDecorator(options.IBCKeeper),
|
2022-02-26 16:34:43 +00:00
|
|
|
)
|
|
|
|
}
|