-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix(evm): mempool fee checker * Update evmante_handler.go * feat: add GetEffectiveGasPrice to MsgEthereumTx * refactor: use less local variables by inlining expressions * fix: set correct block gas used * refactor: remove GetBaseFeeNoCfg * feat(evm): add global_min_gas_price * refactor: rename K to EvmKeeper in tests * refactor: clean up doc and rename test * feat(evm): default 1unibi for global gas price * feat(evm): add GlobalGasPriceDecorator ante handler * feat(evm): add GlobalGasPriceDecorator ante handler * feat(evm): hard-code baseFee to 1unibi for now * Update CHANGELOG.md * fix: bigint to dec comparison * fix: base fee query default * fix: adjust for gas price in e2e tests * chore(evm): rip out GlobalGasPriceDecorator * chore(evm): rip out GlobalMinGasPrice * Update gas_fees.go * Update evmante_handler.go
- Loading branch information
Showing
24 changed files
with
248 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) 2023-2024 Nibi, Inc. | ||
package evmante | ||
|
||
import ( | ||
"cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
errortypes "github.com/cosmos/cosmos-sdk/types/errors" | ||
|
||
"github.com/NibiruChain/nibiru/x/evm" | ||
) | ||
|
||
var _ sdk.AnteDecorator = MempoolGasPriceDecorator{} | ||
|
||
// MempoolGasPriceDecorator will check if the transaction's fee is at least as large | ||
// as the mempool MinGasPrices param. If fee is too low, decorator returns error and tx | ||
// is rejected. This applies to CheckTx only. | ||
// If fee is high enough, then call next AnteHandler | ||
type MempoolGasPriceDecorator struct { | ||
evmKeeper EVMKeeper | ||
} | ||
|
||
// NewMempoolGasPriceDecorator creates a new MinGasPriceDecorator instance used only for | ||
// Ethereum transactions. | ||
func NewMempoolGasPriceDecorator(k EVMKeeper) MempoolGasPriceDecorator { | ||
return MempoolGasPriceDecorator{ | ||
evmKeeper: k, | ||
} | ||
} | ||
|
||
// AnteHandle ensures that the effective fee from the transaction is greater than the | ||
// local mempool gas prices, which is defined by the MinGasPrice (parameter) * GasLimit (tx argument). | ||
func (d MempoolGasPriceDecorator) AnteHandle( | ||
ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler, | ||
) (newCtx sdk.Context, err error) { | ||
// only run on CheckTx | ||
if !ctx.IsCheckTx() && !simulate { | ||
return next(ctx, tx, simulate) | ||
} | ||
|
||
minGasPrice := ctx.MinGasPrices().AmountOf(d.evmKeeper.GetParams(ctx).EvmDenom) | ||
// if MinGasPrices is not set, skip the check | ||
if minGasPrice.IsZero() { | ||
return next(ctx, tx, simulate) | ||
} | ||
|
||
baseFee := d.evmKeeper.GetBaseFee(ctx) | ||
|
||
for _, msg := range tx.GetMsgs() { | ||
ethTx, ok := msg.(*evm.MsgEthereumTx) | ||
if !ok { | ||
return ctx, errors.Wrapf( | ||
errortypes.ErrUnknownRequest, | ||
"invalid message type %T, expected %T", | ||
msg, (*evm.MsgEthereumTx)(nil), | ||
) | ||
} | ||
|
||
effectiveGasPrice := ethTx.GetEffectiveGasPrice(baseFee) | ||
|
||
if sdk.NewDecFromBigInt(effectiveGasPrice).LT(minGasPrice) { | ||
return ctx, errors.Wrapf( | ||
errortypes.ErrInsufficientFee, | ||
"provided gas price < minimum local gas price (%s < %s). "+ | ||
"Please increase the priority tip (for EIP-1559 txs) or the gas prices "+ | ||
"(for access list or legacy txs)", | ||
effectiveGasPrice.String(), minGasPrice.String(), | ||
) | ||
} | ||
} | ||
|
||
return next(ctx, tx, simulate) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.