Skip to content

Commit

Permalink
EIP-7840 prototype
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Dudley <[email protected]>
  • Loading branch information
siladu committed Dec 17, 2024
1 parent 929945a commit 35062a4
Show file tree
Hide file tree
Showing 22 changed files with 552 additions and 88 deletions.
14 changes: 14 additions & 0 deletions acceptance-tests/tests/src/test/resources/dev/dev_prague.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@
"terminalTotalDifficulty":0,
"cancunTime":0,
"pragueTime":0,
"blobSchedule": {
"cancun": {
"target": 3,
"max": 6
},
"prague": {
"target": 6,
"max": 9
},
"osaka": {
"target": 9,
"max": 12
}
},
"clique": {
"period": 5,
"epoch": 30000
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright contributors to Hyperledger Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.config;

import com.fasterxml.jackson.databind.node.ObjectNode;

/** The Checkpoint config options. */
public class BlobScheduleOptions {

/** The constant DEFAULT. */
public static final BlobScheduleOptions DEFAULT =
new BlobScheduleOptions(JsonUtil.createEmptyObjectNode());

private final ObjectNode blobScheduleOptionsConfigRoot;

private static final String CANCUN_KEY = "cancun";
private static final String PRAGUE_KEY = "prague";
private static final String OSAKA_KEY = "osaka";

/**
* Instantiates a new Blob Schedule config options.
*
* @param blobScheduleConfigRoot the blob schedule config root
*/
public BlobScheduleOptions(final ObjectNode blobScheduleConfigRoot) {
this.blobScheduleOptionsConfigRoot = blobScheduleConfigRoot;
}

/**
* Gets cancun blob schedule.
*
* @return the cancun blob schedule
*/
public BlobSchedule getCancun() {
return JsonUtil.getObjectNode(blobScheduleOptionsConfigRoot, CANCUN_KEY)
.map(BlobSchedule::new)
.orElse(BlobSchedule.DEFAULT);
}

/**
* Gets prague blob schedule.
*
* @return the prague blob schedule
*/
public BlobSchedule getPrague() {
return JsonUtil.getObjectNode(blobScheduleOptionsConfigRoot, PRAGUE_KEY)
.map(BlobSchedule::new)
.orElse(BlobSchedule.DEFAULT);
}

/**
* Gets osaka blob schedule.
*
* @return the osaka blob schedule
*/
public BlobSchedule getOsaka() {
return JsonUtil.getObjectNode(blobScheduleOptionsConfigRoot, OSAKA_KEY)
.map(BlobSchedule::new)
.orElse(BlobSchedule.DEFAULT);
}

/** The Blob schedule for a particular fork. */
public static class BlobSchedule {
private final ObjectNode blobScheduleConfigRoot;

/** The constant DEFAULT. */
public static final BlobSchedule DEFAULT = new BlobSchedule(JsonUtil.createEmptyObjectNode());

/**
* Instantiates a new Blob schedule.
*
* @param blobScheduleItemConfigRoot the blob schedule item config root
*/
public BlobSchedule(final ObjectNode blobScheduleItemConfigRoot) {
this.blobScheduleConfigRoot = blobScheduleItemConfigRoot;
}

/**
* Gets target.
*
* @return the target
*/
public int getTarget() {
// TODO SLD EIP-7840 - reasonable default?
return JsonUtil.getInt(blobScheduleConfigRoot, "target").orElse(3);
}

/**
* Gets max.
*
* @return the max
*/
public int getMax() {
// TODO SLD EIP-7840 - reasonable default?
return JsonUtil.getInt(blobScheduleConfigRoot, "max").orElse(6);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -546,4 +546,11 @@ default boolean isConsensusMigration() {
* @return the consolidation request contract address
*/
Optional<Address> getConsolidationRequestContractAddress();

/**
* The blob schedule is a list of hardfork names and their associated target and max blob values.
*
* @return the blob schedule
*/
BlobScheduleOptions getBlobScheduleOptions();
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions {
private static final String TRANSITIONS_CONFIG_KEY = "transitions";
private static final String DISCOVERY_CONFIG_KEY = "discovery";
private static final String CHECKPOINT_CONFIG_KEY = "checkpoint";
private static final String BLOB_SCHEDULE_CONFIG_KEY = "blobschedule";
private static final String ZERO_BASE_FEE_KEY = "zerobasefee";
private static final String FIXED_BASE_FEE_KEY = "fixedbasefee";
private static final String WITHDRAWAL_REQUEST_CONTRACT_ADDRESS_KEY =
Expand Down Expand Up @@ -199,6 +200,13 @@ public EthashConfigOptions getEthashConfigOptions() {
.orElse(EthashConfigOptions.DEFAULT);
}

@Override
public BlobScheduleOptions getBlobScheduleOptions() {
return JsonUtil.getObjectNode(configRoot, BLOB_SCHEDULE_CONFIG_KEY)
.map(BlobScheduleOptions::new)
.orElse(BlobScheduleOptions.DEFAULT);
}

@Override
public TransitionsConfigOptions getTransitions() {
return transitions;
Expand Down Expand Up @@ -462,6 +470,7 @@ public Optional<Address> getConsolidationRequestContractAddress() {
return inputAddress.map(Address::fromHexString);
}

// TODO SLD - EIP-7840
@Override
public Map<String, Object> asMap() {
final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,11 @@ public Optional<Address> getConsolidationRequestContractAddress() {
return Optional.empty();
}

@Override
public BlobScheduleOptions getBlobScheduleOptions() {
return BlobScheduleOptions.DEFAULT;
}

/**
* Homestead block stub genesis config options.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright contributors to Hyperledger Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.config;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;

public class BlobScheduleOptionsTest {

@Test
public void blobScheduleIsParsed() {
final GenesisConfigFile genesisConfigFile =
GenesisConfigFile.fromResource("/mainnet_with_blob_schedule.json");
final GenesisConfigOptions configOptions = genesisConfigFile.getConfigOptions();

assertThat(configOptions.getBlobScheduleOptions().getCancun().getTarget()).isEqualTo(3);
assertThat(configOptions.getBlobScheduleOptions().getCancun().getMax()).isEqualTo(6);
assertThat(configOptions.getBlobScheduleOptions().getPrague().getTarget()).isEqualTo(6);
assertThat(configOptions.getBlobScheduleOptions().getPrague().getMax()).isEqualTo(9);
assertThat(configOptions.getBlobScheduleOptions().getOsaka().getTarget()).isEqualTo(9);
assertThat(configOptions.getBlobScheduleOptions().getOsaka().getMax()).isEqualTo(12);
}
}
37 changes: 37 additions & 0 deletions config/src/test/resources/mainnet_with_blob_schedule.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"config": {
"chainId": 3151908,
"homesteadBlock": 0,
"eip150Block": 0,
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"berlinBlock": 0,
"londonBlock": 0,
"preMergeForkBlock": 0,
"terminalTotalDifficulty": 0,
"ethash": {},
"shanghaiTime": 0,
"cancunTime": 0,
"blobSchedule": {
"cancun": {
"target": 3,
"max": 6
},
"prague": {
"target": 6,
"max": 9
},
"osaka": {
"target": 9,
"max": 12
}
},
"depositContractAddress": "0x4242424242424242424242424242424242424242",
"pragueTime": 1734106711,
"osakaTime": 1734107095
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
/** The GasLimitCalculator interface defines methods for calculating the gas limit. */
public interface GasLimitCalculator {

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

/**
* Calculates the next gas limit based on the current gas limit, target gas limit, and new block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,36 @@
package org.hyperledger.besu.ethereum.mainnet;

import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
import org.hyperledger.besu.evm.gascalculator.CancunGasCalculator;

public class CancunTargetingGasLimitCalculator extends LondonTargetingGasLimitCalculator {
private static final long MAX_BLOB_GAS_PER_BLOCK = 786432L;

/**
* The constant MAX_BLOB_GAS_PER_BLOCK represents the maximum gas limit for blob data. =
* CancunGasCalculator.BLOB_GAS_PER_BLOB * 6 blobs = 131072 * 6 = 786432 = 0xC0000
*/
private static final int DEFAULT_MAX_BLOBS_PER_BLOCK = 6;

/**
* The maximum gas limit for blob data per block. getBlobGasPerBlob() * 6 blobs = 131072 * 6 =
* 786432 = 0xC0000
*/
private final long maxBlobGasPerBlock;

public CancunTargetingGasLimitCalculator(
final long londonForkBlock, final BaseFeeMarket feeMarket) {
this(londonForkBlock, feeMarket, DEFAULT_MAX_BLOBS_PER_BLOCK);
}

public CancunTargetingGasLimitCalculator(
final long londonForkBlock, final BaseFeeMarket feeMarket, final int maxBlobsPerBlock) {
super(londonForkBlock, feeMarket);
final CancunGasCalculator cancunGasCalculator = new CancunGasCalculator();
this.maxBlobGasPerBlock = cancunGasCalculator.getBlobGasPerBlob() * maxBlobsPerBlock;
}

@Override
public long currentBlobGasLimit() {
return MAX_BLOB_GAS_PER_BLOCK;
return maxBlobGasPerBlock;
}
}
Loading

0 comments on commit 35062a4

Please sign in to comment.