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

Align gas cap calculation for transaction simulation to Geth approach #7703

Merged
merged 1 commit into from
Oct 1, 2024

Conversation

fab-10
Copy link
Contributor

@fab-10 fab-10 commented Oct 1, 2024

PR description

A recent PR (#6978) made the optional rpc-gas-cap config to always override the gas cap used for tx simulation, when specified, but while this could be good for eth_call, it does not work well with calls like eth_estimateGas when the gas cap could be based on what use provided or the sender balance, and it also diverging from what Geth does.

This PR align the gas cap calculation used during tx simulation, to what Geth does, with only a little difference, the algorithm is the following:

  • if the user specific the gas limit, then use it unless it is bigger than the rpc-gas-cap, in which case we return the latter
  • if there is not user specified gas limit, then use rpc-gas-cap if configured, otherwise use the block gas limit^.

^ in this case Geth use MaxUint64 / 2

Fixed Issue(s)

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:

  • 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 Align gas cap for transaction simulation to Geth approach Align gas cap calculation for transaction simulation to Geth approach Oct 1, 2024
@fab-10 fab-10 force-pushed the align-gas-cap-simulation-to-geth branch from 0278348 to 6a302c8 Compare October 1, 2024 14:43
@fab-10 fab-10 marked this pull request as ready for review October 1, 2024 14:43
final long simulationGasCap;

// when not set gas limit is -1
if (callParams.getGasLimit() >= 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it's big and focused enough to factor it into a discrete method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, done

@fab-10 fab-10 force-pushed the align-gas-cap-simulation-to-geth branch from 6a302c8 to 6235c1f Compare October 1, 2024 14:54
@@ -291,6 +283,38 @@ public Optional<TransactionSimulatorResult> processWithWorldUpdater(
return Optional.of(new TransactionSimulatorResult(transaction, result));
}

private long calculateSimulationGasCap(
final CallParameter callParams, final BlockHeader blockHeaderToProcess) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry to come back to you on this, but rather than passing whole CallParameter and BlockHeader, we can pass gas limits only, it would make it even more focused

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no worries, it makes sense again.

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
@fab-10 fab-10 force-pushed the align-gas-cap-simulation-to-geth branch from 6235c1f to 3e5ed76 Compare October 1, 2024 15:27
Copy link
Contributor

@ahamlat ahamlat left a comment

Choose a reason for hiding this comment

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

LGTM


// when not set gas limit is -1
if (callParams.getGasLimit() >= 0) {
if (rpcGasCap > 0 && callParams.getGasLimit() > rpcGasCap) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it is more clear to use rpcGasCap > 0 as the first test.
Basically, we start by asking if the user have a configured rpcGasCap, and depending on this user choice, we can check other options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand it could be subjective, I prefer that user provided gas limit drives the choice.

@fab-10 fab-10 merged commit 7af03b7 into hyperledger:main Oct 1, 2024
43 checks passed
@fab-10 fab-10 deleted the align-gas-cap-simulation-to-geth branch October 1, 2024 16:00
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.

3 participants