forked from cerc-io/laconicd-deprecated
update fork
This commit is contained in:
@@ -4,32 +4,72 @@ order: 1
|
||||
|
||||
# Concepts
|
||||
|
||||
## Base fee
|
||||
## EIP-1559: Fee Market
|
||||
|
||||
The base fee is a global base fee defined at the consensus level. It is adjusted for each block based on the total gas used in the previous block and gas target (block gas limit divided by elasticity multiplier)
|
||||
[EIP-1559](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md) describes a pricing mechanism that was proposed on Ethereum to improve to calculation of transaction fees. It includes a fixed-per-block network fee that is burned and dynamically expands/contracts block sizes to deal with peaks of network congestion.
|
||||
|
||||
- it increases when blocks are above the gas target
|
||||
- it decreases when blocks are below the gas target
|
||||
Before EIP-1559 the transaction fee is calculated with
|
||||
|
||||
Unlike the Cosmos SDK local `minimal-gas-prices`, this value is stored as a module parameter which provides a reliable value for validators to agree upon.
|
||||
```
|
||||
fee = gasPrice * gasLimit
|
||||
```
|
||||
|
||||
## Tip
|
||||
, where `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 gasLimit (See [Executing EVM bytecode](https://docs.evmos.org/modules/evm/01_concepts.html#executing-evm-bytecode)). To submit a transaction, the signer needs to specify the `gasPrice`.
|
||||
|
||||
In EIP-1559, the `tip` is a value that can be added to the `baseFee` in order to incentive transaction prioritization.
|
||||
With EIP-1559 enabled, the transaction fee is calculated with
|
||||
|
||||
The transaction fee in Ethereum is calculated using the following the formula :
|
||||
```
|
||||
fee = (baseFee + priorityTip) * gasLimit
|
||||
```
|
||||
|
||||
`transaction fee = (baseFee + tip) * gas units (limit)`
|
||||
, where `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 a gas prices. To submit a transaction with EIP-1559, the signer needs to specify the `gasFeeCap` a maximum fee per gas they are willing to pay total and optionally the `priorityTip` , which covers both the priority fee and the block's network fee per gas (aka: base fee).
|
||||
|
||||
In Cosmos SDK there is no notion of prioritization, thus the tip for an EIP-1559 transaction in Ethermint should be zero (`MaxPriorityFeePerGas` JSON-RPC endpoint returns `0`)
|
||||
::: tip
|
||||
The Cosmos SDK uses a different terminology for `gas` than Ethereum. What is called `gasLimit` on Ethereum is called `gasWanted` on Cosmos. You might encounter both terminologies on Evmos since it builds Ethereum on top of the SDK, e.g. when using different wallets like Keplr for Cosmos and Metamask for Ethereum.
|
||||
:::
|
||||
|
||||
## Base Fee
|
||||
|
||||
The base fee per gas (aka base fee) is a global gas price defined at the consensus level. It is stored as a module parameter and is adjusted at the end of each block based on the total gas used in the previous block and gas target (`block gas limit / elasticity multiplier`):
|
||||
|
||||
## EIP-1559
|
||||
- it increases when blocks are above the gas target,
|
||||
- it decreases when blocks are below the gas target.
|
||||
|
||||
A transaction pricing mechanism introduced in Ethereum that includes fixed-per-block network fee that is burned and dynamically expands/contracts block sizes to deal with transient congestion.
|
||||
Instead of burning the base fee (as implemented on Ethereum), the `feemarket` module allocates the base fee for regular [Cosmos SDK fee distribution](https://docs.evmos.org/modules/distribution/).
|
||||
|
||||
Transactions specify a maximum fee per gas they are willing to pay total (aka: max fee), which covers both the priority fee and the block's network fee per gas (aka: base fee)
|
||||
## Priority Tip
|
||||
|
||||
Reference: [EIP1559](https://eips.ethereum.org/EIPS/eip-1559)
|
||||
In EIP-1559, the `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 incentive 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 Ethermint should be zero (`MaxPriorityFeePerGas` JSON-RPC endpoint returns `0`). Have a look at [ADR 067](https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-067-mempool-refactor.md) to read about future plans on transaction prioritization in the Cosmos SDK.
|
||||
|
||||
## Effective Gas price
|
||||
|
||||
For EIP-1559 transactions (dynamic fee transactions) the effective gas price descibes the maximum gas price that a transaction is willing to provide. It is derived from the transaction arguments and the base fee parameter. Depending on which one is smaller, the effective gas price is either the `baseFee + tip` or the `gasFeeCap`
|
||||
|
||||
```
|
||||
min(baseFee + gasTipCap, gasFeeCap)
|
||||
```
|
||||
|
||||
## Local vs. Global Minimum Gas Prices
|
||||
|
||||
Minimum gas prices are used to discard spam transactions in the network, by raising the cost of transactions to the point that it is not economically viable for the spammer. This is achieved by defining a minimum gas price for accepting txs in the mempool for both Cosmos and EVM transactions. A transaction is discarded from the mempool if it doesn't provide at least one of the two types of min gas prices:
|
||||
|
||||
Minimum gas prices are used to discard spam transactions in the network, by raising the cost of transactions to the point that it is not economically viable for the spammer. This is achieved by defining a minimum gas price for accepting txs in the mempool for both Cosmos and EVM transactions. A transaction is discarded from the mempool if it doesn't provide at least one of the two types of min gas prices:
|
||||
|
||||
1. the local min gas prices that validators can set on their node config and
|
||||
2. the global min gas price, which is set as a parameter in the `feemarket` module, which can be changed through governance.
|
||||
|
||||
The lower bound for a transaction gas price is determined by comparing of gas price bounds according to three cases:
|
||||
|
||||
1. If the effective gas price (`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.
|
||||
|
||||
2. If transactions are rejected due to having a gas price lower than `MinGasPrice`, users need to resend the transactions with a gas price higher or equal to `MinGasPrice`.
|
||||
|
||||
3. If the effective gas price or the local `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.
|
||||
|
||||
The comparison of transaction gas price and the lower bound is implemented through AnteHandler decorators. For EVM transactions, this is done in the `EthMempoolFeeDecorator` and `EthMinGasPriceDecorator` `AnteHandler` and for Cosmos transactions in `NewMempoolFeeDecorator` and `MinGasPriceDecorator` `AnteHandler`.
|
||||
|
||||
::: tip
|
||||
If the base fee decreases to a value below the global `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`.
|
||||
:::
|
||||
@@ -8,7 +8,6 @@ The x/feemarket module keeps in the state variable needed to the fee calculation
|
||||
|
||||
Only BlockGasUsed in previous block needs to be tracked in state for the next base fee calculation.
|
||||
|
||||
|
||||
| | Description | Key | Value | Store |
|
||||
| ----------- | ------------------------------ | ---------------| ------------------- | --------- |
|
||||
| BlockGasUsed | gas used in the block | `[]byte{1}` | `[]byte{gas_used}` | KV |
|
||||
|
||||
@@ -4,7 +4,7 @@ order: 3
|
||||
|
||||
# Begin block
|
||||
|
||||
The base fee is calculated at the beginning of each block.
|
||||
The base fee is calculated at the beginning of each block.
|
||||
|
||||
## Base Fee
|
||||
|
||||
@@ -15,6 +15,7 @@ We introduce two parameters : `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.
|
||||
|
||||
- If `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.
|
||||
- If `NoBaseFee = false` and `height >= EnableHeight`, the base fee is dynamically calculated upon each block at `BeginBlock`.
|
||||
|
||||
@@ -28,7 +29,6 @@ To enable EIP1559 with the EVM, the following parameters should be set :
|
||||
- EnableHeight should be set to a positive integer >= upgrade height. It defines at which height the chain starts the base fee adjustment
|
||||
- LondonBlock evm's param should be set to a positive integer >= upgrade height. It defines at which height the chain start to accept EIP1559 transactions
|
||||
|
||||
|
||||
### Calculation
|
||||
|
||||
The base fee is initialized at `EnableHeight` to the `InitialBaseFee` value defined in the genesis file.
|
||||
@@ -51,4 +51,4 @@ else:
|
||||
base_fee_delta = parent_base_fee * gas_used_delta / parent_gas_target / BASE_FEE_MAX_CHANGE_DENOMINATOR
|
||||
base_fee = parent_base_fee - base_fee_delta
|
||||
|
||||
```
|
||||
```
|
||||
|
||||
@@ -4,10 +4,10 @@ order: 4
|
||||
|
||||
# End block
|
||||
|
||||
The block_gas_used value is updated at the end of each block.
|
||||
The block_gas_used value is updated at the end of each block.
|
||||
|
||||
## Block Gas Used
|
||||
|
||||
The total gas used by current block is stored in the KVStore at `EndBlock`.
|
||||
|
||||
It is initialized to `block_gas` defined in the genesis.
|
||||
It is initialized to `block_gas` defined in the genesis.
|
||||
|
||||
@@ -12,4 +12,4 @@ type Keeper interface {
|
||||
GetBaseFee(ctx sdk.Context) *big.Int
|
||||
}
|
||||
|
||||
```
|
||||
```
|
||||
|
||||
@@ -11,4 +11,5 @@ The `x/feemarket` module contains the following parameters:
|
||||
| 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|
|
||||
| BaseFee | uint32 | 1000000000 | base fee for EIP-1559 blocks |
|
||||
| EnableHeight | uint32 | 0 | height which enable fee adjustment |
|
||||
| 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 |
|
||||
|
||||
@@ -77,7 +77,6 @@ subspace: feemarket
|
||||
value: "2"
|
||||
```
|
||||
|
||||
|
||||
## gRPC
|
||||
|
||||
### Queries
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<!--
|
||||
order: 5
|
||||
-->
|
||||
|
||||
# AnteHandlers
|
||||
|
||||
The `x/feemarket` module provides `AnteDecorator`s that are recursively chained together into a single [`Antehandler`](https://github.com/cosmos/cosmos-sdk/blob/v0.43.0-alpha1/docs/architecture/adr-010-modular-antehandler.md). 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`.
|
||||
|
||||
## Decorators
|
||||
|
||||
### `MinGasPriceDecorator`
|
||||
|
||||
Rejects Cosmos SDK transactions with transaction fees lower than `MinGasPrice * GasLimit`.
|
||||
|
||||
### `EthMinGasPriceDecorator`
|
||||
|
||||
Rejects EVM transactions with transactions fees lower than `MinGasPrice * GasLimit`.
|
||||
- For `LegacyTx` and `AccessListTx`, the `GasPrice * GasLimit` is used.
|
||||
- For EIP-1559 (*aka.* `DynamicFeeTx`), the `EffectivePrice * GasLimit` is used.
|
||||
|
||||
::: tip
|
||||
**Note**: For dynamic transactions, if the `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`
|
||||
|
||||
Calculates the effective fees to deduct and the tx priority according to EIP-1559 spec, then deducts the fees and sets the tx priority in the response.
|
||||
|
||||
```
|
||||
effectivePrice = min(baseFee + tipFeeCap, gasFeeCap)
|
||||
effectiveTipFee = effectivePrice - baseFee
|
||||
priority = effectiveTipFee / DefaultPriorityReduction
|
||||
```
|
||||
|
||||
When there are multiple messages in the transaction, choose the lowest priority in them.
|
||||
-1
@@ -4,4 +4,3 @@ order: 9 -->
|
||||
# Future Improvements
|
||||
|
||||
- The feemarket module has been designed mainly to support EIP-1559 on EVM-based chain on cosmos, supporting non-EVM chain could be done as a future improvements.
|
||||
|
||||
@@ -13,13 +13,11 @@ This document specifies the feemarket module which allows to define a global tra
|
||||
|
||||
This module has been designed to support EIP1559 in cosmos-sdk.
|
||||
|
||||
The `MempoolFeeDecorator` in `x/auth` module needs to be overrided to check the `baseFee` along with the `minimal-gas-prices` allowing to implement a global fee mechanism which vary depending on the network activity.
|
||||
The `MempoolFeeDecorator` in `x/auth` module needs to be overrided 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 EIP1559:
|
||||
|
||||
https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md
|
||||
|
||||
|
||||
<https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md>
|
||||
|
||||
## Contents
|
||||
|
||||
@@ -31,4 +29,4 @@ https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md
|
||||
6. **[Events](06_events.md)**
|
||||
7. **[Params](07_params.md)**
|
||||
8. **[Client](08_client.md)**
|
||||
9. **[Future Improvements](09_future_improvements.md)**
|
||||
9. **[Future Improvements](09_future_improvements.md)**
|
||||
|
||||
Reference in New Issue
Block a user