Skip to content

Commit 54abff0

Browse files
Hard code max blobs per tx to 6 for Osaka (#8929)
* Hard code max blobs per tx to 6 for Osaka Signed-off-by: Fabio Di Fabio <[email protected]> * Apply suggestions from code review Signed-off-by: Fabio Di Fabio <[email protected]> --------- Signed-off-by: Fabio Di Fabio <[email protected]> Co-authored-by: Gabriel-Trintinalia <[email protected]>
1 parent 237f343 commit 54abff0

File tree

11 files changed

+112
-159
lines changed

11 files changed

+112
-159
lines changed

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

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,18 @@
2121
/** The Blob schedule for a particular fork. */
2222
public class BlobSchedule {
2323
/** The constant CANCUN_DEFAULT. */
24-
public static final BlobSchedule CANCUN_DEFAULT = BlobSchedule.create(3, 6, 6, 3338477);
24+
public static final BlobSchedule CANCUN_DEFAULT = BlobSchedule.create(3, 6, 3338477);
2525

2626
/** The constant PRAGUE_DEFAULT. */
27-
public static final BlobSchedule PRAGUE_DEFAULT = BlobSchedule.create(6, 9, 9, 5007716);
27+
public static final BlobSchedule PRAGUE_DEFAULT = BlobSchedule.create(6, 9, 5007716);
2828

2929
private final int target;
3030
private final int max;
31-
private final int maxPerTransaction;
3231
private final int baseFeeUpdateFraction;
3332

34-
private BlobSchedule(
35-
final int target,
36-
final int max,
37-
final int maxPerTransaction,
38-
final int baseFeeUpdateFraction) {
33+
private BlobSchedule(final int target, final int max, final int baseFeeUpdateFraction) {
3934
this.target = target;
4035
this.max = max;
41-
this.maxPerTransaction = maxPerTransaction;
4236
this.baseFeeUpdateFraction = baseFeeUpdateFraction;
4337
}
4438

@@ -51,18 +45,14 @@ private BlobSchedule(
5145
public static BlobSchedule create(final ObjectNode blobScheduleConfigRoot) {
5246
int target = JsonUtil.getInt(blobScheduleConfigRoot, "target").orElseThrow();
5347
int max = JsonUtil.getInt(blobScheduleConfigRoot, "max").orElseThrow();
54-
int maxPerTransaction = JsonUtil.getInt(blobScheduleConfigRoot, "maxblobspertx").orElse(max);
5548
int baseFeeUpdateFraction =
5649
JsonUtil.getInt(blobScheduleConfigRoot, "basefeeupdatefraction").orElseThrow();
57-
return create(target, max, maxPerTransaction, baseFeeUpdateFraction);
50+
return create(target, max, baseFeeUpdateFraction);
5851
}
5952

6053
private static BlobSchedule create(
61-
final int target,
62-
final int max,
63-
final int maxPerTransaction,
64-
final int baseFeeUpdateFraction) {
65-
return new BlobSchedule(target, max, maxPerTransaction, baseFeeUpdateFraction);
54+
final int target, final int max, final int baseFeeUpdateFraction) {
55+
return new BlobSchedule(target, max, baseFeeUpdateFraction);
6656
}
6757

6858
/**
@@ -83,15 +73,6 @@ public int getMax() {
8373
return max;
8474
}
8575

86-
/**
87-
* Gets max per transaction.
88-
*
89-
* @return the max per transaction
90-
*/
91-
public int getMaxPerTransaction() {
92-
return maxPerTransaction;
93-
}
94-
9576
/**
9677
* Gets base fee update fraction.
9778
*
@@ -126,7 +107,7 @@ public String toString() {
126107
public static class NoBlobSchedule extends BlobSchedule {
127108
/** Constructs a NoBlobSchedule */
128109
public NoBlobSchedule() {
129-
super(0, 0, 0, 0);
110+
super(0, 0, 0);
130111
}
131112

132113
@Override
@@ -144,11 +125,6 @@ public int getBaseFeeUpdateFraction() {
144125
throw new UnsupportedOperationException("NoBlobSchedule does not support this operation.");
145126
}
146127

147-
@Override
148-
public int getMaxPerTransaction() {
149-
throw new UnsupportedOperationException("NoBlobSchedule does not support this operation.");
150-
}
151-
152128
@Override
153129
public Map<String, Object> asMap() {
154130
throw new UnsupportedOperationException("NoBlobSchedule does not support this operation.");

config/src/test/java/org/hyperledger/besu/config/BlobScheduleOptionsTest.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,11 @@ public void blobScheduleIsParsed() {
4949
@Test
5050
public void blobScheduleDefaults() {
5151
assertThat(BlobSchedule.CANCUN_DEFAULT.getTarget()).isEqualTo(3);
52-
assertThat(BlobSchedule.CANCUN_DEFAULT.getMaxPerTransaction()).isEqualTo(6);
5352
assertThat(BlobSchedule.CANCUN_DEFAULT.getMax()).isEqualTo(6);
5453
assertThat(BlobSchedule.PRAGUE_DEFAULT.getTarget()).isEqualTo(6);
55-
assertThat(BlobSchedule.PRAGUE_DEFAULT.getMaxPerTransaction()).isEqualTo(9);
5654
assertThat(BlobSchedule.PRAGUE_DEFAULT.getMax()).isEqualTo(9);
5755
}
5856

59-
@Test
60-
public void blobScheduleMaxPerTransactionDefaultsToMax() {
61-
Optional<BlobSchedule> cancun = options.getCancun();
62-
assertThat(cancun).isNotEmpty();
63-
BlobSchedule schedule = cancun.get();
64-
assertThat(schedule.getMaxPerTransaction()).isEqualTo(schedule.getMax());
65-
}
66-
67-
@Test
68-
public void blobScheduleMaxPerTransactionIsSpecified() {
69-
Optional<BlobSchedule> bpo1 = options.getBpo1();
70-
assertThat(bpo1).isNotEmpty();
71-
BlobSchedule schedule = bpo1.get();
72-
assertThat(schedule.getMax()).isEqualTo(12);
73-
assertThat(schedule.getMaxPerTransaction()).isEqualTo(13);
74-
}
75-
7657
private void assertParsed(
7758
final Supplier<Optional<BlobSchedule>> scheduleSupplier,
7859
final int expectedTarget,

config/src/test/resources/mainnet_with_blob_schedule.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,26 @@
3030
"bpo1": {
3131
"target": 11,
3232
"max": 12,
33-
"maxBlobsPerTx": 13,
3433
"baseFeeUpdateFraction": 5007716
3534
},
3635
"bpo2": {
3736
"target": 21,
3837
"max": 22,
39-
"maxBlobsPerTx": 23,
4038
"baseFeeUpdateFraction": 5007716
4139
},
4240
"bpo3": {
4341
"target": 31,
4442
"max": 32,
45-
"maxBlobsPerTx": 33,
4643
"baseFeeUpdateFraction": 5007716
4744
},
4845
"bpo4": {
4946
"target": 41,
5047
"max": 42,
51-
"maxBlobsPerTx": 43,
5248
"baseFeeUpdateFraction": 5007716
5349
},
5450
"bpo5": {
5551
"target": 51,
5652
"max": 52,
57-
"maxBlobsPerTx": 53,
5853
"baseFeeUpdateFraction": 5007716
5954
},
6055
"future_eips": {

ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthBlobBaseFeeTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
import org.junit.jupiter.api.Test;
4242

4343
public class EthBlobBaseFeeTest {
44+
private static final int MAX_BLOBS_PER_BLOCK = 6;
45+
private static final int TARGET_BLOBS_PER_BLOCK = 3;
4446
private final BlockDataGenerator blockDataGenerator = new BlockDataGenerator();
4547
private MutableBlockchain blockchain;
4648
private EthBlobBaseFee method;
@@ -62,7 +64,11 @@ public void setUp() {
6264
public void shouldReturnBlobBaseFee() {
6365
final CancunTargetingGasLimitCalculator gasLimitCalculator =
6466
new CancunTargetingGasLimitCalculator(
65-
0L, FeeMarket.cancunDefault(0L, Optional.empty()), new CancunGasCalculator());
67+
0L,
68+
FeeMarket.cancunDefault(0L, Optional.empty()),
69+
new CancunGasCalculator(),
70+
MAX_BLOBS_PER_BLOCK,
71+
TARGET_BLOBS_PER_BLOCK);
6672
configureProtocolSpec(
6773
FeeMarket.cancunDefault(5, Optional.empty()),
6874
new CancunGasCalculator(),
@@ -75,7 +81,11 @@ public void shouldReturnBlobBaseFee() {
7581
public void shouldReturnZeroForNonBlobForks() {
7682
final CancunTargetingGasLimitCalculator gasLimitCalculator =
7783
new CancunTargetingGasLimitCalculator(
78-
0L, FeeMarket.cancunDefault(0L, Optional.empty()), new ShanghaiGasCalculator());
84+
0L,
85+
FeeMarket.cancunDefault(0L, Optional.empty()),
86+
new ShanghaiGasCalculator(),
87+
MAX_BLOBS_PER_BLOCK,
88+
TARGET_BLOBS_PER_BLOCK);
7989
configureProtocolSpec(
8090
FeeMarket.london(5, Optional.empty()), new ShanghaiGasCalculator(), gasLimitCalculator);
8191
assertThat(requestBlobBaseFee().getResult()).isEqualTo("0x0");

ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
import org.junit.jupiter.api.Test;
6565

6666
public class EthGetTransactionReceiptTest {
67+
private static final int MAX_BLOBS_PER_BLOCK = 6;
68+
private static final int TARGET_BLOBS_PER_BLOCK = 3;
6769
private final TransactionReceipt statusReceipt =
6870
new TransactionReceipt(1, 12, Collections.emptyList(), Optional.empty());
6971
private final Hash stateRoot =
@@ -329,7 +331,11 @@ private void mockProtocolSpec(final BlockHeader blockHeader) {
329331
when(spec.getGasLimitCalculator())
330332
.thenReturn(
331333
new CancunTargetingGasLimitCalculator(
332-
0L, FeeMarket.cancunDefault(0L, Optional.empty()), new CancunGasCalculator()));
334+
0L,
335+
FeeMarket.cancunDefault(0L, Optional.empty()),
336+
new CancunGasCalculator(),
337+
MAX_BLOBS_PER_BLOCK,
338+
TARGET_BLOBS_PER_BLOCK));
333339
when(protocolSchedule.getByBlockHeader(blockHeader)).thenReturn(spec);
334340
}
335341

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

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,16 @@
1414
*/
1515
package org.hyperledger.besu.ethereum.mainnet;
1616

17-
import static com.google.common.base.Preconditions.checkArgument;
18-
1917
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
2018
import org.hyperledger.besu.evm.gascalculator.GasCalculator;
2119

2220
public class CancunTargetingGasLimitCalculator extends LondonTargetingGasLimitCalculator {
23-
24-
/** The mainnet default maximum number of blobs per block for Cancun */
25-
private static final int DEFAULT_MAX_BLOBS_PER_BLOCK_CANCUN = 6;
26-
27-
/** The default target number of blobs per transaction for Cancun */
28-
private static final int DEFAULT_MAX_BLOBS_PER_TRANSACTION_CANCUN = 6;
29-
30-
/** The default mainnet target blobs per block for Cancun */
31-
private static final int DEFAULT_TARGET_BLOBS_PER_BLOCK_CANCUN = 3;
32-
3321
private final long maxBlobGasPerBlock;
34-
3522
private final long targetBlobGasPerBlock;
36-
3723
private final long blobGasPerBlob;
24+
3825
protected final int maxBlobsPerBlock;
3926
protected final int targetBlobsPerBlock;
40-
private final long transactionBlobGasLimitCap;
41-
42-
public CancunTargetingGasLimitCalculator(
43-
final long londonForkBlock,
44-
final BaseFeeMarket feeMarket,
45-
final GasCalculator gasCalculator) {
46-
this(
47-
londonForkBlock,
48-
feeMarket,
49-
gasCalculator,
50-
DEFAULT_MAX_BLOBS_PER_BLOCK_CANCUN,
51-
DEFAULT_TARGET_BLOBS_PER_BLOCK_CANCUN,
52-
DEFAULT_MAX_BLOBS_PER_TRANSACTION_CANCUN);
53-
}
5427

5528
/**
5629
* Using Cancun mainnet default of 6 blobs for maxBlobsPerBlock: getBlobGasPerBlob() * 6 blobs =
@@ -61,20 +34,13 @@ public CancunTargetingGasLimitCalculator(
6134
final BaseFeeMarket feeMarket,
6235
final GasCalculator gasCalculator,
6336
final int maxBlobsPerBlock,
64-
final int targetBlobsPerBlock,
65-
final int maxBlobsPerTransaction) {
37+
final int targetBlobsPerBlock) {
6638
super(londonForkBlock, feeMarket);
6739
this.blobGasPerBlob = gasCalculator.getBlobGasPerBlob();
6840
this.targetBlobGasPerBlock = blobGasPerBlob * targetBlobsPerBlock;
6941
this.maxBlobGasPerBlock = blobGasPerBlob * maxBlobsPerBlock;
7042
this.maxBlobsPerBlock = maxBlobsPerBlock;
7143
this.targetBlobsPerBlock = targetBlobsPerBlock;
72-
this.transactionBlobGasLimitCap = gasCalculator.getBlobGasPerBlob() * maxBlobsPerTransaction;
73-
checkArgument(
74-
maxBlobsPerBlock >= maxBlobsPerTransaction,
75-
"maxBlobsPerTransaction (%s) must not be greater than maxBlobsPerBlock (%s)",
76-
maxBlobsPerTransaction,
77-
maxBlobsPerBlock);
7844
}
7945

8046
@Override
@@ -114,6 +80,6 @@ public long getMaxBlobGasPerBlock() {
11480

11581
@Override
11682
public long transactionBlobGasLimitCap() {
117-
return transactionBlobGasLimitCap;
83+
return maxBlobGasPerBlock;
11884
}
11985
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,7 @@ static ProtocolSpecBuilder cancunDefinition(
692692
(BaseFeeMarket) feeMarket,
693693
gasCalculator,
694694
blobSchedule.getMax(),
695-
blobSchedule.getTarget(),
696-
blobSchedule.getMaxPerTransaction()))
695+
blobSchedule.getTarget()))
697696
// EVM changes to support EIP-1153: TSTORE and EIP-5656: MCOPY
698697
.evmBuilder(
699698
(gasCalculator, jdCacheConfig) ->
@@ -783,7 +782,6 @@ static ProtocolSpecBuilder pragueDefinition(
783782
.flatMap(BlobScheduleOptions::getPrague)
784783
.orElse(BlobSchedule.PRAGUE_DEFAULT))
785784
.gasCalculator(PragueGasCalculator::new)
786-
// EIP-3074 AUTH and AUTHCALL
787785
.evmBuilder(
788786
(gasCalculator, jdCacheConfig) ->
789787
MainnetEVMs.prague(
@@ -879,8 +877,7 @@ static ProtocolSpecBuilder osakaDefinition(
879877
(BaseFeeMarket) feeMarket,
880878
gasCalculator,
881879
blobSchedule.getMax(),
882-
blobSchedule.getTarget(),
883-
blobSchedule.getMaxPerTransaction()))
880+
blobSchedule.getTarget()))
884881
.evmBuilder(
885882
(gasCalculator, __) ->
886883
MainnetEVMs.osaka(gasCalculator, chainId.orElse(BigInteger.ZERO), evmConfiguration))

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,39 @@
1414
*/
1515
package org.hyperledger.besu.ethereum.mainnet;
1616

17+
import static com.google.common.base.Preconditions.checkArgument;
18+
1719
import org.hyperledger.besu.datatypes.BlobGas;
1820
import org.hyperledger.besu.datatypes.Wei;
1921
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
2022
import org.hyperledger.besu.evm.gascalculator.GasCalculator;
2123

2224
public class OsakaTargetingGasLimitCalculator extends CancunTargetingGasLimitCalculator {
25+
/** The constant max number of blobs per transaction defined for Osaka */
26+
private static final int DEFAULT_MAX_BLOBS_PER_TRANSACTION = 6;
27+
2328
/** The blob base cost constant for Osaka */
2429
private static final long BLOB_BASE_COST = 1 << 13; // 2^13
2530

2631
/** The mainnet transaction gas limit cap for Osaka */
2732
private static final long DEFAULT_TRANSACTION_GAS_LIMIT_CAP_OSAKA = 30_000_000L;
2833

2934
private final long transactionGasLimitCap;
35+
private final long transactionBlobGasLimitCap;
3036

3137
public OsakaTargetingGasLimitCalculator(
3238
final long londonForkBlock,
3339
final BaseFeeMarket feeMarket,
3440
final GasCalculator gasCalculator,
3541
final int maxBlobsPerBlock,
36-
final int targetBlobsPerBlock,
37-
final int maxBlobsPerTransaction) {
42+
final int targetBlobsPerBlock) {
3843
this(
3944
londonForkBlock,
4045
feeMarket,
4146
gasCalculator,
4247
maxBlobsPerBlock,
4348
targetBlobsPerBlock,
44-
maxBlobsPerTransaction,
49+
DEFAULT_MAX_BLOBS_PER_TRANSACTION,
4550
DEFAULT_TRANSACTION_GAS_LIMIT_CAP_OSAKA);
4651
}
4752

@@ -53,14 +58,14 @@ public OsakaTargetingGasLimitCalculator(
5358
final int targetBlobsPerBlock,
5459
final int maxBlobsPerTransaction,
5560
final long transactionGasLimitCap) {
56-
super(
57-
londonForkBlock,
58-
feeMarket,
59-
gasCalculator,
60-
maxBlobsPerBlock,
61-
targetBlobsPerBlock,
62-
maxBlobsPerTransaction);
61+
super(londonForkBlock, feeMarket, gasCalculator, maxBlobsPerBlock, targetBlobsPerBlock);
6362
this.transactionGasLimitCap = transactionGasLimitCap;
63+
this.transactionBlobGasLimitCap = gasCalculator.getBlobGasPerBlob() * maxBlobsPerTransaction;
64+
checkArgument(
65+
maxBlobsPerBlock >= maxBlobsPerTransaction,
66+
"maxBlobsPerTransaction (%s) must not be greater than maxBlobsPerBlock (%s)",
67+
maxBlobsPerTransaction,
68+
maxBlobsPerBlock);
6469
}
6570

6671
@Override
@@ -91,4 +96,9 @@ public long computeExcessBlobGas(
9196
return currentExcessBlobGas - getTargetBlobGasPerBlock();
9297
}
9398
}
99+
100+
@Override
101+
public long transactionBlobGasLimitCap() {
102+
return transactionBlobGasLimitCap;
103+
}
94104
}

0 commit comments

Comments
 (0)