MempoolFeeDecorator
in x/auth
module needs to be overwritten to check the baseFee
along with the minimal-gas-prices
allowing to implement a global fee mechanism which vary depending on the network activity.
For more reference to EIP-1559:
https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md
gasPrice
is the price per gas and gasLimit
describes the amount of gas required to perform the transaction. The more complex operations a transaction requires, the higher the gas limit (see Executing EVM bytecode). To submit a transaction, the signer needs to specify the gasPrice
.
With EIP-1559 enabled, the transaction fee is calculated with
baseFee
is the fixed-per-block network fee per gas and priorityTip
is an additional fee per gas that can be set optionally. Note, that both the base fee and the priority tip are gas prices. To submit a transaction with EIP-1559, the signer needs to specify the gasFeeCap
, which is the maximum fee per gas they are willing to pay in total. Optionally, the priorityTip
can be specified, which covers both the priority fee and the block’s network fee per gas (aka: base fee).
gas
than Ethereum. What is called gasLimit
on Ethereum is called gasWanted
on Cosmos. You might encounter both terminologies in the Cosmos EVM since it builds Ethereum on top of the SDK, e.g. when using different wallets like Keplr for Cosmos and Metamask for Ethereum.block gas limit / elasticity multiplier
):
feemarket
module allocates the base fee for regular Cosmos SDK fee distribution.
max_priority_fee_per_gas
, often referred to as tip
, is an additional gas price that can be added to the baseFee
in order to incentivize transaction prioritization. The higher the tip, the more likely the transaction is included in the block.
Until the Cosmos SDK version v0.46, however, there is no notion of transaction prioritization. Thus, the tip for an EIP-1559 transaction on a Cosmos EVM chain should be zero (MaxPriorityFeePerGas
JSON-RPC endpoint returns 0
).
baseFee + tip
or the gasFeeCap
feemarket
module, which can be changed through governance.effective gas price = base fee + priority tip
) or the local minimum gas price is lower than the global MinGasPrice
(min-gas-price (local) < MinGasPrice (global) OR EffectiveGasPrice < MinGasPrice
), then MinGasPrice
is used as a lower bound.MinGasPrice
, users need to resend the transactions with a gas price higher or equal to MinGasPrice
.minimum-gas-price
is higher than the global MinGasPrice
, then the larger value of the two is used as a lower bound. In the case of EIP-1559, users must increase the priority fee for their transactions to be valid.EthMempoolFeeDecorator
and EthMinGasPriceDecorator
AnteHandler
and for Cosmos transactions in NewMempoolFeeDecorator
and MinGasPriceDecorator
AnteHandler
.
MinGasPrice
, it is set to the MinGasPrice
. This is implemented, so that the base fee can’t drop to gas prices that wouldn’t allow transactions to be accepted in the mempool, because of a higher MinGasPrice
.Description | Key | Value | Store | |
---|---|---|---|---|
BlockGasUsed | gas used in the block | []byte{1} | []byte{gas_used} | KV |
EndBlock
to comply with EIP-1559 specifications. The logic described here now executes at the end of each block.
NoBaseFee
and EnableHeight
NoBaseFee
controls the feemarket base fee value. If set to true, no calculation is done and the base fee returned by the keeper is zero.
EnableHeight
controls the height we start the calculation.
NoBaseFee = false
and height < EnableHeight
, the base fee value will be equal to base_fee
defined in the genesis and the BeginBlock
will return without further computation.NoBaseFee = false
and height >= EnableHeight
, the base fee is dynamically calculated upon each block at BeginBlock
.EnableHeight
to the InitialBaseFee
value defined in the genesis file.
The base fee is after adjusted according to the total gas used in the previous block.
block_gas_used
value is updated at the end of each block.
EndBlock
.
It is initialized to block_gas
, defined in the genesis.
x/feemarket
module emits the following events:
Type | Attribute Key | Attribute Value |
---|---|---|
fee_market | base_fee | {baseGasPrices} |
Type | Attribute Key | Attribute Value |
---|---|---|
block_gas | height | {blockHeight} |
block_gas | amount | {blockGasUsed} |
x/feemarket
module contains the following parameters:
Key | Type | Default Values | Description |
---|---|---|---|
NoBaseFee | bool | false | control the base fee adjustment |
BaseFeeChangeDenominator | uint32 | 8 | bounds the amount the base fee that can change between blocks |
ElasticityMultiplier | uint32 | 2 | bounds the threshold which the base fee will increase or decrease depending on the total gas used in the previous block |
EnableHeight | uint32 | 0 | height which enable fee adjustment |
MinGasPrice | sdk.Dec | 0 | global minimum gas price that needs to be paid to include a transaction in a block |
feemarket
module using the CLI.
query
commands allow users to query feemarket
state.
base-fee
command allows users to query the block base fee by height.
block-gas
command allows users to query the block gas by height.
params
command allows users to query the module params.
Verb | Method | Description |
---|---|---|
gRPC | ethermint.feemarket.v1.Query/Params | Get the module params |
gRPC | ethermint.feemarket.v1.Query/BaseFee | Get the block base fee |
gRPC | ethermint.feemarket.v1.Query/BlockGas | Get the block gas used |
GET | /ethermint/feemarket/v1/params | Get the module params |
GET | /ethermint/feemarket/v1/base_fee | Get the block base fee |
GET | /ethermint/feemarket/v1/block_gas | Get the block gas used |
x/feemarket
module provides AnteDecorator
s that are recursively chained together into a single Antehandler
. These decorators perform basic validity checks on an Ethereum or Cosmos SDK transaction, such that it could be thrown out of the transaction Mempool.
Note that the AnteHandler
is run for every transaction and called on both CheckTx
and DeliverTx
.
MinGasPriceDecorator
MinGasPrice * GasLimit
.
EthMinGasPriceDecorator
MinGasPrice * GasLimit
.
LegacyTx
and AccessListTx
, the GasPrice * GasLimit
is used.DynamicFeeTx
), the EffectivePrice * GasLimit
is used.feemarket
formula results in a BaseFee
that lowers EffectivePrice < MinGasPrices
, the users must increase the GasTipCap
(priority fee) until EffectivePrice > MinGasPrices
. Transactions with MinGasPrices * GasLimit < transaction fee < EffectiveFee
are rejected by the feemarket
AnteHandle
.EthGasConsumeDecorator