feat: dynamic gas price, keeper implementation
Context
This PR is inspired by EIP-1559 and adjusts the gas price based on the ratio of gas used in the last block compared to the target block gas. The gas price is enforced globally across the network. However, validators can still configure a minimum gas price (min-gas-price) to reject low-fee transactions and prevent mempool spam. A higher gas price will take precedence when configured.
Current implementation is an alternative to PR2544 and is based on the feedbacks.
Here are the main differences:
- Dynamic gas prices are managed by a new auth.GasPriceKeeper, rather than being saved in the block header.
- Gas price configurations have been moved from consensus parameters to GnoGenesisState and are stored in a new parameter module.
- The parameters can be modified later through governance proposals, making it easier to update these configurations without requiring a chain upgrade.
- All implementations are on the application side, with no changes made to the consensus layer.
High level flow
Start a new node from genesis. The initial gas price and formula parameters are saved in the genesis and loaded into the params keeper and gas keeper.
When a node receives a new transaction, the application checks if the user has provided sufficient fees for the transaction. It will reject the transaction if it does not meet the gas price set by the network and individual nodes.
The node processes the entire block during the proposal, voting, and restart phases. The GasPriceKeeper will calculate and update the gas price according to the formula in the applicationβs EndBlock() function.
Formular
The compressor is used to reduce the impact on price caused by sudden changes in the gas used within a block
When the last gas used in a block is above the target gas, we increase the gas price
When the last gas used in a block is below the target gas, we decrease the gas price until it returns to the initial gas price in the block.
Impact
The Cosmos SDK has an optional setting for a minimum gas price. Each validator can configure their own values to only accept transactions with a gas price that meets their setting in the mempool. When a user submits a transaction on-chain, the gas price is calculated as gas-fee / gas-wanted.
With the addition of the block gas price, a network-wide minimum gas price is enforced for every validator. Users will need to provide a gas price that meets the requirements set by both the validator and the network.
Contributors' checklist...
- [X] Added new tests
- [X] Provided an example (e.g. screenshot) to aid review
- [ ] Updated the official documentation or not needed
- [ ] No breaking changes were made, or a
BREAKING CHANGE: xxxmessage was included in the description - [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to generated graphs, if any. More info here.
Codecov Report
Attention: Patch coverage is 62.89855% with 128 lines in your changes missing coverage. Please review.
:loudspeaker: Thoughts on this report? Let us know!
π PR Checks Summary
All Automated Checks passed. β
Manual Checks (for Reviewers):
- [ ] SKIP: Do not block the CI for this PR
Read More
π€ This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.
β Automated Checks (for Contributors):
π’ Maintainers must be able to edit this pull request (more info) π’ The pull request head branch must be up-to-date with its base (more info)
βοΈ Contributor Actions:
- Fix any issues flagged by automated checks.
- Follow the Contributor Checklist to ensure your PR is ready for review.
- Add new tests, or document why they are unnecessary.
- Provide clear examples/screenshots, if necessary.
- Update documentation, if required.
- Ensure no breaking changes, or include
BREAKING CHANGEnotes. - Link related issues/PRs, where applicable.
βοΈ Reviewer Actions:
- Complete manual checks for the PR, including the guidelines and additional checks if applicable.
π Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)
If
π’ Condition met βββ π’ The pull request was created from a fork (head branch repo: piux2/gno)Then
π’ Requirement satisfied βββ π’ Maintainer can modify this pull requestThe pull request head branch must be up-to-date with its base (more info)
If
π’ Condition met βββ π’ On every pull requestThen
π’ Requirement satisfied βββ π’ Head branch (piux2:feat_gasprice_keeper) is up to date with base (master): behind by 0 / ahead by 20Manual Checks
**SKIP**: Do not block the CI for this PR
If
π’ Condition met βββ π’ On every pull requestCan be checked by
- Any user with comment edit permission