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

Merged
merged 20 commits into from
Dec 17, 2024

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
Contributor

@deelawn deelawn left a 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.

tm2/pkg/std/gasprice.go Outdated Show resolved Hide resolved
gno.land/pkg/gnoland/app.go Outdated Show resolved Hide resolved
gno.land/pkg/gnoland/app.go Show resolved Hide resolved
gno.land/pkg/gnoland/genesis.go Outdated Show resolved Hide resolved
@zivkovicmilos zivkovicmilos added this to the 🚀 Mainnet launch milestone Oct 28, 2024
@Kouteki Kouteki removed request for a team and leohhhn November 1, 2024 16:39
This was referenced Nov 18, 2024
Copy link
Member

@zivkovicmilos zivkovicmilos left a 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

contribs/gnodev/go.mod Outdated Show resolved Hide resolved
tm2/pkg/telemetry/metrics/metrics.go Show resolved Hide resolved
tm2/pkg/std/gasprice.go Outdated Show resolved Hide resolved
tm2/pkg/std/gasprice.go Outdated Show resolved Hide resolved
tm2/pkg/std/gasprice.go Show resolved Hide resolved
tm2/pkg/sdk/auth/keeper.go Outdated Show resolved Hide resolved
tm2/pkg/sdk/auth/keeper.go Show resolved Hide resolved
tm2/pkg/sdk/auth/keeper.go Show resolved Hide resolved
tm2/pkg/sdk/auth/keeper.go Outdated Show resolved Hide resolved
gno.land/pkg/gnoland/types.go Show resolved Hide resolved
@Gno2D2
Copy link
Collaborator

Gno2D2 commented Dec 5, 2024

🛠 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

@piux2 piux2 merged commit 273fb27 into gnolang:master Dec 17, 2024
107 checks passed
omarsy pushed a commit to omarsy/gno that referenced this pull request Dec 18, 2024
<!-- 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>
albttx pushed a commit that referenced this pull request Jan 10, 2025
<!-- 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>
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: Done
Development

Successfully merging this pull request may close these issues.

5 participants