From 5c1e1e18791cd37bb60b9b246a7b5a109d37745a Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Mon, 18 Mar 2024 18:52:38 +1000 Subject: [PATCH] Suppress ComparisonOutOfRange error-prone warning in AbstractGasLimitSpecification (#6727) * Add suppression for ComparisonOutOfRange * test: Add unit test to cover max gas limit --------- Signed-off-by: Usman Saleem --- .../ethereum/mainnet/AbstractGasLimitSpecification.java | 7 +++++++ .../ethereum/mainnet/TargetingGasLimitCalculatorTest.java | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractGasLimitSpecification.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractGasLimitSpecification.java index b1a21e54b4b..91cf73c3df8 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractGasLimitSpecification.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractGasLimitSpecification.java @@ -40,6 +40,13 @@ public static long deltaBound(final long currentGasLimit) { return Long.divideUnsigned(currentGasLimit, GAS_LIMIT_BOUND_DIVISOR); } + /** + * Verify that the target gas limit is within the allowed bounds. + * + * @param targetGasLimit the target gas limit to validate + * @return true if within bounds + */ + @SuppressWarnings("ComparisonOutOfRange") public static boolean isValidTargetGasLimit(final long targetGasLimit) { return DEFAULT_MIN_GAS_LIMIT <= targetGasLimit && DEFAULT_MAX_GAS_LIMIT >= targetGasLimit; } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/TargetingGasLimitCalculatorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/TargetingGasLimitCalculatorTest.java index ef197143f2f..4932eef30d8 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/TargetingGasLimitCalculatorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/TargetingGasLimitCalculatorTest.java @@ -72,6 +72,12 @@ public void verifyMinGasLimit() { .isFalse(); } + @Test + public void verifyMaxGasLimit() { + assertThat(AbstractGasLimitSpecification.isValidTargetGasLimit(Long.MAX_VALUE - 1)).isTrue(); + assertThat(AbstractGasLimitSpecification.isValidTargetGasLimit(Long.MAX_VALUE)).isTrue(); + } + @Test public void verifyWithinGasLimitDelta() { final long targetGasLimit = 10_000_000L;