Skip to content

Make gas estimation strict by default#8629

Merged
fab-10 merged 7 commits intobesu-eth:mainfrom
fab-10:improve-estimate-gas2
May 23, 2025
Merged

Make gas estimation strict by default#8629
fab-10 merged 7 commits intobesu-eth:mainfrom
fab-10:improve-estimate-gas2

Conversation

@fab-10
Copy link
Copy Markdown
Contributor

@fab-10 fab-10 commented May 14, 2025

PR description

Second PR of the series that improves gas estimation.

Besu implementation of eth_gasEstimation accepts the non standard parameters strict, that by default is false.
This parameters tells Besu that when processing the tx to estimate the gas used, the sender is allowed to exceeds his balance, and this is achieved setting to 0 all the gas price related field in the tx and in the block header.
This approach is not the standard, and could cause wrong gas estimations for some txs, so this PR set the default value of the strict parameter to true.

It is still possible to force the previous behavior, explicitly passing the strict parameter in the request, set to false.

Since strict mode does not alter gas pricing parameters, there is the need to calculate the gas limit upper bound that the sender is able to afford according to his balance, and use that upper bound in case it is lower than the block gas limit, when starting the binary search, to avoid tx upfront cost exceed balance errors.

Always in strict mode, since the gas pricing parameters are absent, then we need to permit underpriced tx, to skip checks on baseFee and blobBaseFee.

Comparing this PR with current main branch, using https://github.com/Consensys/compate-estimate-gas-plugin, there are less under estimations:

BesuPR8629 3399
BesuNightly 3426

Fixed Issue(s)

fixes #8146

Thanks for sending a pull request! Have you done the following?

  • Checked out our contribution guidelines?
  • Considered documentation and added the doc-change-required label to this PR if updates are required.
  • Considered the changelog and included an update if required.
  • For database changes (e.g. KeyValueSegmentIdentifier) considered compatibility and performed forwards and backwards compatibility tests

Locally, you can run these tests to catch failures early:

  • spotless: ./gradlew spotlessApply
  • unit tests: ./gradlew build
  • acceptance tests: ./gradlew acceptanceTest
  • integration tests: ./gradlew integrationTest
  • reference tests: ./gradlew ethereum:referenceTests:referenceTests

@fab-10 fab-10 changed the title Improve estimate gas2 Make gas estimation strict by default May 14, 2025
@fab-10 fab-10 force-pushed the improve-estimate-gas2 branch 6 times, most recently from 3768971 to 1cb6e75 Compare May 19, 2025 15:29
@fab-10 fab-10 marked this pull request as ready for review May 20, 2025 12:58
@macfarla macfarla added the doc-change-required Indicates an issue or PR that requires doc to be updated label May 22, 2025
Copy link
Copy Markdown
Contributor

@macfarla macfarla left a comment

Choose a reason for hiding this comment

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

LGTM maybe an update to the docs required

fab-10 added 7 commits May 23, 2025 12:28
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
@fab-10 fab-10 force-pushed the improve-estimate-gas2 branch from 63d8f3a to 7c6c9b7 Compare May 23, 2025 10:28
@fab-10 fab-10 enabled auto-merge (squash) May 23, 2025 10:28
@fab-10 fab-10 merged commit 3e52bb3 into besu-eth:main May 23, 2025
48 checks passed
@fab-10 fab-10 deleted the improve-estimate-gas2 branch May 23, 2025 11:29
@bgravenorst bgravenorst removed the doc-change-required Indicates an issue or PR that requires doc to be updated label May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gas estimation RPC methods should take in account the sender balance

3 participants