Skip to content

Commit 3dc6fd9

Browse files
committed
EIP-7840 prototype
Signed-off-by: Simon Dudley <simon.dudley@consensys.net>
1 parent 929945a commit 3dc6fd9

File tree

22 files changed

+543
-88
lines changed

22 files changed

+543
-88
lines changed

acceptance-tests/tests/src/test/resources/dev/dev_prague.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@
1515
"terminalTotalDifficulty":0,
1616
"cancunTime":0,
1717
"pragueTime":0,
18+
"blobSchedule": {
19+
"cancun": {
20+
"target": 3,
21+
"max": 6
22+
},
23+
"prague": {
24+
"target": 6,
25+
"max": 9
26+
},
27+
"osaka": {
28+
"target": 9,
29+
"max": 12
30+
}
31+
},
1832
"clique": {
1933
"period": 5,
2034
"epoch": 30000
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright contributors to Hyperledger 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.config;
16+
17+
import java.util.Optional;
18+
19+
import com.fasterxml.jackson.databind.node.ObjectNode;
20+
21+
/** The Checkpoint config options. */
22+
public class BlobScheduleOptions {
23+
24+
/** The constant DEFAULT. */
25+
public static final BlobScheduleOptions DEFAULT =
26+
new BlobScheduleOptions(JsonUtil.createEmptyObjectNode());
27+
28+
private final ObjectNode blobScheduleOptionsConfigRoot;
29+
30+
private static final String CANCUN_KEY = "cancun";
31+
private static final String PRAGUE_KEY = "prague";
32+
private static final String OSAKA_KEY = "osaka";
33+
34+
/**
35+
* Instantiates a new Blob Schedule config options.
36+
*
37+
* @param blobScheduleConfigRoot the blob schedule config root
38+
*/
39+
public BlobScheduleOptions(final ObjectNode blobScheduleConfigRoot) {
40+
this.blobScheduleOptionsConfigRoot = blobScheduleConfigRoot;
41+
}
42+
43+
/**
44+
* Gets cancun blob schedule.
45+
*
46+
* @return the cancun blob schedule
47+
*/
48+
public Optional<BlobSchedule> getCancun() {
49+
return JsonUtil.getObjectNode(blobScheduleOptionsConfigRoot, CANCUN_KEY).map(BlobSchedule::new);
50+
}
51+
52+
/**
53+
* Gets prague blob schedule.
54+
*
55+
* @return the prague blob schedule
56+
*/
57+
public Optional<BlobSchedule> getPrague() {
58+
return JsonUtil.getObjectNode(blobScheduleOptionsConfigRoot, PRAGUE_KEY).map(BlobSchedule::new);
59+
}
60+
61+
/**
62+
* Gets osaka blob schedule.
63+
*
64+
* @return the osaka blob schedule
65+
*/
66+
public Optional<BlobSchedule> getOsaka() {
67+
return JsonUtil.getObjectNode(blobScheduleOptionsConfigRoot, OSAKA_KEY).map(BlobSchedule::new);
68+
}
69+
70+
/** The Blob schedule for a particular fork. */
71+
public static class BlobSchedule {
72+
private final ObjectNode blobScheduleConfigRoot;
73+
74+
/**
75+
* Instantiates a new Blob schedule.
76+
*
77+
* @param blobScheduleItemConfigRoot the blob schedule item config root
78+
*/
79+
public BlobSchedule(final ObjectNode blobScheduleItemConfigRoot) {
80+
this.blobScheduleConfigRoot = blobScheduleItemConfigRoot;
81+
}
82+
83+
/**
84+
* Gets target.
85+
*
86+
* @return the target
87+
*/
88+
public int getTarget() {
89+
return JsonUtil.getInt(blobScheduleConfigRoot, "target").orElseThrow();
90+
}
91+
92+
/**
93+
* Gets max.
94+
*
95+
* @return the max
96+
*/
97+
public int getMax() {
98+
return JsonUtil.getInt(blobScheduleConfigRoot, "max").orElseThrow();
99+
}
100+
}
101+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,4 +546,11 @@ default boolean isConsensusMigration() {
546546
* @return the consolidation request contract address
547547
*/
548548
Optional<Address> getConsolidationRequestContractAddress();
549+
550+
/**
551+
* The blob schedule is a list of hardfork names and their associated target and max blob values.
552+
*
553+
* @return the blob schedule
554+
*/
555+
BlobScheduleOptions getBlobScheduleOptions();
549556
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions {
4747
private static final String TRANSITIONS_CONFIG_KEY = "transitions";
4848
private static final String DISCOVERY_CONFIG_KEY = "discovery";
4949
private static final String CHECKPOINT_CONFIG_KEY = "checkpoint";
50+
private static final String BLOB_SCHEDULE_CONFIG_KEY = "blobschedule";
5051
private static final String ZERO_BASE_FEE_KEY = "zerobasefee";
5152
private static final String FIXED_BASE_FEE_KEY = "fixedbasefee";
5253
private static final String WITHDRAWAL_REQUEST_CONTRACT_ADDRESS_KEY =
@@ -199,6 +200,13 @@ public EthashConfigOptions getEthashConfigOptions() {
199200
.orElse(EthashConfigOptions.DEFAULT);
200201
}
201202

203+
@Override
204+
public BlobScheduleOptions getBlobScheduleOptions() {
205+
return JsonUtil.getObjectNode(configRoot, BLOB_SCHEDULE_CONFIG_KEY)
206+
.map(BlobScheduleOptions::new)
207+
.orElse(BlobScheduleOptions.DEFAULT);
208+
}
209+
202210
@Override
203211
public TransitionsConfigOptions getTransitions() {
204212
return transitions;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,11 @@ public Optional<Address> getConsolidationRequestContractAddress() {
472472
return Optional.empty();
473473
}
474474

475+
@Override
476+
public BlobScheduleOptions getBlobScheduleOptions() {
477+
return BlobScheduleOptions.DEFAULT;
478+
}
479+
475480
/**
476481
* Homestead block stub genesis config options.
477482
*
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright contributors to Hyperledger 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.config;
16+
17+
import static org.assertj.core.api.Assertions.assertThat;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
public class BlobScheduleOptionsTest {
22+
23+
@Test
24+
public void blobScheduleIsParsed() {
25+
final GenesisConfigFile genesisConfigFile =
26+
GenesisConfigFile.fromResource("/mainnet_with_blob_schedule.json");
27+
final GenesisConfigOptions configOptions = genesisConfigFile.getConfigOptions();
28+
29+
assertThat(configOptions.getBlobScheduleOptions().getCancun().get().getTarget()).isEqualTo(3);
30+
assertThat(configOptions.getBlobScheduleOptions().getCancun().get().getMax()).isEqualTo(6);
31+
assertThat(configOptions.getBlobScheduleOptions().getPrague().get().getTarget()).isEqualTo(6);
32+
assertThat(configOptions.getBlobScheduleOptions().getPrague().get().getMax()).isEqualTo(9);
33+
assertThat(configOptions.getBlobScheduleOptions().getOsaka().get().getTarget()).isEqualTo(9);
34+
assertThat(configOptions.getBlobScheduleOptions().getOsaka().get().getMax()).isEqualTo(12);
35+
}
36+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"config": {
3+
"chainId": 3151908,
4+
"homesteadBlock": 0,
5+
"eip150Block": 0,
6+
"eip155Block": 0,
7+
"eip158Block": 0,
8+
"byzantiumBlock": 0,
9+
"constantinopleBlock": 0,
10+
"petersburgBlock": 0,
11+
"istanbulBlock": 0,
12+
"berlinBlock": 0,
13+
"londonBlock": 0,
14+
"preMergeForkBlock": 0,
15+
"terminalTotalDifficulty": 0,
16+
"ethash": {},
17+
"shanghaiTime": 0,
18+
"cancunTime": 0,
19+
"blobSchedule": {
20+
"cancun": {
21+
"target": 3,
22+
"max": 6
23+
},
24+
"prague": {
25+
"target": 6,
26+
"max": 9
27+
},
28+
"osaka": {
29+
"target": 9,
30+
"max": 12
31+
}
32+
},
33+
"depositContractAddress": "0x4242424242424242424242424242424242424242",
34+
"pragueTime": 1734106711,
35+
"osakaTime": 1734107095
36+
}
37+
}

ethereum/core/src/main/java/org/hyperledger/besu/ethereum/GasLimitCalculator.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@
1717
/** The GasLimitCalculator interface defines methods for calculating the gas limit. */
1818
public interface GasLimitCalculator {
1919

20-
/** The constant BLOB_GAS_LIMIT represents the gas limit for blob data. */
21-
long BLOB_GAS_LIMIT = 786432;
20+
/**
21+
* The constant BLOB_GAS_LIMIT represents the gas limit for blob data. Defaults to the Cancun
22+
* value where it was first introduced as part of EIP-4844
23+
*/
24+
long BLOB_GAS_LIMIT = 0xC0000;
2225

2326
/**
2427
* Calculates the next gas limit based on the current gas limit, target gas limit, and new block

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,36 @@
1515
package org.hyperledger.besu.ethereum.mainnet;
1616

1717
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
18+
import org.hyperledger.besu.evm.gascalculator.CancunGasCalculator;
1819

1920
public class CancunTargetingGasLimitCalculator extends LondonTargetingGasLimitCalculator {
20-
private static final long MAX_BLOB_GAS_PER_BLOCK = 786432L;
21+
22+
/**
23+
* The constant MAX_BLOB_GAS_PER_BLOCK represents the maximum gas limit for blob data. =
24+
* CancunGasCalculator.BLOB_GAS_PER_BLOB * 6 blobs = 131072 * 6 = 786432 = 0xC0000
25+
*/
26+
private static final int DEFAULT_MAX_BLOBS_PER_BLOCK = 6;
27+
28+
/**
29+
* The maximum gas limit for blob data per block. getBlobGasPerBlob() * 6 blobs = 131072 * 6 =
30+
* 786432 = 0xC0000
31+
*/
32+
private final long maxBlobGasPerBlock;
2133

2234
public CancunTargetingGasLimitCalculator(
2335
final long londonForkBlock, final BaseFeeMarket feeMarket) {
36+
this(londonForkBlock, feeMarket, DEFAULT_MAX_BLOBS_PER_BLOCK);
37+
}
38+
39+
public CancunTargetingGasLimitCalculator(
40+
final long londonForkBlock, final BaseFeeMarket feeMarket, final int maxBlobsPerBlock) {
2441
super(londonForkBlock, feeMarket);
42+
final CancunGasCalculator cancunGasCalculator = new CancunGasCalculator();
43+
this.maxBlobGasPerBlock = cancunGasCalculator.getBlobGasPerBlob() * maxBlobsPerBlock;
2544
}
2645

2746
@Override
2847
public long currentBlobGasLimit() {
29-
return MAX_BLOB_GAS_PER_BLOCK;
48+
return maxBlobGasPerBlock;
3049
}
3150
}

0 commit comments

Comments
 (0)