Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

piux2
Copy link
Contributor

@piux2 piux2 commented Sep 24, 2024

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...
  • Added new tests
  • 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.

@github-actions github-actions bot added 📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ gno.land Issues or PRs gno.land package related labels Sep 24, 2024
Copy link

codecov bot commented Sep 24, 2024

Codecov Report

Attention: Patch coverage is 33.66337% with 134 lines in your changes missing coverage. Please review.

Project coverage is 60.79%. Comparing base (9897b66) to head (e7cf296).

Files with missing lines Patch % Lines
tm2/pkg/sdk/auth/keeper.go 21.33% 55 Missing and 4 partials ⚠️
tm2/pkg/sdk/auth/params.go 37.20% 18 Missing and 9 partials ⚠️
tm2/pkg/std/gasprice.go 0.00% 12 Missing ⚠️
tm2/pkg/sdk/params/keeper.go 60.00% 6 Missing and 4 partials ⚠️
tm2/pkg/sdk/auth/genesis.go 0.00% 6 Missing ⚠️
tm2/pkg/sdk/auth/types.go 0.00% 6 Missing ⚠️
tm2/pkg/telemetry/metrics/metrics.go 0.00% 6 Missing ⚠️
tm2/pkg/sdk/auth/abci.go 0.00% 4 Missing ⚠️
tm2/pkg/sdk/baseapp.go 20.00% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2838      +/-   ##
==========================================
- Coverage   60.87%   60.79%   -0.08%     
==========================================
  Files         563      567       +4     
  Lines       75193    75354     +161     
==========================================
+ Hits        45770    45813      +43     
- Misses      26055    26156     +101     
- Partials     3368     3385      +17     
Flag Coverage Δ
contribs/gnofaucet 14.46% <ø> (-0.86%) ⬇️
gnovm 65.63% <ø> (ø)
misc/genstd 80.54% <ø> (ø)
misc/logos 19.88% <ø> (-0.36%) ⬇️
tm2 61.92% <33.66%> (-0.17%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ gno.land Issues or PRs gno.land package related
Projects
Status: No status
Status: Triage
Development

Successfully merging this pull request may close these issues.

1 participant