Skip to content

Commit

Permalink
rename premerge fork to paris, keep premerge as an alias (hyperledger…
Browse files Browse the repository at this point in the history
…#3615)

* rename premerge fork to paris, keep premerge as an alias

Signed-off-by: garyschulte <garyschulte@gmail.com>
  • Loading branch information
garyschulte committed May 2, 2022
1 parent c5b9414 commit 21cda64
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ default boolean isConsensusMigration() {

OptionalLong getArrowGlacierBlockNumber();

OptionalLong getPreMergeForkBlockNumber();
OptionalLong getParisBlockNumber();

Optional<Wei> getBaseFeePerGas();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Streams;
import org.apache.tuweni.units.bigints.UInt256;

public class JsonGenesisConfigOptions implements GenesisConfigOptions {
Expand Down Expand Up @@ -273,8 +274,14 @@ public OptionalLong getArrowGlacierBlockNumber() {
}

@Override
public OptionalLong getPreMergeForkBlockNumber() {
return getOptionalLong("premergeforkblock");
public OptionalLong getParisBlockNumber() {
var parisBlock = getOptionalLong("parisblock");
var preMergeAlias = getOptionalLong("premergeforkblock");
if (parisBlock.isPresent() && preMergeAlias.isPresent()) {
throw new RuntimeException(
"Found both paris and preMergeFork blocks. Should have one or the other");
}
return Streams.concat(parisBlock.stream(), preMergeAlias.stream()).findFirst();
}

@Override
Expand Down Expand Up @@ -432,7 +439,7 @@ public Map<String, Object> asMap() {
getBerlinBlockNumber().ifPresent(l -> builder.put("berlinBlock", l));
getLondonBlockNumber().ifPresent(l -> builder.put("londonBlock", l));
getArrowGlacierBlockNumber().ifPresent(l -> builder.put("arrowGlacierBlock", l));
getPreMergeForkBlockNumber().ifPresent(l -> builder.put("preMergeForkBlock", l));
getParisBlockNumber().ifPresent(l -> builder.put("parisBlock", l));
getTerminalBlockNumber().ifPresent(l -> builder.put("terminalBlockNumber", l));
getTerminalBlockHash().ifPresent(h -> builder.put("terminalBlockHash", h.toHexString()));

Expand Down Expand Up @@ -550,7 +557,7 @@ public List<Long> getForks() {
getBerlinBlockNumber(),
getLondonBlockNumber(),
getArrowGlacierBlockNumber(),
getPreMergeForkBlockNumber(),
getParisBlockNumber(),
getTerminalBlockNumber(),
getEcip1015BlockNumber(),
getDieHardBlockNumber(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions {
private OptionalLong berlinBlockNumber = OptionalLong.empty();
private OptionalLong londonBlockNumber = OptionalLong.empty();
private OptionalLong arrowGlacierBlockNumber = OptionalLong.empty();
private OptionalLong preMergeForkBlockNumber = OptionalLong.empty();
private OptionalLong parisBlockNumber = OptionalLong.empty();
private OptionalLong terminalBlockNumber = OptionalLong.empty();
private Optional<Hash> terminalBlockHash = Optional.empty();
private Optional<UInt256> terminalTotalDifficulty = Optional.empty();
Expand Down Expand Up @@ -201,8 +201,8 @@ public OptionalLong getArrowGlacierBlockNumber() {
}

@Override
public OptionalLong getPreMergeForkBlockNumber() {
return preMergeForkBlockNumber;
public OptionalLong getParisBlockNumber() {
return parisBlockNumber;
}

@Override
Expand Down Expand Up @@ -331,7 +331,7 @@ public Map<String, Object> asMap() {
getBerlinBlockNumber().ifPresent(l -> builder.put("berlinBlock", l));
getLondonBlockNumber().ifPresent(l -> builder.put("londonBlock", l));
getArrowGlacierBlockNumber().ifPresent(l -> builder.put("arrowGlacierBlock", l));
getPreMergeForkBlockNumber().ifPresent(l -> builder.put("preMergeForkBlock", l));
getParisBlockNumber().ifPresent(l -> builder.put("parisBlock", l));
getTerminalBlockNumber().ifPresent(l -> builder.put("terminalBlockNumber", l));
getTerminalBlockHash().ifPresent(h -> builder.put("terminalBlockHash", h));
// classic fork blocks
Expand Down Expand Up @@ -460,8 +460,8 @@ public StubGenesisConfigOptions arrowGlacierBlock(final long blockNumber) {
return this;
}

public StubGenesisConfigOptions preMergeForkBlock(final long blockNumber) {
preMergeForkBlockNumber = OptionalLong.of(blockNumber);
public StubGenesisConfigOptions parisBlock(final long blockNumber) {
parisBlockNumber = OptionalLong.of(blockNumber);
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion config/src/main/resources/kiln.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"istanbulBlock": 0,
"berlinBlock": 0,
"londonBlock": 0,
"preMergeForkBlock": 1000,
"parisBlock": 1000,
"terminalTotalDifficulty": 20000000000000,
"discovery": {
"bootnodes": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,37 @@ public void shouldGetEmptyTerminalTotalDifficultyAtGenesis() {
assertThat(EMPTY_CONFIG.getConfigOptions().getTerminalTotalDifficulty()).isNotPresent();
}

@Test
public void shouldFindParisForkAndAlias() {
GenesisConfigFile parisGenesis =
GenesisConfigFile.fromConfig("{\"config\":{\"parisBlock\":10},\"baseFeePerGas\":\"0xa\"}");
assertThat(parisGenesis.getForks()).hasSize(1);
assertThat(parisGenesis.getConfigOptions().getParisBlockNumber()).isPresent();
assertThat(parisGenesis.getConfigOptions().getParisBlockNumber().getAsLong()).isEqualTo(10L);

GenesisConfigFile premergeForkGenesis =
GenesisConfigFile.fromConfig(
"{\"config\":{\"preMergeForkBlock\":11},\"baseFeePerGas\":\"0xa\"}");
assertThat(premergeForkGenesis.getForks()).hasSize(1);
assertThat(premergeForkGenesis.getConfigOptions().getParisBlockNumber()).isPresent();
assertThat(premergeForkGenesis.getConfigOptions().getParisBlockNumber().getAsLong())
.isEqualTo(11L);

// assert fail if both paris and alias are present
var dupeOptions =
GenesisConfigFile.fromConfig(
"{\"config\":{\"parisBlock\":10,\"preMergeForkBlock\":11},\"baseFeePerGas\":\"0xa\"}")
.getConfigOptions();
assertThatThrownBy(() -> dupeOptions.getParisBlockNumber())
.isInstanceOf(RuntimeException.class);

// assert empty if neither are present:
GenesisConfigFile londonGenesis =
GenesisConfigFile.fromConfig("{\"config\":{\"londonBlock\":11},\"baseFeePerGas\":\"0xa\"}");
assertThat(londonGenesis.getForks()).hasSize(1);
assertThat(londonGenesis.getConfigOptions().getParisBlockNumber()).isEmpty();
}

@Test
public void shouldDefaultTimestampToZero() {
assertThat(EMPTY_CONFIG.getTimestamp()).isZero();
Expand Down
2 changes: 1 addition & 1 deletion config/src/test/resources/all_forks.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"berlinBlock": 10,
"londonBlock": 11,
"arrowGlacierBlock": 12,
"preMergeForkBlock": 13,
"parisBlock": 13,
"ecip1015Block": 102,
"dieHardBlock": 103,
"gothamBlock": 104,
Expand Down
2 changes: 1 addition & 1 deletion config/src/test/resources/preMerge.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"chainId": 1337,
"londonBlock": 0,
"phillyBlock": 5,
"preMergeForkBlock": 10,
"parisBlock": 10,
"contractSizeLimit": 2147483647,
"ethash": {
"fixeddifficulty": 100
Expand Down
2 changes: 1 addition & 1 deletion consensus/merge/src/test/resources/posAtGenesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"config": {
"chainId": 1337,
"londonBlock": 0,
"preMergeForkBlock": 0,
"parisBlock": 0,
"terminalTotalDifficulty": 1000,
"contractSizeLimit": 2147483647,
"ethash": {
Expand Down
2 changes: 1 addition & 1 deletion consensus/merge/src/test/resources/powAtGenesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"config": {
"chainId": 1337,
"londonBlock": 0,
"preMergeForkBlock": 0,
"parisBlock": 0,
"terminalTotalDifficulty": 1001,
"contractSizeLimit": 2147483647,
"ethash": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,8 @@ public ProtocolSpecBuilder arrowGlacierDefinition(
evmConfiguration);
}

public ProtocolSpecBuilder preMergeForkDefinition(
final GenesisConfigOptions genesisConfigOptions) {
return MainnetProtocolSpecs.preMergeForkDefinition(
public ProtocolSpecBuilder parisDefinition(final GenesisConfigOptions genesisConfigOptions) {
return MainnetProtocolSpecs.parisDefinition(
chainId,
contractSizeLimit,
evmStackSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ static ProtocolSpecBuilder arrowGlacierDefinition(
.name("ArrowGlacier");
}

static ProtocolSpecBuilder preMergeForkDefinition(
static ProtocolSpecBuilder parisDefinition(
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
final OptionalInt configStackSizeLimit,
Expand All @@ -608,9 +608,8 @@ static ProtocolSpecBuilder preMergeForkDefinition(
evmConfiguration)
.evmBuilder(
(gasCalculator, jdCacheConfig) ->
MainnetEVMs.preMergeFork(
gasCalculator, chainId.orElse(BigInteger.ZERO), evmConfiguration))
.name("PreMergeFork");
MainnetEVMs.paris(gasCalculator, chainId.orElse(BigInteger.ZERO), evmConfiguration))
.name("ParisFork");
}

private static TransactionReceipt frontierTransactionReceiptFactory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,7 @@ private TreeMap<Long, BuilderMapEntry> buildMilestoneMap(
create(
config.getArrowGlacierBlockNumber(),
specFactory.arrowGlacierDefinition(config)),
create(
config.getPreMergeForkBlockNumber(),
specFactory.preMergeForkDefinition(config)),
create(config.getParisBlockNumber(), specFactory.parisDefinition(config)),
// Classic Milestones
create(config.getEcip1015BlockNumber(), specFactory.tangerineWhistleDefinition()),
create(config.getDieHardBlockNumber(), specFactory.dieHardDefinition()),
Expand Down
15 changes: 7 additions & 8 deletions evm/src/main/java/org/hyperledger/besu/evm/MainnetEVMs.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,26 +369,25 @@ public static void registerLondonOperations(
registry.put(new BaseFeeOperation(gasCalculator));
}

public static EVM preMergeFork(
final BigInteger chainId, final EvmConfiguration evmConfiguration) {
return preMergeFork(new LondonGasCalculator(), chainId, evmConfiguration);
public static EVM paris(final BigInteger chainId, final EvmConfiguration evmConfiguration) {
return paris(new LondonGasCalculator(), chainId, evmConfiguration);
}

public static EVM preMergeFork(
public static EVM paris(
final GasCalculator gasCalculator,
final BigInteger chainId,
final EvmConfiguration evmConfiguration) {
return new EVM(preMergeForkOperations(gasCalculator, chainId), gasCalculator, evmConfiguration);
return new EVM(parisOperations(gasCalculator, chainId), gasCalculator, evmConfiguration);
}

public static OperationRegistry preMergeForkOperations(
public static OperationRegistry parisOperations(
final GasCalculator gasCalculator, final BigInteger chainId) {
OperationRegistry operationRegistry = new OperationRegistry();
registerPreMergeForkOperations(operationRegistry, gasCalculator, chainId);
registerParisOperations(operationRegistry, gasCalculator, chainId);
return operationRegistry;
}

public static void registerPreMergeForkOperations(
public static void registerParisOperations(
final OperationRegistry registry,
final GasCalculator gasCalculator,
final BigInteger chainID) {
Expand Down

0 comments on commit 21cda64

Please sign in to comment.