-
Notifications
You must be signed in to change notification settings - Fork 391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: dynamic gas price, keeper implementation #2838
Conversation
Codecov ReportAttention: Patch coverage is 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are some initial questions and comments per our conversation earlier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the PR looks alright 💯
The way we transfer params, and load latest gas values through keepers in different modules is not a pattern we should be using, but I realize that the alternatives require much, much chunkier changes to how modules communicate.
There needs to be some heavy rebasing done with master
, but I haven't seen anything blocking in the PR. We should be good
🛠 PR Checks SummaryAll Automated Checks passed. ✅ Manual Checks (for Reviewers):
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) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
<!-- 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](gnolang#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>
<!-- 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>
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:
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...
BREAKING CHANGE: xxx
message was included in the description