Skip to content

Commit

Permalink
Reuse HardforkId in EvmSpecVersion (hyperledger#7448)
Browse files Browse the repository at this point in the history
* Reuse HardforkId in EvmSpecVersion

Move the HardforkId into datatypes and re-use the data in
EvmSpecVersion, keeping evm specific details in the evm and merging the
rest into datatypes.

Signed-off-by: Danno Ferrin <danno@numisight.com>

* Update evm/src/main/java/org/hyperledger/besu/evm/EvmSpecVersion.java

Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: Danno Ferrin <danno.ferrin@shemnon.com>

---------

Signed-off-by: Danno Ferrin <danno@numisight.com>
Signed-off-by: Danno Ferrin <danno.ferrin@shemnon.com>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
  • Loading branch information
shemnon and macfarla authored Aug 16, 2024
1 parent 35faf06 commit 5133595
Show file tree
Hide file tree
Showing 20 changed files with 285 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
package org.hyperledger.besu.consensus.merge;

import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.datatypes.HardforkId;
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.Difficulty;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.PermissionTransactionFilter;
import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader;
import org.hyperledger.besu.ethereum.mainnet.HardforkId;
import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
Expand Down
164 changes: 164 additions & 0 deletions datatypes/src/main/java/org/hyperledger/besu/datatypes/HardforkId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*
* 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.datatypes;

/** Description and metadata for a hard fork */
public interface HardforkId {

/**
* The name of the hard fork.
*
* @return the name for the fork
*/
String name();

/**
* Has the fork been finalized? i.e., could the definition change in future versions of Besu?
*
* @return true if the specification is finalized.
*/
boolean finalized();

/**
* A brief description of the hard fork, suitable for human consumption
*
* @return the description of the fork.
*/
String description();

/** List of all Ethereum Mainnet hardforks, including future and developmental forks. */
enum MainnetHardforkId implements HardforkId {
/** Frontier fork. */
FRONTIER(true, "Frontier"),
/** Homestead fork. */
HOMESTEAD(true, "Homestead"),
/** DAO Fork fork. */
DAO_FORK(true, "DAO Fork"),
/** Tangerine Whistle fork. */
TANGERINE_WHISTLE(true, "Tangerine Whistle"),
/** Spurious Dragon fork. */
SPURIOUS_DRAGON(true, "Spurious Dragon"),
/** Byzantium fork. */
BYZANTIUM(true, "Byzantium"),
/** Constantinople fork. */
CONSTANTINOPLE(true, "Constantinople"),
/** Petersburg fork. */
PETERSBURG(true, "Petersburg"),
/** Istanbul fork. */
ISTANBUL(true, "Istanbul"),
/** Muir Glacier fork. */
MUIR_GLACIER(true, "Muir Glacier"),
/** Berlin fork. */
BERLIN(true, "Berlin"),
/** London fork. */
LONDON(true, "London"),
/** Arrow Glacier fork. */
ARROW_GLACIER(true, "Arrow Glacier"),
/** Gray Glacier fork. */
GRAY_GLACIER(true, "Gray Glacier"),
/** Paris fork. */
PARIS(true, "Paris"),
/** Shanghai fork. */
SHANGHAI(true, "Shanghai"),
/** Cancun fork. */
CANCUN(true, "Cancun"),
/** Cancun + EOF fork. */
CANCUN_EOF(false, "Cancun + EOF"),
/** Prague fork. */
PRAGUE(false, "Prague"),
/** Prague + EOF fork. */
PRAGUE_EOF(false, "Prague + EOF"),
/** Osaka fork. */
OSAKA(false, "Osaka"),
/** Amsterdam fork. */
AMSTERDAM(false, "Amsterdam"),
/** Bogota fork. */
BOGOTA(false, "Bogota"),
/** Polis fork. (from the greek form of an earlier incarnation of the city of Istanbul. */
POLIS(false, "Polis"),
/** Bangkok fork. */
BANGKOK(false, "Bangkok"),
/** Development fork, for accepted and unscheduled EIPs. */
FUTURE_EIPS(false, "Development, for accepted and unscheduled EIPs"),
/** Developmental fork, for experimental EIPs. */
EXPERIMENTAL_EIPS(false, "Developmental, for experimental EIPs");

final boolean finalized;
final String description;

MainnetHardforkId(final boolean finalized, final String description) {
this.finalized = finalized;
this.description = description;
}

@Override
public boolean finalized() {
return finalized;
}

@Override
public String description() {
return description;
}
}

/** List of all Ethereum Classic hard forks. */
enum ClassicHardforkId implements HardforkId {
/** Frontier fork. */
FRONTIER(true, "Frontier"),
/** Homestead fork. */
HOMESTEAD(true, "Homestead"),
/** Classic Tangerine Whistle fork. */
CLASSIC_TANGERINE_WHISTLE(true, "Classic Tangerine Whistle"),
/** Die Hard fork. */
DIE_HARD(true, "Die Hard"),
/** Gotham fork. */
GOTHAM(true, "Gotham"),
/** Defuse Difficulty Bomb fork. */
DEFUSE_DIFFICULTY_BOMB(true, "Defuse Difficulty Bomb"),
/** Atlantis fork. */
ATLANTIS(true, "Atlantis"),
/** Agharta fork. */
AGHARTA(true, "Agharta"),
/** Phoenix fork. */
PHOENIX(true, "Phoenix"),
/** Thanos fork. */
THANOS(true, "Thanos"),
/** Magneto fork. */
MAGNETO(true, "Magneto"),
/** Mystique fork. */
MYSTIQUE(true, "Mystique"),
/** Spiral fork. */
SPIRAL(true, "Spiral");

final boolean finalized;
final String description;

ClassicHardforkId(final boolean finalized, final String description) {
this.finalized = finalized;
this.description = description;
}

@Override
public boolean finalized() {
return finalized;
}

@Override
public String description() {
return description;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine;

import static java.util.stream.Collectors.toList;
import static org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId.CANCUN;
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.INVALID;
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.SYNCING;
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.VALID;
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine.WithdrawalsValidatorProvider.getWithdrawalsValidator;
import static org.hyperledger.besu.ethereum.mainnet.HardforkId.MainnetHardforkId.CANCUN;

import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator;
import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator.ForkchoiceResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine;

import static org.hyperledger.besu.ethereum.mainnet.HardforkId.MainnetHardforkId.CANCUN;
import static org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId.CANCUN;

import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator;
import org.hyperledger.besu.ethereum.ProtocolContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine;

import static org.hyperledger.besu.ethereum.mainnet.HardforkId.MainnetHardforkId.CANCUN;
import static org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId.CANCUN;

import org.hyperledger.besu.consensus.merge.PayloadWrapper;
import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine;

import static org.hyperledger.besu.ethereum.mainnet.HardforkId.MainnetHardforkId.CANCUN;
import static org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId.CANCUN;

import org.hyperledger.besu.consensus.merge.PayloadWrapper;
import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine;

import static org.hyperledger.besu.ethereum.mainnet.HardforkId.MainnetHardforkId.PRAGUE;
import static org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId.PRAGUE;

import org.hyperledger.besu.consensus.merge.PayloadWrapper;
import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine;

import static org.hyperledger.besu.ethereum.mainnet.HardforkId.MainnetHardforkId.CANCUN;
import static org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId.CANCUN;

import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator;
import org.hyperledger.besu.datatypes.VersionedHash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine;

import static org.hyperledger.besu.ethereum.mainnet.HardforkId.MainnetHardforkId.CANCUN;
import static org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId.CANCUN;

import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator;
import org.hyperledger.besu.ethereum.ProtocolContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine;

import static org.hyperledger.besu.ethereum.mainnet.HardforkId.MainnetHardforkId.PRAGUE;
import static org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId.PRAGUE;

import org.hyperledger.besu.consensus.merge.blockcreation.MergeMiningCoordinator;
import org.hyperledger.besu.ethereum.ProtocolContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine;

import org.hyperledger.besu.datatypes.HardforkId;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
import org.hyperledger.besu.ethereum.mainnet.HardforkId;
import org.hyperledger.besu.ethereum.mainnet.ValidationResult;

import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

import static java.util.Collections.emptyList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId.CANCUN;
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.INVALID;
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.SYNCING;
import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.ExecutionEngineJsonRpcMethod.EngineStatus.VALID;
import static org.hyperledger.besu.ethereum.mainnet.HardforkId.MainnetHardforkId.CANCUN;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.mock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine;

import static org.hyperledger.besu.ethereum.mainnet.HardforkId.MainnetHardforkId.CANCUN;
import static org.hyperledger.besu.ethereum.mainnet.HardforkId.MainnetHardforkId.EXPERIMENTAL_EIPS;
import static org.hyperledger.besu.ethereum.mainnet.HardforkId.MainnetHardforkId.LONDON;
import static org.hyperledger.besu.ethereum.mainnet.HardforkId.MainnetHardforkId.PARIS;
import static org.hyperledger.besu.ethereum.mainnet.HardforkId.MainnetHardforkId.PRAGUE;
import static org.hyperledger.besu.ethereum.mainnet.HardforkId.MainnetHardforkId.SHANGHAI;
import static org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId.CANCUN;
import static org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId.EXPERIMENTAL_EIPS;
import static org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId.LONDON;
import static org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId.PARIS;
import static org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId.PRAGUE;
import static org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId.SHANGHAI;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import static com.google.common.base.Preconditions.checkArgument;

import org.hyperledger.besu.datatypes.HardforkId;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.PermissionTransactionFilter;
import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.ethereum.mainnet;

import org.hyperledger.besu.datatypes.HardforkId;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder;
import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.hyperledger.besu.ethereum.mainnet;

import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.datatypes.HardforkId;
import org.hyperledger.besu.ethereum.chain.BadBlockManager;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
Expand Down
Loading

0 comments on commit 5133595

Please sign in to comment.