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: congestion-aware gas price oracle #790

Merged
merged 5 commits into from
Jun 4, 2024
Merged

Conversation

jonastheis
Copy link

1. Purpose or design rationale of this PR

When there are few transactions, the gas price oracle (GPO) can be skewed by a handful of high-price transactions easily, after which most clients would start using the higher gas price reported by GPO, even though their transaction would be processed with a lower gas price. Thus starting a upward price cycle.

This PR addresses this issue by taking into account current "congestion" levels as perceived by the txpool (run geth with -gpo.congestionthreshold) and returns a configurable minimum price (pre EIP 1559, takes -txpool.pricelimit) and a minimum tip of 1 Wei post EIP 1559.

2. PR title

Your PR title must follow conventional commits (as we are doing squash merge for each PR), so it must start with one of the following types:

  • build: Changes that affect the build system or external dependencies (example scopes: yarn, eslint, typescript)
  • ci: Changes to our CI configuration files and scripts (example scopes: vercel, github, cypress)
  • docs: Documentation-only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that doesn't fix a bug, or add a feature, or improves performance
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • test: Adding missing tests or correcting existing tests

3. Deployment tag versioning

Has the version in params/version.go been updated?

  • This PR doesn't involve a new deployment, git tag, docker image tag, and it doesn't affect traces
  • Yes

4. Breaking change label

Does this PR have the breaking-change label?

  • This PR is not a breaking change
  • Yes

@jonastheis jonastheis changed the title feat: Congestion-aware gas price oracle feat: congestion-aware gas price oracle May 31, 2024
omerfirmak
omerfirmak previously approved these changes Jun 3, 2024
colinlyguo
colinlyguo previously approved these changes Jun 3, 2024
Copy link
Member

@colinlyguo colinlyguo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

eth/gasprice/gasprice_test.go Outdated Show resolved Hide resolved
eth/gasprice/gasprice.go Show resolved Hide resolved
eth/gasprice/gasprice.go Show resolved Hide resolved
georgehao
georgehao previously approved these changes Jun 3, 2024
@jonastheis jonastheis dismissed stale reviews from georgehao, colinlyguo, and omerfirmak via 5dcd0e2 June 4, 2024 01:49
colinlyguo
colinlyguo previously approved these changes Jun 4, 2024
omerfirmak
omerfirmak previously approved these changes Jun 4, 2024
@github-actions github-actions bot dismissed stale reviews from colinlyguo and omerfirmak via 965232c June 4, 2024 09:01
@jonastheis jonastheis merged commit b9d3c72 into develop Jun 4, 2024
@jonastheis jonastheis deleted the jt/gpo-congestion branch June 4, 2024 09:05
@colinlyguo
Copy link
Member

colinlyguo commented Jun 11, 2024

fyi, tested with --gpo.congestionthreshold 1000 before and after Curie transition, the GPO works as expected:

before Curie (0.15 gwei, which is equal to --txpool.pricelimit "$L2GETH_MIN_GAS_PRICE", L2GETH_MIN_GAS_PRICE="150000000" # 0.15 gwei):

eth_maxPriorityFeePerGas: 0.15 gwei.
eth_gasPrice: 0.15 gwei.

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_maxPriorityFeePerGas","id":1}' -H "Content-Type: application/json" http://10.6.11.134:8545 | jq
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x8f0d180"
}

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_gasPrice","id":1}' -H "Content-Type: application/json" http://10.6.11.134:8545 | jq
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x8f0d180"
}

After Curie (when tx pool is not congested):

eth_maxPriorityFeePerGas: 1 wei.
eth_gasPrice: 0.15 gwei + 1 wei.

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_maxPriorityFeePerGas","id":1}' -H "Content-Type: application/json" http://10.6.11.134:8545 | jq
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x1"
}

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_gasPrice","id":1}' -H "Content-Type: application/json" http://10.6.11.134:8545 | jq
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x8f0d181"
}

HAOYUatHZ pushed a commit that referenced this pull request Aug 1, 2024
* Implement functionality to reset gas price / suggested tip to minimal value when there's no congestion

* Add flags to configure congestion value and initialize gas price oracle accordingly

* Fix and add tests to make sure GPO works as expected depending on pre- or post-Curie (EIP 1559) upgrade

* Apply review suggestions

* chore: auto version bump [bot]

---------

Co-authored-by: omerfirmak <omerfirmak@users.noreply.github.com>
HAOYUatHZ added a commit that referenced this pull request Aug 1, 2024
* feat: congestion-aware gas price oracle (#790)

* Implement functionality to reset gas price / suggested tip to minimal value when there's no congestion

* Add flags to configure congestion value and initialize gas price oracle accordingly

* Fix and add tests to make sure GPO works as expected depending on pre- or post-Curie (EIP 1559) upgrade

* Apply review suggestions

* chore: auto version bump [bot]

---------

Co-authored-by: omerfirmak <omerfirmak@users.noreply.github.com>

* fix eth/gasprice/gasprice_test.go

* minor

* fix(GPO): min suggested tip cap if there's congestion to avoid filtering through `DefaultIgnorePrice` (#883)

* fix tests

* fix tests

---------

Co-authored-by: Jonas Theis <4181434+jonastheis@users.noreply.github.com>
Co-authored-by: omerfirmak <omerfirmak@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants