Skip to content

Commit

Permalink
Add baseFeeUpdateFraction to blobSchedule genesis config
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Lehrner <[email protected]>
  • Loading branch information
daniellehrner committed Jan 16, 2025
1 parent 1e7f6f6 commit 30ded54
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 41 deletions.
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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,22 @@
public class CancunFeeMarket extends LondonFeeMarket {
private static final Logger LOG = LoggerFactory.getLogger(CancunFeeMarket.class);
protected static final BigInteger BLOB_GAS_PRICE = BigInteger.ONE;
private static final BigInteger BLOB_GAS_PRICE_UPDATE_FRACTION = BigInteger.valueOf(3338477);
private static final long BLOB_GAS_PRICE_UPDATE_FRACTION = 3338477;

protected final BigInteger baseFeeUpdateFraction;

public CancunFeeMarket(
final long londonForkBlockNumber, final Optional<Wei> baseFeePerGasOverride) {
final long londonForkBlockNumber,
final Optional<Wei> baseFeePerGasOverride,
final long baseFeeUpdateFraction) {
super(londonForkBlockNumber, baseFeePerGasOverride);

this.baseFeeUpdateFraction = BigInteger.valueOf(baseFeeUpdateFraction);
}

public CancunFeeMarket(
final long londonForkBlockNumber, final Optional<Wei> baseFeePerGasOverride) {
this(londonForkBlockNumber, baseFeePerGasOverride, BLOB_GAS_PRICE_UPDATE_FRACTION);
}

@Override
Expand All @@ -42,8 +53,7 @@ public boolean implementsDataFee() {
public Wei blobGasPricePerGas(final BlobGas excessBlobGas) {
final var blobGasPrice =
Wei.of(
fakeExponential(
BLOB_GAS_PRICE, excessBlobGas.toBigInteger(), BLOB_GAS_PRICE_UPDATE_FRACTION));
fakeExponential(BLOB_GAS_PRICE, excessBlobGas.toBigInteger(), baseFeeUpdateFraction));
LOG.atTrace()
.setMessage("parentExcessBlobGas: {} blobGasPrice: {}")
.addArgument(excessBlobGas::toShortHexString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,25 @@ static BaseFeeMarket cancun(
return new CancunFeeMarket(londonForkBlockNumber, baseFeePerGasOverride);
}

static BaseFeeMarket cancun(
final long londonForkBlockNumber,
final Optional<Wei> baseFeePerGasOverride,
final long baseFeeUpdateFraction) {
return new CancunFeeMarket(londonForkBlockNumber, baseFeePerGasOverride, baseFeeUpdateFraction);
}

static BaseFeeMarket prague(
final long londonForkBlockNumber, final Optional<Wei> baseFeePerGasOverride) {
return new PragueFeeMarket(londonForkBlockNumber, baseFeePerGasOverride);
}

static BaseFeeMarket prague(
final long londonForkBlockNumber,
final Optional<Wei> baseFeePerGasOverride,
final long baseFeeUpdateFraction) {
return new PragueFeeMarket(londonForkBlockNumber, baseFeePerGasOverride, baseFeeUpdateFraction);
}

static BaseFeeMarket zeroBaseFee(final long londonForkBlockNumber) {
return new ZeroBaseFeeMarket(londonForkBlockNumber);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,32 @@
import org.hyperledger.besu.datatypes.BlobGas;
import org.hyperledger.besu.datatypes.Wei;

import java.math.BigInteger;
import java.util.Optional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PragueFeeMarket extends CancunFeeMarket {
private static final BigInteger BLOB_BASE_FEE_UPDATE_FRACTION_ELECTRA =
BigInteger.valueOf(5007716);
private static final long BLOB_BASE_FEE_UPDATE_FRACTION_ELECTRA = 5007716;
private static final Logger LOG = LoggerFactory.getLogger(PragueFeeMarket.class);

public PragueFeeMarket(
final long londonForkBlockNumber,
final Optional<Wei> baseFeePerGasOverride,
final long baseFeeUpdateFraction) {
super(londonForkBlockNumber, baseFeePerGasOverride, baseFeeUpdateFraction);
}

public PragueFeeMarket(
final long londonForkBlockNumber, final Optional<Wei> baseFeePerGasOverride) {
super(londonForkBlockNumber, baseFeePerGasOverride);
this(londonForkBlockNumber, baseFeePerGasOverride, BLOB_BASE_FEE_UPDATE_FRACTION_ELECTRA);
}

@Override
public Wei blobGasPricePerGas(final BlobGas excessBlobGas) {
final var blobGasPrice =
Wei.of(
fakeExponential(
BLOB_GAS_PRICE,
excessBlobGas.toBigInteger(),
BLOB_BASE_FEE_UPDATE_FRACTION_ELECTRA));
fakeExponential(BLOB_GAS_PRICE, excessBlobGas.toBigInteger(), baseFeeUpdateFraction));
LOG.atTrace()
.setMessage("parentExcessBlobGas: {} blobGasPrice: {}")
.addArgument(excessBlobGas::toShortHexString)
Expand Down

0 comments on commit 30ded54

Please sign in to comment.