Fix to increment/decrement gas-limit in block production (#6425)

Signed-off-by: Matt Nelson <85905982+non-fungible-nelson@users.noreply.github.com>
Co-authored-by: Stefan Pingel <16143240+pinges@users.noreply.github.com>
Co-authored-by: Simon Dudley <simon.dudley@consensys.net>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
pull/6431/head
Matt Nelson 10 months ago committed by GitHub
parent 2d7941f8b8
commit f81d5445f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 4
      acceptance-tests/tests/src/test/resources/jsonrpc/engine/cancun/test-cases/block-production/12_cancun_get_built_block.json
  3. 1
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/AbstractGasLimitSpecification.java
  4. 10
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/FrontierTargetingGasLimitCalculator.java
  5. 10
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/LondonTargetingGasLimitCalculator.java
  6. 43
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/TargetingGasLimitCalculatorTest.java

@ -26,6 +26,7 @@
- Fix Besu Docker images with `openjdk-latest` tags since 23.10.3 using UID 1001 instead of 1000 for the `besu` user [#6360](https://github.com/hyperledger/besu/pull/6360)
- Fluent EVM API definition for Tangerine Whistle had incorrect code size validation configured [#6382](https://github.com/hyperledger/besu/pull/6382)
- Correct mining beneficiary for Clique networks in TraceServiceImpl [#6390](https://github.com/hyperledger/besu/pull/6390)
- Fix to gas limit delta calculations used in block production. Besu should now increment or decrement the block gas limit towards its target correctly (thanks @arbora) #6425
### Download Links

@ -10,7 +10,7 @@
"stateRoot" : "0x8d9115d9211932d4a3a1f068fb8fe262b0b2ab0bfd74eaece1a572efe6336677",
"logsBloom" : "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"prevRandao" : "0xc13da06dc53836ca0766057413b9683eb9a8773bbb8fcc5691e41c25b56dda1d",
"gasLimit" : "0x2ff3d8",
"gasLimit" : "0x2ffbd2",
"gasUsed" : "0xf618",
"timestamp" : "0x1236",
"extraData" : "0x",
@ -70,7 +70,7 @@
"amount" : "0x64"
} ],
"blockNumber" : "0x1",
"blockHash" : "0xf1e35607932349e87f29e1053a4fb2666782e09fde21ded74c1f7e4a57d3fa2b",
"blockHash" : "0x736bdddc2eca36fe8ed4ed515e5d295a08d7eaddc0d0fda2a35408127eb890d0",
"receiptsRoot" : "0x9af165447e5b3193e9ac8389418648ee6d6cb1d37459fe65cfc245fc358721bd",
"blobGasUsed" : "0x60000"
},

@ -19,7 +19,6 @@ import static com.google.common.base.Preconditions.checkArgument;
/** Specification for the block gasLimit. */
public abstract class AbstractGasLimitSpecification {
public static final long DEFAULT_MAX_CONSTANT_ADMUSTMENT_INCREMENT = 1024L;
public static final long DEFAULT_MIN_GAS_LIMIT = 5000L;
public static final long DEFAULT_MAX_GAS_LIMIT = Long.MAX_VALUE;

@ -23,16 +23,13 @@ public class FrontierTargetingGasLimitCalculator extends AbstractGasLimitSpecifi
implements GasLimitCalculator {
private static final Logger LOG =
LoggerFactory.getLogger(FrontierTargetingGasLimitCalculator.class);
private final long maxConstantAdjustmentIncrement;
public FrontierTargetingGasLimitCalculator() {
this(DEFAULT_MAX_CONSTANT_ADMUSTMENT_INCREMENT, DEFAULT_MIN_GAS_LIMIT, DEFAULT_MAX_GAS_LIMIT);
this(DEFAULT_MIN_GAS_LIMIT, DEFAULT_MAX_GAS_LIMIT);
}
public FrontierTargetingGasLimitCalculator(
final long maxConstantAdjustmentIncrement, final long minGasLimit, final long maxGasLimit) {
public FrontierTargetingGasLimitCalculator(final long minGasLimit, final long maxGasLimit) {
super(minGasLimit, maxGasLimit);
this.maxConstantAdjustmentIncrement = maxConstantAdjustmentIncrement;
}
@Override
@ -55,8 +52,7 @@ public class FrontierTargetingGasLimitCalculator extends AbstractGasLimitSpecifi
}
private long adjustAmount(final long currentGasLimit) {
final long maxProportionalAdjustmentLimit = Math.max(deltaBound(currentGasLimit) - 1, 0);
return Math.min(maxConstantAdjustmentIncrement, maxProportionalAdjustmentLimit);
return Math.max(deltaBound(currentGasLimit) - 1, 0);
}
protected long safeAddAtMost(final long gasLimit) {

@ -27,21 +27,15 @@ public class LondonTargetingGasLimitCalculator extends FrontierTargetingGasLimit
public LondonTargetingGasLimitCalculator(
final long londonForkBlock, final BaseFeeMarket feeMarket) {
this(
DEFAULT_MAX_CONSTANT_ADMUSTMENT_INCREMENT,
DEFAULT_MIN_GAS_LIMIT,
DEFAULT_MAX_GAS_LIMIT,
londonForkBlock,
feeMarket);
this(DEFAULT_MIN_GAS_LIMIT, DEFAULT_MAX_GAS_LIMIT, londonForkBlock, feeMarket);
}
public LondonTargetingGasLimitCalculator(
final long maxConstantAdjustmentIncrement,
final long minGasLimit,
final long maxGasLimit,
final long londonForkBlock,
final BaseFeeMarket feeMarket) {
super(maxConstantAdjustmentIncrement, minGasLimit, maxGasLimit);
super(minGasLimit, maxGasLimit);
this.londonForkBlock = londonForkBlock;
this.feeMarket = feeMarket;
}

@ -27,22 +27,6 @@ import org.junit.jupiter.api.Test;
public class TargetingGasLimitCalculatorTest {
private static final long ADJUSTMENT_FACTOR = 1024L;
@Test
public void verifyGasLimitIsIncreasedWithinLimits() {
FrontierTargetingGasLimitCalculator targetingGasLimitCalculator =
new FrontierTargetingGasLimitCalculator();
assertThat(targetingGasLimitCalculator.nextGasLimit(8_000_000L, 10_000_000L, 1L))
.isEqualTo(8_000_000L + ADJUSTMENT_FACTOR);
}
@Test
public void verifyGasLimitIsDecreasedWithinLimits() {
FrontierTargetingGasLimitCalculator targetingGasLimitCalculator =
new FrontierTargetingGasLimitCalculator();
assertThat(targetingGasLimitCalculator.nextGasLimit(12_000_000L, 10_000_000L, 1L))
.isEqualTo(12_000_000L - ADJUSTMENT_FACTOR);
}
@Test
public void verifyGasLimitReachesTarget() {
final long target = 10_000_000L;
@ -55,6 +39,33 @@ public class TargetingGasLimitCalculatorTest {
.isEqualTo(target);
}
@Test
public void verifyAdjustmentDeltas() {
assertDeltas(20000000L, 20019530L, 19980470L);
assertDeltas(40000000L, 40039061L, 39960939L);
}
private void assertDeltas(
final long gasLimit, final long expectedIncrease, final long expectedDecrease) {
FrontierTargetingGasLimitCalculator targetingGasLimitCalculator =
new FrontierTargetingGasLimitCalculator();
// increase
assertThat(targetingGasLimitCalculator.nextGasLimit(gasLimit, gasLimit * 2, 1L))
.isEqualTo(expectedIncrease);
// decrease
assertThat(targetingGasLimitCalculator.nextGasLimit(gasLimit, 0, 1L))
.isEqualTo(expectedDecrease);
// small decrease
assertThat(targetingGasLimitCalculator.nextGasLimit(gasLimit, gasLimit - 1, 1L))
.isEqualTo(gasLimit - 1);
// small increase
assertThat(targetingGasLimitCalculator.nextGasLimit(gasLimit, gasLimit + 1, 1L))
.isEqualTo(gasLimit + 1);
// no change
assertThat(targetingGasLimitCalculator.nextGasLimit(gasLimit, gasLimit, 1L))
.isEqualTo(gasLimit);
}
@Test
public void verifyMinGasLimit() {
assertThat(AbstractGasLimitSpecification.isValidTargetGasLimit(DEFAULT_MIN_GAS_LIMIT - 1))

Loading…
Cancel
Save