Skip to content

Commit

Permalink
Add baseFeeUpdateFraction to blobSchedule genesis config (hyperledger…
Browse files Browse the repository at this point in the history
…#8128)

* Add baseFeeUpdateFraction to blobSchedule genesis config

Signed-off-by: Daniel Lehrner <[email protected]>

* added genesis file for CodeDelegationTransactionAcceptanceTest

Signed-off-by: Daniel Lehrner <[email protected]>

* remove hard coded baseFeeUpdateFraction from CancunFeeMarket & PragueFeeMarket

Signed-off-by: Daniel Lehrner <[email protected]>

* make FeeMarket constructors package private

Signed-off-by: Daniel Lehrner <[email protected]>

---------

Signed-off-by: Daniel Lehrner <[email protected]>
  • Loading branch information
daniellehrner authored Jan 17, 2025
1 parent 89632d7 commit a98e950
Show file tree
Hide file tree
Showing 28 changed files with 168 additions and 81 deletions.
9 changes: 6 additions & 3 deletions acceptance-tests/tests/src/test/resources/dev/dev_prague.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@
"blobSchedule": {
"cancun": {
"target": 3,
"max": 6
"max": 6,
"baseFeeUpdateFraction": 3338477
},
"prague": {
"target": 6,
"max": 9
"max": 9,
"baseFeeUpdateFraction": 5007716
},
"osaka": {
"target": 9,
"max": 12
"max": 12,
"baseFeeUpdateFraction": 5007716
}
},
"clique": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration;
import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions;
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.LondonFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration;
import org.hyperledger.besu.ethereum.storage.StorageProvider;
import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueStoragePrefixedKeyBlockchainStorage;
Expand Down Expand Up @@ -106,7 +106,7 @@ public class MergeBesuControllerBuilderTest {

BigInteger networkId = BigInteger.ONE;
private final BlockHeaderTestFixture headerGenerator = new BlockHeaderTestFixture();
private final BaseFeeMarket feeMarket = new LondonFeeMarket(0, Optional.of(Wei.of(42)));
private final BaseFeeMarket feeMarket = FeeMarket.london(0, Optional.of(Wei.of(42)));
private final TransactionPoolConfiguration poolConfiguration =
TransactionPoolConfiguration.DEFAULT;
private final ObservableMetricsSystem observableMetricsSystem = new NoOpMetricsSystem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,16 @@ public Map<String, Object> asMap() {
public static class BlobSchedule {
private final int target;
private final int max;
private final int baseFeeUpdateFraction;

/** The constant CANCUN_DEFAULT. */
public static final BlobSchedule CANCUN_DEFAULT = new BlobSchedule(3, 6);
public static final BlobSchedule CANCUN_DEFAULT = new BlobSchedule(3, 6, 3338477);

/** The constant PRAGUE_DEFAULT. */
public static final BlobSchedule PRAGUE_DEFAULT = new BlobSchedule(6, 9);
public static final BlobSchedule PRAGUE_DEFAULT = new BlobSchedule(6, 9, 5007716);

/** The constant OSAKA_DEFAULT. */
public static final BlobSchedule OSAKA_DEFAULT = new BlobSchedule(9, 12);
public static final BlobSchedule OSAKA_DEFAULT = new BlobSchedule(9, 12, 5007716);

/**
* Instantiates a new Blob schedule.
Expand All @@ -100,11 +101,14 @@ public static class BlobSchedule {
public BlobSchedule(final ObjectNode blobScheduleConfigRoot) {
this.target = JsonUtil.getInt(blobScheduleConfigRoot, "target").orElseThrow();
this.max = JsonUtil.getInt(blobScheduleConfigRoot, "max").orElseThrow();
this.baseFeeUpdateFraction =
JsonUtil.getInt(blobScheduleConfigRoot, "basefeeupdatefraction").orElseThrow();
}

private BlobSchedule(final int target, final int max) {
private BlobSchedule(final int target, final int max, final int baseFeeUpdateFraction) {
this.target = target;
this.max = max;
this.baseFeeUpdateFraction = baseFeeUpdateFraction;
}

/**
Expand All @@ -125,13 +129,22 @@ public int getMax() {
return max;
}

/**
* Gets base fee update fraction.
*
* @return the base fee update fraction
*/
public int getBaseFeeUpdateFraction() {
return baseFeeUpdateFraction;
}

/**
* As map.
*
* @return the map
*/
Map<String, Object> asMap() {
return Map.of("target", target, "max", max);
return Map.of("target", target, "max", max, "baseFeeUpdateFraction", baseFeeUpdateFraction);
}
}
}
12 changes: 12 additions & 0 deletions config/src/main/resources/holesky.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@
"terminalTotalDifficulty": 0,
"shanghaiTime": 1696000704,
"cancunTime": 1707305664,
"blobSchedule": {
"cancun": {
"target": 3,
"max": 6,
"baseFeeUpdateFraction": 3338477
},
"prague": {
"target": 6,
"max": 9,
"baseFeeUpdateFraction": 5007716
}
},
"ethash": {},
"discovery": {
"dns": "enrtree://AKA3AM6LPBYEUDMVNU3BSVQJ5AD45Y7YPOHJLEF6W26QOE4VTUDPE@all.holesky.ethdisco.net",
Expand Down
6 changes: 4 additions & 2 deletions config/src/main/resources/mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
"blobSchedule": {
"cancun": {
"target": 3,
"max": 6
"max": 6,
"baseFeeUpdateFraction": 3338477
},
"prague": {
"target": 6,
"max": 9
"max": 9,
"baseFeeUpdateFraction": 5007716
}
},
"ethash": {
Expand Down
12 changes: 12 additions & 0 deletions config/src/main/resources/sepolia.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@
"terminalTotalDifficulty": 17000000000000000,
"shanghaiTime": 1677557088,
"cancunTime": 1706655072,
"blobSchedule": {
"cancun": {
"target": 3,
"max": 6,
"baseFeeUpdateFraction": 3338477
},
"prague": {
"target": 6,
"max": 9,
"baseFeeUpdateFraction": 5007716
}
},
"ethash":{},
"discovery": {
"dns": "enrtree://AKA3AM6LPBYEUDMVNU3BSVQJ5AD45Y7YPOHJLEF6W26QOE4VTUDPE@all.sepolia.ethdisco.net",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ public void blobScheduleIsParsed() {
assertThat(blobScheduleOptions.getCancun()).isNotEmpty();
assertThat(blobScheduleOptions.getCancun().get().getTarget()).isEqualTo(4);
assertThat(blobScheduleOptions.getCancun().get().getMax()).isEqualTo(7);
assertThat(blobScheduleOptions.getCancun().get().getBaseFeeUpdateFraction()).isEqualTo(3338477);
assertThat(blobScheduleOptions.getPrague()).isNotEmpty();
assertThat(blobScheduleOptions.getPrague().get().getTarget()).isEqualTo(7);
assertThat(blobScheduleOptions.getPrague().get().getMax()).isEqualTo(10);
assertThat(blobScheduleOptions.getPrague().get().getBaseFeeUpdateFraction()).isEqualTo(5007716);
assertThat(blobScheduleOptions.getOsaka()).isNotEmpty();
assertThat(blobScheduleOptions.getOsaka().get().getTarget()).isEqualTo(10);
assertThat(blobScheduleOptions.getOsaka().get().getMax()).isEqualTo(13);
assertThat(blobScheduleOptions.getOsaka().get().getBaseFeeUpdateFraction()).isEqualTo(5007716);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,18 @@ void asMapIncludesBlobFeeSchedule() {
+ " \"blobSchedule\": {\n"
+ " \"cancun\": {\n"
+ " \"target\": 1,\n"
+ " \"max\": 2\n"
+ " \"max\": 2,\n"
+ " \"baseFeeUpdateFraction\": 3\n"
+ " },\n"
+ " \"prague\": {\n"
+ " \"target\": 3,\n"
+ " \"max\": 4\n"
+ " \"target\": 4,\n"
+ " \"max\": 5,\n"
+ " \"baseFeeUpdateFraction\": 6\n"
+ " },\n"
+ " \"osaka\": {\n"
+ " \"target\": 4,\n"
+ " \"max\": 5\n"
+ " \"target\": 7,\n"
+ " \"max\": 8,\n"
+ " \"baseFeeUpdateFraction\": 9\n"
+ " }\n"
+ " }\n"
+ " }\n"
Expand All @@ -438,14 +441,14 @@ void asMapIncludesBlobFeeSchedule() {
final Map<String, Object> blobSchedule = (Map<String, Object>) map.get("blobSchedule");
assertThat(blobSchedule).containsOnlyKeys("cancun", "prague", "osaka");
assertThat((Map<String, Object>) blobSchedule.get("cancun"))
.containsOnlyKeys("target", "max")
.containsValues(1, 2);
.containsOnlyKeys("target", "max", "baseFeeUpdateFraction")
.containsValues(1, 2, 3);
assertThat((Map<String, Object>) blobSchedule.get("prague"))
.containsOnlyKeys("target", "max")
.containsValues(3, 4);
.containsOnlyKeys("target", "max", "baseFeeUpdateFraction")
.containsValues(4, 5, 6);
assertThat((Map<String, Object>) blobSchedule.get("osaka"))
.containsOnlyKeys("target", "max")
.containsValues(4, 5);
.containsOnlyKeys("target", "max", "baseFeeUpdateFraction")
.containsValues(7, 8, 9);
}

private GenesisConfigOptions fromConfigOptions(final Map<String, Object> configOptions) {
Expand Down
9 changes: 6 additions & 3 deletions config/src/test/resources/mainnet_with_blob_schedule.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@
"blobSchedule": {
"cancun": {
"target": 4,
"max": 7
"max": 7,
"baseFeeUpdateFraction": 3338477
},
"prague": {
"target": 7,
"max": 10
"max": 10,
"baseFeeUpdateFraction": 5007716
},
"osaka": {
"target": 10,
"max": 13
"max": 13,
"baseFeeUpdateFraction": 5007716
}
},
"depositContractAddress": "0x4242424242424242424242424242424242424242",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
import org.hyperledger.besu.ethereum.eth.transactions.sorter.BaseFeePendingTransactionsSorter;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.LondonFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
import org.hyperledger.besu.ethereum.trie.MerkleTrieException;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.metrics.StubMetricsSystem;
Expand Down Expand Up @@ -158,7 +158,7 @@ public class MergeCoordinatorTest implements MergeGenesisConfigHelper {
private final Address suggestedFeeRecipient = Address.ZERO;
private final BlockHeaderTestFixture headerGenerator = new BlockHeaderTestFixture();
private final BaseFeeMarket feeMarket =
new LondonFeeMarket(0, genesisState.getBlock().getHeader().getBaseFee());
FeeMarket.london(0, genesisState.getBlock().getHeader().getBaseFee());

private final org.hyperledger.besu.metrics.StubMetricsSystem metricsSystem =
new StubMetricsSystem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.LondonFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.testutil.DeterministicEthScheduler;
import org.hyperledger.besu.util.LogConfigurator;
Expand Down Expand Up @@ -81,7 +81,7 @@ public class MergeReorgTest implements MergeGenesisConfigHelper {
private final Address coinbase = genesisAllocations(getPowGenesisConfig()).findFirst().get();
private final BlockHeaderTestFixture headerGenerator = new BlockHeaderTestFixture();
private final BaseFeeMarket feeMarket =
new LondonFeeMarket(0, genesisState.getBlock().getHeader().getBaseFee());
FeeMarket.london(0, genesisState.getBlock().getHeader().getBaseFee());

@BeforeEach
public void setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
import org.hyperledger.besu.ethereum.mainnet.feemarket.CancunFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.LegacyFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.LondonFeeMarket;
import org.hyperledger.besu.evm.log.LogsBloomFilter;

import java.util.HashMap;
Expand Down Expand Up @@ -289,11 +286,11 @@ private void verifyGasPriceLimit(
}

private void mockBaseFeeMarket() {
mockFeeMarket(new LondonFeeMarket(0));
mockFeeMarket(FeeMarket.london(0));
}

private void mockGasPriceMarket() {
mockFeeMarket(new LegacyFeeMarket());
mockFeeMarket(FeeMarket.legacy());
}

private void mockFeeMarket(final FeeMarket feeMarket) {
Expand All @@ -313,7 +310,7 @@ private void mockBlockchain(
final var genesisBlock = createFakeBlock(0, 0, genesisBaseFee);
blocksByNumber.put(0L, genesisBlock);

final var baseFeeMarket = new CancunFeeMarket(0, Optional.empty());
final var baseFeeMarket = FeeMarket.cancun(0, Optional.empty());

var baseFee = genesisBaseFee;
for (long i = 1; i <= chainHeadBlockNumber; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
import org.hyperledger.besu.ethereum.mainnet.blockhash.FrontierBlockHashProcessor;
import org.hyperledger.besu.ethereum.mainnet.feemarket.CancunFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;
import org.hyperledger.besu.evm.gascalculator.CancunGasCalculator;
Expand Down Expand Up @@ -322,7 +321,7 @@ private void mockBlockWithBlobTransaction(final Hash blockHash, final long block
}

private void mockProtocolSpec(final BlockHeader blockHeader) {
FeeMarket feeMarket = new CancunFeeMarket(0, Optional.empty());
FeeMarket feeMarket = FeeMarket.cancun(0, Optional.empty());
ProtocolSpec spec = mock(ProtocolSpec.class);
when(spec.getFeeMarket()).thenReturn(feeMarket);
when(spec.getGasCalculator()).thenReturn(new CancunGasCalculator());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.hyperledger.besu.ethereum.core.MiningConfiguration;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.feemarket.CancunFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
import org.hyperledger.besu.evm.log.LogsBloomFilter;

import java.math.BigInteger;
Expand Down Expand Up @@ -148,7 +148,7 @@ private void mockBlockchain(final long chainHeadBlockNumber, final int txsNum) {
final var genesisBlock = createFakeBlock(0, 0, genesisBaseFee);
blocksByNumber.put(0L, genesisBlock);

final var baseFeeMarket = new CancunFeeMarket(0, Optional.empty());
final var baseFeeMarket = FeeMarket.cancun(0, Optional.empty());

var baseFee = genesisBaseFee;
for (long i = 1; i <= chainHeadBlockNumber; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,13 @@ static ProtocolSpecBuilder cancunDefinition(
final boolean isParallelTxProcessingEnabled,
final MetricsSystem metricsSystem) {
final long londonForkBlockNumber = genesisConfigOptions.getLondonBlockNumber().orElse(0L);

final var cancunBlobSchedule =
genesisConfigOptions
.getBlobScheduleOptions()
.flatMap(BlobScheduleOptions::getCancun)
.orElse(BlobScheduleOptions.BlobSchedule.CANCUN_DEFAULT);

final BaseFeeMarket cancunFeeMarket;
if (genesisConfigOptions.isZeroBaseFee()) {
cancunFeeMarket = FeeMarket.zeroBaseFee(londonForkBlockNumber);
Expand All @@ -686,15 +693,12 @@ static ProtocolSpecBuilder cancunDefinition(
londonForkBlockNumber, miningConfiguration.getMinTransactionGasPrice());
} else {
cancunFeeMarket =
FeeMarket.cancun(londonForkBlockNumber, genesisConfigOptions.getBaseFeePerGas());
FeeMarket.cancun(
londonForkBlockNumber,
genesisConfigOptions.getBaseFeePerGas(),
cancunBlobSchedule.getBaseFeeUpdateFraction());
}

final var cancunBlobSchedule =
genesisConfigOptions
.getBlobScheduleOptions()
.flatMap(BlobScheduleOptions::getCancun)
.orElse(BlobScheduleOptions.BlobSchedule.CANCUN_DEFAULT);

final java.util.function.Supplier<GasCalculator> cancunGasCalcSupplier =
() -> new CancunGasCalculator(cancunBlobSchedule.getTarget());

Expand Down Expand Up @@ -830,7 +834,10 @@ static ProtocolSpecBuilder pragueDefinition(
londonForkBlockNumber, miningConfiguration.getMinTransactionGasPrice());
} else {
pragueFeeMarket =
FeeMarket.prague(londonForkBlockNumber, genesisConfigOptions.getBaseFeePerGas());
FeeMarket.prague(
londonForkBlockNumber,
genesisConfigOptions.getBaseFeePerGas(),
pragueBlobSchedule.getBaseFeeUpdateFraction());
}

return cancunDefinition(
Expand Down
Loading

0 comments on commit a98e950

Please sign in to comment.