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

Use different transaction simulators for different behavior of rpc gas cap #7691

Closed
wants to merge 2 commits into from

Conversation

fab-10
Copy link
Contributor

@fab-10 fab-10 commented Sep 30, 2024

…tx gas limit

PR description

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 marked this pull request as ready for review September 30, 2024 13:38
@fab-10 fab-10 changed the title Fix: rpc gas price option should not incoditionally override smaller … Fix: rpc-gas-cap option should not incoditionally override smaller … Sep 30, 2024
@fab-10 fab-10 changed the title Fix: rpc-gas-cap option should not incoditionally override smaller … Fix: rpc-gas-cap option should not incoditionally override smaller tx gas limit Sep 30, 2024
@fab-10 fab-10 changed the title Fix: rpc-gas-cap option should not incoditionally override smaller tx gas limit Fix: rpc-gas-cap option should not inconditionally override smaller tx gas limit Sep 30, 2024
…x gas limit

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
if (rpcGasCap > 0) {
gasLimit = rpcGasCap;
simulationGasLimit = Math.min(txGasLimit, rpcGasCap);
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a real need to make RPC gas limit above block size limit, especially on eth_call. I wonder if we cannot make eth_estimateGas using a different variante of the transaction simulator

Copy link
Contributor Author

Choose a reason for hiding this comment

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

using different transaction simulators is doable, let me try to implement that way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ahamlat I have implemented your suggestion and now eth_call behaves differently of other call in regards of how rpc-gas-cap is applied

@fab-10 fab-10 changed the title Fix: rpc-gas-cap option should not inconditionally override smaller tx gas limit Use different transaction simulators for different behavior of rpc gas cap Sep 30, 2024
…s cap

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
rpcGasCap);
return simulationGasLimit;
}
return txGasLimit;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm trying to understand the logic here. If rpcGasCap == 0 we return txGasLimit and do not consider txGasCap? If so, can we move the final long txGasCap = txGasLimit >= 0 ? txGasLimit : blockGasLimit to be inside the if?

Also, could you please add a summary to the PR description.


public TransactionSimulator build() {
final SimulationGasLimitCalculator simulationGasLimitCalculator;
if (rpcGasCap > 0 && rpcGasCapMode.equals(RpcGasCapMode.UNBOUNDED)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

a long + enum encodes same amount of information as Long or Optional null or Optional.empty() may mean no bound. Introduction of RpcGasCapMode is verbose, but maybe it makes it more obvious

Copy link
Contributor

Choose a reason for hiding this comment

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

However possibility to set it to (0, BOUNDED) makes it errorprone. Optional or a nullable Long is less errorprone from this perspective

blockchainQueries.getBlockchain(),
blockchainQueries.getWorldStateArchive(),
protocolSchedule)
.rpcGasCap(apiConfiguration.getGasCap(), BOUNDED)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we want to use BOUNDED for eth_estimateGas? Isn't linea_estimateGas supposed to behave the same as eth_estimateGas?

public interface SimulationGasLimitCalculator {
long calculate(final long txGasLimit, final long blockGasLimit);

static long bounded(final long txGasLimit, final long blockGasLimit, final long 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 think if we replace 0 values with Long.MAX_VALUE the logic would be as simple as taking a min over 3 values. Would it be simpler to read?

@fab-10
Copy link
Contributor Author

fab-10 commented Oct 1, 2024

Thanks all for reviewing, but after studying a bit more and looking at what Geth does, I am closing this and changing approach in this new PR #7703

@fab-10 fab-10 closed this Oct 1, 2024
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.

4 participants