-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dynamic gas price, keeper implementation (#2838)
<!-- please provide a detailed description of the changes made in this pull request. --> # 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](#2544) 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. ![image](https://github.com/user-attachments/assets/6f7bbf56-5196-4ee2-9c77-c55331cbfde6) 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. ![image](https://github.com/user-attachments/assets/c9123370-0f83-4ef9-a4e6-a09c6aad98c9) 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. ![image](https://github.com/user-attachments/assets/51d233be-318b-4f05-8a45-3157604657ea) # Formular ![image](https://github.com/user-attachments/assets/ba282aba-a145-46d3-80b8-dcc5787d2a0b) 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 ![image](https://github.com/user-attachments/assets/bb31dcbe-aaab-4c1a-b96f-156dafef80fc) ## 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. ![image](https://github.com/user-attachments/assets/c200cd1a-d4f3-4b4d-9198-2af08ad657ab) ## 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. <details><summary>Contributors' checklist...</summary> - [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: xxx` message 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](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details>
- Loading branch information
Showing
33 changed files
with
1,465 additions
and
150 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 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
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.