forked from cerc-io/laconicd-deprecated
e1560849dd
* Set priority for eth transactions Set the tx priority to the lowest priority in the messages. fix unit tests code cleanup and spec update spec fix go lint add priority integration test add python linter job add access list tx type fix gas limit remove ledger tag, so no need to replace hid dependency fix earlier check ibc-go v5.0.0-beta1 * fix pruned node integration test * Update x/feemarket/spec/09_antehandlers.md Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
113 lines
5.4 KiB
Go
113 lines
5.4 KiB
Go
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"
|
|
|
|
ibcante "github.com/cosmos/ibc-go/v5/modules/core/ante"
|
|
ibckeeper "github.com/cosmos/ibc-go/v5/modules/core/keeper"
|
|
|
|
evmtypes "github.com/evmos/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 {
|
|
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
|
|
MaxTxGasWanted uint64
|
|
ExtensionOptionChecker ante.ExtensionOptionChecker
|
|
TxFeeChecker ante.TxFeeChecker
|
|
}
|
|
|
|
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(
|
|
NewEthSetUpContextDecorator(options.EvmKeeper), // outermost AnteDecorator. SetUpContext must be called first
|
|
NewEthMempoolFeeDecorator(options.EvmKeeper), // Check eth effective gas price against minimal-gas-prices
|
|
NewEthMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper), // Check eth effective gas price against the global MinGasPrice
|
|
NewEthValidateBasicDecorator(options.EvmKeeper),
|
|
NewEthSigVerificationDecorator(options.EvmKeeper),
|
|
NewEthAccountVerificationDecorator(options.AccountKeeper, options.EvmKeeper),
|
|
NewCanTransferDecorator(options.EvmKeeper),
|
|
NewEthGasConsumeDecorator(options.EvmKeeper, options.MaxTxGasWanted),
|
|
NewEthIncrementSenderSequenceDecorator(options.AccountKeeper), // innermost AnteDecorator.
|
|
NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper),
|
|
NewEthEmitEventDecorator(options.EvmKeeper), // emit eth tx hash and index at the very last ante handler.
|
|
)
|
|
}
|
|
|
|
func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
|
|
return sdk.ChainAnteDecorators(
|
|
RejectMessagesDecorator{}, // reject MsgEthereumTxs
|
|
ante.NewSetUpContextDecorator(),
|
|
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
|
|
NewMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper),
|
|
ante.NewValidateBasicDecorator(),
|
|
ante.NewTxTimeoutHeightDecorator(),
|
|
ante.NewValidateMemoDecorator(options.AccountKeeper),
|
|
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
|
|
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),
|
|
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
|
|
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
|
|
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
|
|
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
|
|
NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper),
|
|
)
|
|
}
|
|
|
|
func newCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {
|
|
return sdk.ChainAnteDecorators(
|
|
RejectMessagesDecorator{}, // reject MsgEthereumTxs
|
|
ante.NewSetUpContextDecorator(),
|
|
// NOTE: extensions option decorator removed
|
|
// ante.NewRejectExtensionOptionsDecorator(),
|
|
NewMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper),
|
|
ante.NewValidateBasicDecorator(),
|
|
ante.NewTxTimeoutHeightDecorator(),
|
|
ante.NewValidateMemoDecorator(options.AccountKeeper),
|
|
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
|
|
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),
|
|
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),
|
|
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
|
|
NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper),
|
|
)
|
|
}
|