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

Suppress ComparisonOutOfRange errorprone warning in AbstractGasLimitSpecification #6727

Merged
merged 7 commits into from
Mar 18, 2024

Conversation

usmansaleem
Copy link
Member

@usmansaleem usmansaleem commented Mar 13, 2024

PR description

Suppress ComparisonOutOfRange error-prone warning in AbstractGasLimitSpecification. This was reported during errorprone plugin update. Add a unit test to cover the max limit as well.

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

Most advanced CI tests are deferred until PR approval, but you could:

  • locally run all unit tests via: ./gradlew build
  • locally run all acceptance tests via: ./gradlew acceptanceTest
  • locally run all integration tests via: ./gradlew integrationTest
  • locally run all reference tests via: ./gradlew ethereum:referenceTests:referenceTests

Simplify isValidTargetGasLimit bound condition

Signed-off-by: Usman Saleem <usman@usmans.info>
@usmansaleem usmansaleem requested a review from garyschulte March 13, 2024 23:49
public static boolean isValidTargetGasLimit(final long targetGasLimit) {
return DEFAULT_MIN_GAS_LIMIT <= targetGasLimit && DEFAULT_MAX_GAS_LIMIT >= targetGasLimit;
// only check the lower bound as the upper bound is Long.MAX_VALUE
return targetGasLimit >= DEFAULT_MIN_GAS_LIMIT;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you point to which tests this is covered by please?

Copy link
Member Author

Choose a reason for hiding this comment

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

ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/TargetingGasLimitCalculatorTest.java

Copy link
Contributor

@siladu siladu Mar 14, 2024

Choose a reason for hiding this comment

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

Thanks. I find this errorprone check odd - wouldn't this code break if we ever changed the DEFAULT_MAX to be something other than Long.MAX_VALUE?

I don't think the test coverage is good enough to pick up on that either.

Better to suppress the warning in this case IMO.

Copy link
Contributor

Choose a reason for hiding this comment

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

agree it seems safer to suppress this warning

Copy link
Member Author

Choose a reason for hiding this comment

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

To counter-argue, if we jump from long to BigInteger for example, then the targetGasLimit would also change from long to BigInteger. What is the value DEFAULT_GAS_MAX_LIMIT as per the spec? Here it seems to be bounded by the variable type we are using i.e. Long.MAX_VALUE.

I'll close this PR and will add the suppression when we bring in the updated errorprone library dependency.

Copy link
Contributor

@siladu siladu Mar 18, 2024

Choose a reason for hiding this comment

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

Can't find a max value in the spec, was looking here: https://ethereum.github.io/execution-specs/src/ethereum/shanghai/fork.py.html#ethereum.shanghai.fork.check_gas_limit:0

It's UInt so unspecified arbitrary size https://ethereum.github.io/execution-specs/src/ethereum/base_types.py.html

if we ever changed the DEFAULT_MAX to be something other than Long.MAX_VALUE

I was more thinking if a future spec introduced a specific max value to enforce something in the protocol.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. I'll add a unit test instead to cover the max value.

Signed-off-by: Usman Saleem <usman@usmans.info>
Signed-off-by: Usman Saleem <usman@usmans.info>
Signed-off-by: Usman Saleem <usman@usmans.info>
Signed-off-by: Usman Saleem <usman@usmans.info>
Signed-off-by: Usman Saleem <usman@usmans.info>
@usmansaleem usmansaleem changed the title Refactor AbstractGasLimitSpecification to simplify isValidTargetGasLimit bound condition Suppress ComparisonOutOfRange errorprone warning in AbstractGasLimitSpecification Mar 18, 2024
@usmansaleem usmansaleem requested review from siladu and macfarla March 18, 2024 01:06
Signed-off-by: Usman Saleem <usman@usmans.info>
Copy link
Contributor

@siladu siladu left a comment

Choose a reason for hiding this comment

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

👍

@usmansaleem usmansaleem merged commit 5c1e1e1 into hyperledger:main Mar 18, 2024
42 checks passed
@usmansaleem usmansaleem deleted the cq_gaslimitspec branch March 18, 2024 08:52
amsmota pushed a commit to Citi/besu that referenced this pull request Apr 16, 2024
…Specification (hyperledger#6727)

* Add suppression for ComparisonOutOfRange
* test: Add unit test to cover max gas limit

---------

Signed-off-by: Usman Saleem <usman@usmans.info>
Signed-off-by: amsmota <antonio.mota@citi.com>
amsmota pushed a commit to Citi/besu that referenced this pull request Apr 16, 2024
…Specification (hyperledger#6727)

* Add suppression for ComparisonOutOfRange
* test: Add unit test to cover max gas limit

---------

Signed-off-by: Usman Saleem <usman@usmans.info>
Signed-off-by: amsmota <antonio.mota@citi.com>
matthew1001 pushed a commit to kaleido-io/besu that referenced this pull request Jun 7, 2024
…Specification (hyperledger#6727)

* Add suppression for ComparisonOutOfRange
* test: Add unit test to cover max gas limit

---------

Signed-off-by: Usman Saleem <usman@usmans.info>
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