gno icon indicating copy to clipboard operation
gno copied to clipboard

feat: dynamic gas price, keeper implementation

Open piux2 opened this issue 1 year ago β€’ 1 comments

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.

image

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

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

Formular

image

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

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

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: 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, if any. More info here.

piux2 avatar Sep 24 '24 09:09 piux2

πŸ›  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:
  1. Fix any issues flagged by automated checks.
  2. 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 CHANGE notes.
    • Link related issues/PRs, where applicable.
β˜‘οΈ Reviewer Actions:
  1. 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 request

The pull request head branch must be up-to-date with its base (more info)

If

🟒 Condition met
└── 🟒 On every pull request

Then

🟒 Requirement satisfied
└── 🟒 Head branch (piux2:feat_gasprice_keeper) is up to date with base (master): behind by 0 / ahead by 20

Manual Checks
**SKIP**: Do not block the CI for this PR

If

🟒 Condition met
└── 🟒 On every pull request

Can be checked by

  • Any user with comment edit permission

Gno2D2 avatar Dec 05 '24 03:12 Gno2D2