diff --git a/CHANGELOG.md b/CHANGELOG.md index a99751bf4a..d94dbc095e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (ante) [\#866](https://github.com/tharsis/ethermint/pull/866) `NewAnteHandler` constructor now receives a `HandlerOptions` field. * (evm) [\#849](https://github.com/tharsis/ethermint/pull/849) `PostTxProcessing` hook now takes an Ethereum tx `Receipt` and a `from` `Address` as arguments. +* (ante) [#916](https://github.com/tharsis/ethermint/pull/916) don't check min-gas-price for eth tx if london hardfork enabled and feemarket enabled. ### State Machine Breaking diff --git a/app/ante/eth.go b/app/ante/eth.go index ae4dce5a57..4ed65a644b 100644 --- a/app/ante/eth.go +++ b/app/ante/eth.go @@ -221,15 +221,13 @@ func (egcd EthGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula // CanTransferDecorator checks if the sender is allowed to transfer funds according to the EVM block // context rules. type CanTransferDecorator struct { - evmKeeper EVMKeeper - feemarketKeeper evmtypes.FeeMarketKeeper + evmKeeper EVMKeeper } // NewCanTransferDecorator creates a new CanTransferDecorator instance. -func NewCanTransferDecorator(evmKeeper EVMKeeper, fmk evmtypes.FeeMarketKeeper) CanTransferDecorator { +func NewCanTransferDecorator(evmKeeper EVMKeeper) CanTransferDecorator { return CanTransferDecorator{ - evmKeeper: evmKeeper, - feemarketKeeper: fmk, + evmKeeper: evmKeeper, } } @@ -477,45 +475,38 @@ func (esc EthSetupContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul // If fee is high enough or not CheckTx, then call next AnteHandler // CONTRACT: Tx must implement FeeTx to use MempoolFeeDecorator type EthMempoolFeeDecorator struct { - feemarketKeeper evmtypes.FeeMarketKeeper - evmKeeper EVMKeeper + evmKeeper EVMKeeper } -func NewEthMempoolFeeDecorator(ek EVMKeeper, fmk evmtypes.FeeMarketKeeper) EthMempoolFeeDecorator { +func NewEthMempoolFeeDecorator(ek EVMKeeper) EthMempoolFeeDecorator { return EthMempoolFeeDecorator{ - feemarketKeeper: fmk, - evmKeeper: ek, + evmKeeper: ek, } } // AnteHandle ensures that the provided fees meet a minimum threshold for the validator, // if this is a CheckTx. This is only for local mempool purposes, and thus // is only ran on check tx. +// It only do the check if london hardfork not enabled or feemarket not enabled, because in that case feemarket will take over the task. func (mfd EthMempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { if ctx.IsCheckTx() && !simulate { - for _, msg := range tx.GetMsgs() { - ethMsg, ok := msg.(*evmtypes.MsgEthereumTx) - if !ok { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil)) - } - - var feeAmt *big.Int - - params := mfd.evmKeeper.GetParams(ctx) - chainID := mfd.evmKeeper.ChainID() - ethCfg := params.ChainConfig.EthereumConfig(chainID) - evmDenom := params.EvmDenom - baseFee := mfd.evmKeeper.BaseFee(ctx, ethCfg) - if baseFee != nil { - feeAmt = ethMsg.GetEffectiveFee(baseFee) - } else { - feeAmt = ethMsg.GetFee() - } - - glDec := sdk.NewDec(int64(ethMsg.GetGas())) - requiredFee := ctx.MinGasPrices().AmountOf(evmDenom).Mul(glDec) - if sdk.NewDecFromBigInt(feeAmt).LT(requiredFee) { - return ctx, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "insufficient fees; got: %s required: %s", feeAmt, requiredFee) + params := mfd.evmKeeper.GetParams(ctx) + ethCfg := params.ChainConfig.EthereumConfig(mfd.evmKeeper.ChainID()) + baseFee := mfd.evmKeeper.BaseFee(ctx, ethCfg) + if baseFee == nil { + for _, msg := range tx.GetMsgs() { + ethMsg, ok := msg.(*evmtypes.MsgEthereumTx) + if !ok { + return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil)) + } + + evmDenom := params.EvmDenom + feeAmt := ethMsg.GetFee() + glDec := sdk.NewDec(int64(ethMsg.GetGas())) + requiredFee := ctx.MinGasPrices().AmountOf(evmDenom).Mul(glDec) + if sdk.NewDecFromBigInt(feeAmt).LT(requiredFee) { + return ctx, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "insufficient fees; got: %s required: %s", feeAmt, requiredFee) + } } } } diff --git a/app/ante/eth_test.go b/app/ante/eth_test.go index e181e1fc96..80f5455baa 100644 --- a/app/ante/eth_test.go +++ b/app/ante/eth_test.go @@ -293,7 +293,7 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() { } func (suite AnteTestSuite) TestCanTransferDecorator() { - dec := ante.NewCanTransferDecorator(suite.app.EvmKeeper, suite.app.FeeMarketKeeper) + dec := ante.NewCanTransferDecorator(suite.app.EvmKeeper) addr, privKey := tests.NewAddrKey() diff --git a/app/ante/handler_options.go b/app/ante/handler_options.go index b960df3947..1defef7bc5 100644 --- a/app/ante/handler_options.go +++ b/app/ante/handler_options.go @@ -48,13 +48,13 @@ func (options HandlerOptions) Validate() error { func newEthAnteHandler(options HandlerOptions) sdk.AnteHandler { return sdk.ChainAnteDecorators( - NewEthSetUpContextDecorator(options.EvmKeeper), // outermost AnteDecorator. SetUpContext must be called first - NewEthMempoolFeeDecorator(options.EvmKeeper, options.FeeMarketKeeper), // Check eth effective gas price against minimal-gas-prices + NewEthSetUpContextDecorator(options.EvmKeeper), // outermost AnteDecorator. SetUpContext must be called first + NewEthMempoolFeeDecorator(options.EvmKeeper), // Check eth effective gas price against minimal-gas-prices NewEthValidateBasicDecorator(options.EvmKeeper), NewEthSigVerificationDecorator(options.EvmKeeper), NewEthAccountVerificationDecorator(options.AccountKeeper, options.BankKeeper, options.EvmKeeper), NewEthGasConsumeDecorator(options.EvmKeeper), - NewCanTransferDecorator(options.EvmKeeper, options.FeeMarketKeeper), + NewCanTransferDecorator(options.EvmKeeper), NewEthIncrementSenderSequenceDecorator(options.AccountKeeper), // innermost AnteDecorator. ) } diff --git a/rpc/ethereum/backend/backend.go b/rpc/ethereum/backend/backend.go index 0cb68c0560..25eecc90fd 100644 --- a/rpc/ethereum/backend/backend.go +++ b/rpc/ethereum/backend/backend.go @@ -976,9 +976,9 @@ func (e *EVMBackend) ChainConfig() *params.ChainConfig { } // SuggestGasTipCap returns the suggested tip cap +// always return zero since we don't support tx prioritization yet. func (e *EVMBackend) SuggestGasTipCap() (*big.Int, error) { - out := new(big.Int).SetInt64(e.RPCMinGasPrice()) - return out, nil + return big.NewInt(0), nil } // BaseFee returns the base fee tracked by the Fee Market module. If the base fee is not enabled, diff --git a/rpc/ethereum/namespaces/eth/api.go b/rpc/ethereum/namespaces/eth/api.go index 2cac0699d8..a9f70e8690 100644 --- a/rpc/ethereum/namespaces/eth/api.go +++ b/rpc/ethereum/namespaces/eth/api.go @@ -193,16 +193,22 @@ func (e *PublicAPI) Hashrate() hexutil.Uint64 { // GasPrice returns the current gas price based on Ethermint's gas price oracle. func (e *PublicAPI) GasPrice() (*hexutil.Big, error) { e.logger.Debug("eth_gasPrice") - tipcap, err := e.backend.SuggestGasTipCap() - if err != nil { - return nil, err - } - + var ( + result *big.Int + err error + ) if head := e.backend.CurrentHeader(); head.BaseFee != nil { - tipcap.Add(tipcap, head.BaseFee) + result, err = e.backend.SuggestGasTipCap() + if err != nil { + return nil, err + } + + result = result.Add(result, head.BaseFee) + } else { + result = big.NewInt(e.backend.RPCMinGasPrice()) } - return (*hexutil.Big)(tipcap), nil + return (*hexutil.Big)(result), nil } // MaxPriorityFeePerGas returns a suggestion for a gas tip cap for dynamic fee transactions.