Skip to content

Commit 6126848

Browse files
committed
addressed pr comments
Signed-off-by: daniellehrner <daniel.lehrner@consensys.net>
1 parent eb257ed commit 6126848

File tree

6 files changed

+66
-68
lines changed

6 files changed

+66
-68
lines changed

config/src/main/java/org/hyperledger/besu/config/BlobSchedule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class BlobSchedule {
2626
/** The constant PRAGUE_DEFAULT. */
2727
public static final BlobSchedule PRAGUE_DEFAULT = BlobSchedule.create(6, 9, 5007716);
2828

29-
/** The constant BPO2_DEFAULT. BPO2 through BPO5 and Amsterdam share these values. */
29+
/** The constant BPO2_DEFAULT. */
3030
public static final BlobSchedule BPO2_DEFAULT = BlobSchedule.create(14, 21, 11684671);
3131

3232
private final int target;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright contributors to Besu.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*
13+
* SPDX-License-Identifier: Apache-2.0
14+
*/
15+
package org.hyperledger.besu.ethereum.mainnet;
16+
17+
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
18+
import org.hyperledger.besu.evm.gascalculator.GasCalculator;
19+
20+
import java.util.OptionalInt;
21+
22+
/** EIP-8037: Amsterdam disables the validation-time transaction gas limit cap. */
23+
public class AmsterdamTargetingGasLimitCalculator extends OsakaTargetingGasLimitCalculator {
24+
25+
public AmsterdamTargetingGasLimitCalculator(
26+
final long londonForkBlock,
27+
final BaseFeeMarket feeMarket,
28+
final GasCalculator gasCalculator,
29+
final int maxBlobsPerBlock,
30+
final int targetBlobsPerBlock,
31+
final OptionalInt maxBlobsPerTransaction,
32+
final OptionalInt userMaxBlobsPerBlock) {
33+
super(
34+
londonForkBlock,
35+
feeMarket,
36+
gasCalculator,
37+
maxBlobsPerBlock,
38+
targetBlobsPerBlock,
39+
maxBlobsPerTransaction,
40+
userMaxBlobsPerBlock,
41+
Long.MAX_VALUE);
42+
}
43+
}

ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,15 +1256,14 @@ static ProtocolSpecBuilder amsterdamDefinition(
12561256
.gasLimitCalculatorBuilder(
12571257
(feeMarket, gasCalculator, blobSchedule) -> {
12581258
final long londonForkBlock = genesisConfigOptions.getLondonBlockNumber().orElse(0L);
1259-
return new OsakaTargetingGasLimitCalculator(
1259+
return new AmsterdamTargetingGasLimitCalculator(
12601260
londonForkBlock,
12611261
(BaseFeeMarket) feeMarket,
12621262
gasCalculator,
12631263
blobSchedule.getMax(),
12641264
blobSchedule.getTarget(),
12651265
miningConfiguration.getMaxBlobsPerTransaction(),
1266-
miningConfiguration.getMaxBlobsPerBlock(),
1267-
Long.MAX_VALUE);
1266+
miningConfiguration.getMaxBlobsPerBlock());
12681267
})
12691268
// EIP-8037: Amsterdam gas calculator with state gas cost support
12701269
.gasCalculator(AmsterdamGasCalculator::new)

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.Optional;
2626
import java.util.OptionalInt;
2727

28-
import org.assertj.core.api.Assertions;
2928
import org.junit.jupiter.api.Test;
3029
import org.junit.jupiter.api.TestInstance;
3130
import org.junit.jupiter.params.ParameterizedTest;
@@ -40,8 +39,8 @@ class AmsterdamTargetingGasLimitCalculatorTest {
4039
private static final int TARGET_BLOBS = 14;
4140
private static final int MAX_BLOBS = 21;
4241
private static final AmsterdamGasCalculator gasCalculator = new AmsterdamGasCalculator();
43-
private final OsakaTargetingGasLimitCalculator gasLimitCalculator =
44-
new OsakaTargetingGasLimitCalculator(
42+
private final AmsterdamTargetingGasLimitCalculator gasLimitCalculator =
43+
new AmsterdamTargetingGasLimitCalculator(
4544
0L,
4645
FeeMarket.cancun(0L, Optional.empty(), BlobSchedule.BPO2_DEFAULT),
4746
gasCalculator,
@@ -62,7 +61,7 @@ class AmsterdamTargetingGasLimitCalculatorTest {
6261
* where parent_excess_blobs=18 (=(21+14)//2+1), parent_blobs=0, block_base_fee_per_gas=7
6362
*/
6463
@ParameterizedTest(name = "{index} - parent excess {0}, used gas {1}, base fee {2}")
65-
@MethodSource("standardBranchBlobGasses")
64+
@MethodSource("standardBranchBlobGases")
6665
public void shouldCalculateExcessBlobGasCorrectly_standardBranch(
6766
final long parentExcess,
6867
final long parentBlobGasUsed,
@@ -72,7 +71,7 @@ public void shouldCalculateExcessBlobGasCorrectly_standardBranch(
7271
.isEqualTo(expected);
7372
}
7473

75-
Iterable<Arguments> standardBranchBlobGasses() {
74+
Iterable<Arguments> standardBranchBlobGases() {
7675
return List.of(
7776
// zero + zero: below target → 0
7877
Arguments.of(0L, 0L, 7L, 0L),
@@ -103,7 +102,7 @@ Iterable<Arguments> standardBranchBlobGasses() {
103102
* 14 = 7, so: excess = parentExcess + parentBlobGasUsed * 7 / 21
104103
*/
105104
@ParameterizedTest(name = "{index} - parent excess {0}, used gas {1}, base fee {2}")
106-
@MethodSource("eip7918BranchBlobGasses")
105+
@MethodSource("eip7918BranchBlobGases")
107106
public void shouldCalculateExcessBlobGasCorrectly_eip7918Branch(
108107
final long parentExcess,
109108
final long parentBlobGasUsed,
@@ -113,7 +112,7 @@ public void shouldCalculateExcessBlobGasCorrectly_eip7918Branch(
113112
.isEqualTo(expected);
114113
}
115114

116-
Iterable<Arguments> eip7918BranchBlobGasses() {
115+
Iterable<Arguments> eip7918BranchBlobGases() {
117116
// parentExcess = TARGET_GAS + 1 = 1835009, just above target so not clamped to 0
118117
// With base_fee=17: 17*8192=139264 > 1*131072=131072 → EIP-7918 branch
119118
// excess = 1835009 + parentBlobGasUsed * 7 / 21
@@ -131,7 +130,7 @@ Iterable<Arguments> eip7918BranchBlobGasses() {
131130
@Test
132131
void defaultGasLimit() {
133132
GasLimitCalculator calculator =
134-
new OsakaTargetingGasLimitCalculator(
133+
new AmsterdamTargetingGasLimitCalculator(
135134
0L,
136135
FeeMarket.cancun(0L, Optional.empty(), BlobSchedule.BPO2_DEFAULT),
137136
new AmsterdamGasCalculator(),
@@ -144,11 +143,4 @@ void defaultGasLimit() {
144143
// per-tx cap: DEFAULT_MAX_BLOBS_PER_TRANSACTION (6) * 131072 = 0xC0000
145144
assertThat(calculator.transactionBlobGasLimitCap()).isEqualTo(0xC0000);
146145
}
147-
148-
@Test
149-
void dryRunDetector() {
150-
Assertions.assertThat(true)
151-
.withFailMessage("This test is here so gradle --dry-run executes this class")
152-
.isTrue();
153-
}
154146
}

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

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@
2020
import org.hyperledger.besu.ethereum.GasLimitCalculator;
2121
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
2222
import org.hyperledger.besu.evm.gascalculator.CancunGasCalculator;
23-
import org.hyperledger.besu.evm.gascalculator.OsakaGasCalculator;
2423
import org.hyperledger.besu.evm.gascalculator.PragueGasCalculator;
2524

2625
import java.util.List;
2726
import java.util.Optional;
28-
import java.util.OptionalInt;
2927

3028
import org.assertj.core.api.Assertions;
3129
import org.junit.jupiter.api.Test;
@@ -147,47 +145,6 @@ void shouldCalculateCorrectlyPragueBlobGasPerBlob() {
147145
assertThat(pragueTargetingGasLimitCalculator.currentBlobGasLimit()).isEqualTo(1310720);
148146
}
149147

150-
long nineBlobTargetGas = TARGET_BLOB_GAS_PER_BLOCK_OSAKA;
151-
int newTargetCount = 9;
152-
public static final OsakaGasCalculator osakaGasCalculator = new OsakaGasCalculator();
153-
// CancunTargetingGasLimitCalculator with Osaka numbers
154-
private final OsakaTargetingGasLimitCalculator osakaGasLimitCalculator =
155-
new OsakaTargetingGasLimitCalculator(
156-
0L,
157-
FeeMarket.cancunDefault(0L, Optional.empty()),
158-
osakaGasCalculator,
159-
BlobSchedule.PRAGUE_DEFAULT.getMax(),
160-
newTargetCount,
161-
OptionalInt.empty(),
162-
OptionalInt.empty());
163-
164-
private static final long TARGET_BLOB_GAS_PER_BLOCK_OSAKA = 0x120000;
165-
166-
@ParameterizedTest(name = "{index} - parent gas {0}, used gas {1}, blob target {2}")
167-
@MethodSource("osakaBlobGasses")
168-
public void shouldCalculateOsakaExcessBlobGasCorrectly(
169-
final long parentExcess, final long used, final long expected) {
170-
final long usedBlobGas = osakaGasCalculator.blobGasCost(used);
171-
assertThat(osakaGasLimitCalculator.computeExcessBlobGas(parentExcess, usedBlobGas, 0L))
172-
.isEqualTo(expected);
173-
}
174-
175-
Iterable<Arguments> osakaBlobGasses() {
176-
177-
return List.of(
178-
// New target count
179-
Arguments.of(0L, 0L, 0L),
180-
Arguments.of(nineBlobTargetGas, 0L, 0L),
181-
Arguments.of(newTargetCount, 0L, 0L),
182-
Arguments.of(0L, newTargetCount, 0L),
183-
Arguments.of(1L, newTargetCount, 1L),
184-
Arguments.of(
185-
osakaGasCalculator.blobGasCost(newTargetCount),
186-
1L,
187-
osakaGasLimitCalculator.getBlobGasPerBlob()),
188-
Arguments.of(nineBlobTargetGas, newTargetCount, nineBlobTargetGas));
189-
}
190-
191148
@Test
192149
void cancunDefaultGasLimit() {
193150
GasLimitCalculator gasLimitCalculator =

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
import static org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId.PRAGUE;
3636
import static org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId.SHANGHAI;
3737
import static org.mockito.ArgumentMatchers.any;
38+
import static org.mockito.Mockito.lenient;
3839
import static org.mockito.Mockito.mock;
3940
import static org.mockito.Mockito.times;
4041
import static org.mockito.Mockito.verify;
4142
import static org.mockito.Mockito.when;
42-
import static org.mockito.Mockito.withSettings;
4343

4444
import org.hyperledger.besu.config.BlobSchedule;
4545
import org.hyperledger.besu.config.BlobScheduleOptions;
@@ -557,12 +557,19 @@ void inactiveBpoForkBlobScheduleIsNotApplied() {
557557
when(configOptions.getWithdrawalRequestContractAddress()).thenReturn(Optional.of(Address.ZERO));
558558

559559
// Set up blob schedule: BPO2 has max=21, BPO3-5 have max=9 (deliberately different)
560-
final BlobScheduleOptions blobScheduleOptions =
561-
mock(BlobScheduleOptions.class, withSettings().lenient());
560+
final BlobScheduleOptions blobScheduleOptions = mock(BlobScheduleOptions.class);
562561
when(blobScheduleOptions.getBpo2()).thenReturn(Optional.of(BlobSchedule.BPO2_DEFAULT));
563-
when(blobScheduleOptions.getBpo3()).thenReturn(Optional.of(BlobSchedule.PRAGUE_DEFAULT));
564-
when(blobScheduleOptions.getBpo4()).thenReturn(Optional.of(BlobSchedule.PRAGUE_DEFAULT));
565-
when(blobScheduleOptions.getBpo5()).thenReturn(Optional.of(BlobSchedule.PRAGUE_DEFAULT));
562+
// BPO3-5 stubs are lenient because these forks lack timestamps, so the production code
563+
// never calls getBpo3/4/5 — but we set them up to verify they are NOT applied.
564+
lenient()
565+
.when(blobScheduleOptions.getBpo3())
566+
.thenReturn(Optional.of(BlobSchedule.PRAGUE_DEFAULT));
567+
lenient()
568+
.when(blobScheduleOptions.getBpo4())
569+
.thenReturn(Optional.of(BlobSchedule.PRAGUE_DEFAULT));
570+
lenient()
571+
.when(blobScheduleOptions.getBpo5())
572+
.thenReturn(Optional.of(BlobSchedule.PRAGUE_DEFAULT));
566573
when(configOptions.getBlobScheduleOptions()).thenReturn(Optional.of(blobScheduleOptions));
567574

568575
final ProtocolSchedule protocolSchedule = builder.createProtocolSchedule();

0 commit comments

Comments
 (0)