Skip to content

Commit

Permalink
Gray glacier hard fork (hyperledger#3962)
Browse files Browse the repository at this point in the history
* preparation for the gray glacier hard fork

Signed-off-by: Daniel Lehrner <daniel.lehrner@consensys.net>
  • Loading branch information
daniellehrner authored Jun 15, 2022
1 parent e1d0a3d commit 4996a87
Show file tree
Hide file tree
Showing 17 changed files with 95 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- \[EXPERIMENTAL\] Add checkpoint sync `--sync-mode="X_CHECKPOINT"` [#3849](https://github.com/hyperledger/besu/pull/3849)
- Support `finalized` and `safe` as tags for the block parameter in RPC APIs [#3950](https://github.com/hyperledger/besu/pull/3950)
- Added verification of payload attributes in ForkchoiceUpdated [#3837](https://github.com/hyperledger/besu/pull/3837)
- Add support for Gray Glacier hardfork [#3961](https://github.com/hyperledger/besu/issues/3961)

### Bug Fixes
- alias engine-rpc-port parameter with the former rpc param name [#3958](https://github.com/hyperledger/besu/pull/3958)
Expand Down
5 changes: 3 additions & 2 deletions besu/src/test/java/org/hyperledger/besu/ForkIdsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ public static Collection<Object[]> parameters() {
new ForkId(Bytes.ofUnsignedInt(0xe029e991L), 12244000L),
new ForkId(Bytes.ofUnsignedInt(0xeb440f6L), 12965000L),
new ForkId(Bytes.ofUnsignedInt(0xb715077dL), 13773000L),
new ForkId(Bytes.ofUnsignedInt(0x20c327fc), 0L),
new ForkId(Bytes.ofUnsignedInt(0x20c327fc), 0L))
new ForkId(Bytes.ofUnsignedInt(0x20c327fcL), 15050000L),
new ForkId(Bytes.ofUnsignedInt(0xf0afd0e3L), 0L),
new ForkId(Bytes.ofUnsignedInt(0xf0afd0e3L), 0L))
},
new Object[] {
NetworkName.MORDOR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ default boolean isConsensusMigration() {

OptionalLong getArrowGlacierBlockNumber();

OptionalLong getGrayGlacierBlockNumber();

OptionalLong getParisBlockNumber();

Optional<Wei> getBaseFeePerGas();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ public OptionalLong getArrowGlacierBlockNumber() {
return getOptionalLong("arrowglacierblock");
}

@Override
public OptionalLong getGrayGlacierBlockNumber() {
return getOptionalLong("grayglacierblock");
}

@Override
public OptionalLong getParisBlockNumber() {
var parisBlock = getOptionalLong("parisblock");
Expand Down Expand Up @@ -441,6 +446,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));
getGrayGlacierBlockNumber().ifPresent(l -> builder.put("grayGlacierBlock", 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 @@ -559,6 +565,7 @@ public List<Long> getForks() {
getBerlinBlockNumber(),
getLondonBlockNumber(),
getArrowGlacierBlockNumber(),
getGrayGlacierBlockNumber(),
getParisBlockNumber(),
getTerminalBlockNumber(),
getEcip1015BlockNumber(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions {
private OptionalLong berlinBlockNumber = OptionalLong.empty();
private OptionalLong londonBlockNumber = OptionalLong.empty();
private OptionalLong arrowGlacierBlockNumber = OptionalLong.empty();
private OptionalLong grayGlacierBlockNumber = OptionalLong.empty();
private OptionalLong parisBlockNumber = OptionalLong.empty();
private OptionalLong terminalBlockNumber = OptionalLong.empty();
private Optional<Hash> terminalBlockHash = Optional.empty();
Expand Down Expand Up @@ -205,6 +206,11 @@ public OptionalLong getArrowGlacierBlockNumber() {
return arrowGlacierBlockNumber;
}

@Override
public OptionalLong getGrayGlacierBlockNumber() {
return grayGlacierBlockNumber;
}

@Override
public OptionalLong getParisBlockNumber() {
return parisBlockNumber;
Expand Down Expand Up @@ -336,6 +342,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));
getGrayGlacierBlockNumber().ifPresent(l -> builder.put("grayGlacierBlock", l));
getParisBlockNumber().ifPresent(l -> builder.put("parisBlock", l));
getTerminalBlockNumber().ifPresent(l -> builder.put("terminalBlockNumber", l));
getTerminalBlockHash().ifPresent(h -> builder.put("terminalBlockHash", h));
Expand Down Expand Up @@ -465,6 +472,11 @@ public StubGenesisConfigOptions arrowGlacierBlock(final long blockNumber) {
return this;
}

public StubGenesisConfigOptions grayGlacierBlock(final long blockNumber) {
grayGlacierBlockNumber = OptionalLong.of(blockNumber);
return this;
}

public StubGenesisConfigOptions parisBlock(final long blockNumber) {
parisBlockNumber = OptionalLong.of(blockNumber);
return this;
Expand Down
1 change: 1 addition & 0 deletions config/src/main/resources/mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"berlinBlock": 12244000,
"londonBlock": 12965000,
"arrowGlacierBlock": 13773000,
"grayGlacierBlock": 15050000,
"ethash": {
},
"discovery": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ public void shouldGetArrowGlacierBlockNumber() {
assertThat(config.getArrowGlacierBlockNumber()).hasValue(1000);
}

@Test
public void shouldGetGrayGlacierBlockNumber() {
final GenesisConfigOptions config = fromConfigOptions(singletonMap("grayGlacierBlock", 4242));
assertThat(config.getGrayGlacierBlockNumber()).hasValue(4242);
}

@Test
// TODO ECIP-1049 change for the actual fork name when known
public void shouldGetECIP1049BlockNumber() {
Expand All @@ -213,6 +219,7 @@ public void shouldNotReturnEmptyOptionalWhenBlockNumberNotSpecified() {
assertThat(config.getBerlinBlockNumber()).isEmpty();
assertThat(config.getLondonBlockNumber()).isEmpty();
assertThat(config.getArrowGlacierBlockNumber()).isEmpty();
assertThat(config.getGrayGlacierBlockNumber()).isEmpty();
assertThat(config.getEcip1049BlockNumber()).isEmpty();
}

Expand Down
3 changes: 2 additions & 1 deletion config/src/test/resources/all_forks.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"berlinBlock": 10,
"londonBlock": 11,
"arrowGlacierBlock": 12,
"parisBlock": 13,
"grayGlacierBlock": 13,
"parisBlock": 14,
"ecip1015Block": 102,
"dieHardBlock": 103,
"gothamBlock": 104,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public abstract class MainnetDifficultyCalculators {
private static final long MUIR_GLACIER_FAKE_BLOCK_OFFSET = 8_999_999L;
private static final long LONDON_FAKE_BLOCK_OFFSET = 9_699_999L;
private static final long ARROW_GLACIER_FAKE_BLOCK_OFFSET = 10_699_999L;
private static final long GRAY_GLACIER_FAKE_BLOCK_OFFSET = 11_399_999L;

private MainnetDifficultyCalculators() {}

Expand Down Expand Up @@ -94,6 +95,11 @@ private MainnetDifficultyCalculators() {}
(time, parent, protocolContext) ->
calculateThawedDifficulty(time, parent, ARROW_GLACIER_FAKE_BLOCK_OFFSET);

// As per https://eips.ethereum.org/EIPS/eip-5133
static DifficultyCalculator GRAY_GLACIER =
(time, parent, protocolContext) ->
calculateThawedDifficulty(time, parent, GRAY_GLACIER_FAKE_BLOCK_OFFSET);

private static BigInteger calculateThawedDifficulty(
final long time, final BlockHeader parent, final long fakeBlockOffset) {
final BigInteger parentDifficulty = difficulty(parent.getDifficulty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ public ProtocolSpecBuilder arrowGlacierDefinition(
evmConfiguration);
}

public ProtocolSpecBuilder grayGlacierDefinition(
final GenesisConfigOptions genesisConfigOptions) {
return MainnetProtocolSpecs.grayGlacierDefinition(
chainId,
contractSizeLimit,
evmStackSize,
isRevertReasonEnabled,
genesisConfigOptions,
quorumCompatibilityMode,
evmConfiguration);
}

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

static ProtocolSpecBuilder grayGlacierDefinition(
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
final OptionalInt configStackSizeLimit,
final boolean enableRevertReason,
final GenesisConfigOptions genesisConfigOptions,
final boolean quorumCompatibilityMode,
final EvmConfiguration evmConfiguration) {
return arrowGlacierDefinition(
chainId,
configContractSizeLimit,
configStackSizeLimit,
enableRevertReason,
genesisConfigOptions,
quorumCompatibilityMode,
evmConfiguration)
.difficultyCalculator(MainnetDifficultyCalculators.GRAY_GLACIER)
.name("GrayGlacier");
}

static ProtocolSpecBuilder parisDefinition(
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ private TreeMap<Long, BuilderMapEntry> buildMilestoneMap(
create(
config.getArrowGlacierBlockNumber(),
specFactory.arrowGlacierDefinition(config)),
create(
config.getGrayGlacierBlockNumber(), specFactory.grayGlacierDefinition(config)),
create(config.getParisBlockNumber(), specFactory.parisDefinition(config)),
// Classic Milestones
create(config.getEcip1015BlockNumber(), specFactory.tangerineWhistleDefinition()),
Expand Down Expand Up @@ -322,6 +324,8 @@ private void validateEthereumForkOrdering() {
lastForkBlock = validateForkOrder("London", config.getLondonBlockNumber(), lastForkBlock);
lastForkBlock =
validateForkOrder("ArrowGlacier", config.getArrowGlacierBlockNumber(), lastForkBlock);
lastForkBlock =
validateForkOrder("GrayGlacier", config.getGrayGlacierBlockNumber(), lastForkBlock);
assert (lastForkBlock >= 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ public void shouldReturnDefaultProtocolSpecsWhenCustomNumbersAreNotUsed() {
Assertions.assertThat(sched.getByBlockNumber(12_244_000L).getName()).isEqualTo("Berlin");
Assertions.assertThat(sched.getByBlockNumber(12_965_000L).getName()).isEqualTo("London");
Assertions.assertThat(sched.getByBlockNumber(13_773_000L).getName()).isEqualTo("ArrowGlacier");
Assertions.assertThat(sched.getByBlockNumber(15_050_000L).getName()).isEqualTo("GrayGlacier");
Assertions.assertThat(sched.getByBlockNumber(Long.MAX_VALUE).getName())
.isEqualTo("ArrowGlacier");
.isEqualTo("GrayGlacier");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static class Forks {
public static final List<Long> MAINNET =
Arrays.asList(
1920000L, 1150000L, 2463000L, 2675000L, 2675000L, 4370000L, 7280000L, 7280000L,
9069000L, 9200000L, 12244000L, 12965000L, 13773000L);
9069000L, 9200000L, 12244000L, 12965000L, 13773000L, 15050000L);
public static final List<Long> ROPSTEN =
Arrays.asList(0L, 0L, 10L, 1700000L, 4230000L, 4939394L, 6485846L, 7117117L);
public static final List<Long> RINKEBY =
Expand All @@ -88,7 +88,8 @@ public static class ForkIds {
new ForkId(Bytes.fromHexString("0xe029e991"), 12244000L), // First Muir Glacier block
new ForkId(Bytes.fromHexString("0x0eb440f6"), 12965000L), // First Berlin block
new ForkId(Bytes.fromHexString("0xb715077d"), 13773000L), // First London block
new ForkId(Bytes.fromHexString("0x20c327fc"), 0L)); // First Arrow Glacier block
new ForkId(Bytes.fromHexString("0x20c327fc"), 15050000L), // First Arrow Glacier block
new ForkId(Bytes.fromHexString("0xf0afd0e3"), 0L)); // First Gray Glacier block
public static final List<ForkId> ROPSTEN =
Arrays.asList(
new ForkId(Bytes.fromHexString("0x30c7ddbc"), 10L),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,23 @@ public static Collection<Object[]> data() {
"Mainnet // First Arrow Glacier block",
Network.MAINNET,
13773000L,
ForkIdTestUtil.wantForkId("0x20c327fc", 0L),
ForkIdTestUtil.wantForkId("0x20c327fc", 15050000L),
Optional.of(ForkIds.MAINNET),
empty()
},
{
"Mainnet // Future Arrow Glacier block",
"Mainnet // First Gray Glacier block",
Network.MAINNET,
15050000L,
ForkIdTestUtil.wantForkId("0xf0afd0e3", 0L),
Optional.of(ForkIds.MAINNET),
empty()
},
{
"Mainnet // Future Gray Glacier block",
Network.MAINNET,
20000000L,
ForkIdTestUtil.wantForkId("0x20c327fc", 0L),
ForkIdTestUtil.wantForkId("0xf0afd0e3", 0L),
Optional.of(ForkIds.MAINNET),
empty()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public static ReferenceTestProtocolSchedules create() {
builder.put("London", createSchedule(new StubGenesisConfigOptions().londonBlock(0)));
builder.put(
"ArrowGlacier", createSchedule(new StubGenesisConfigOptions().arrowGlacierBlock(0)));
builder.put("GrayGlacier", createSchedule(new StubGenesisConfigOptions().grayGlacierBlock(0)));
return new ReferenceTestProtocolSchedules(builder.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ private static String modifyGenesisFile(final String initialGenesis) {
maybeMoveToNumber(params, "berlinForkBlock", config, "berlinBlock");
maybeMoveToNumber(params, "londonForkBlock", config, "londonBlock");
maybeMoveToNumber(params, "arrowGlacierForkBlock", config, "arrowGlacierBlock");
maybeMoveToNumber(params, "grayGlacierForkBlock", config, "grayGlacierBlock");
maybeMoveToNumber(params, "chainID", config, "chainId", 1);

maybeMove(genesis, "author", chainParamsJson, "coinbase");
Expand Down

0 comments on commit 4996a87

Please sign in to comment.