diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java index f24e11bd8b..e733cc800e 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java @@ -15,6 +15,7 @@ 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; @@ -22,7 +23,6 @@ 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; diff --git a/datatypes/src/main/java/org/hyperledger/besu/datatypes/HardforkId.java b/datatypes/src/main/java/org/hyperledger/besu/datatypes/HardforkId.java new file mode 100644 index 0000000000..73eaddb7ca --- /dev/null +++ b/datatypes/src/main/java/org/hyperledger/besu/datatypes/HardforkId.java @@ -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; + } + } +} diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java index f958b58444..df169560f5 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdated.java @@ -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; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV3.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV3.java index 414d4625b2..c06b119328 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV3.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineForkchoiceUpdatedV3.java @@ -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; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV2.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV2.java index 1732585f16..ce9cdcbbb3 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV2.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV2.java @@ -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; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV3.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV3.java index 555afb50b9..f0b026ef45 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV3.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV3.java @@ -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; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV4.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV4.java index f67a2743ea..ba42aec2ed 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV4.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineGetPayloadV4.java @@ -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; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2.java index fa15891750..acb177c3e0 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV2.java @@ -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; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3.java index 0277d6990e..393687743e 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV3.java @@ -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; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV4.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV4.java index a767c72345..2465cdd813 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV4.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/EngineNewPayloadV4.java @@ -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; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/ForkSupportHelper.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/ForkSupportHelper.java index 0059f3d61b..57b8f549c9 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/ForkSupportHelper.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/ForkSupportHelper.java @@ -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; diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdatedTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdatedTest.java index d2fb3c3741..5496224e25 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdatedTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractEngineForkchoiceUpdatedTest.java @@ -16,10 +16,10 @@ package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.engine; 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; diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractScheduledApiTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractScheduledApiTest.java index bfe23e07e7..46fe7d3b6c 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractScheduledApiTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/engine/AbstractScheduledApiTest.java @@ -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; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/DefaultProtocolSchedule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/DefaultProtocolSchedule.java index d6d3cc0a55..4c67466b9b 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/DefaultProtocolSchedule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/DefaultProtocolSchedule.java @@ -16,6 +16,7 @@ package org.hyperledger.besu.ethereum.mainnet; 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; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/HardforkId.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/HardforkId.java deleted file mode 100644 index 6c764a4209..0000000000 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/HardforkId.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.ethereum.mainnet; - -public interface HardforkId { - - String name(); - - enum MainnetHardforkId implements HardforkId { - FRONTIER, - HOMESTEAD, - DAO_FORK, - TANGERINE_WHISTLE, - SPURIOUS_DRAGON, - BYZANTIUM, - CONSTANTINOPLE, - PETERSBURG, - ISTANBUL, - MUIR_GLACIER, - BERLIN, - LONDON, - ARROW_GLACIER, - GRAY_GLACIER, - PARIS, - SHANGHAI, - CANCUN, - CANCUN_EOF, - PRAGUE, - PRAGUE_EOF, - FUTURE_EIPS, - EXPERIMENTAL_EIPS - } - - enum ClassicHardforkId implements HardforkId { - FRONTIER, - HOMESTEAD, - CLASSIC_TANGERINE_WHISTLE, - DIE_HARD, - GOTHAM, - DEFUSE_DIFFICULTY_BOMB, - ATLANTIS, - AGHARTA, - PHOENIX, - THANOS, - MAGNETO, - MYSTIQUE, - SPIRAL - } -} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSchedule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSchedule.java index 88448a8b54..f97d8f27ea 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSchedule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSchedule.java @@ -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; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java index fb8abbe1b6..beac906be5 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java @@ -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; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilderTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilderTest.java index a1f3d64797..ad261abf47 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilderTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilderTest.java @@ -16,11 +16,11 @@ package org.hyperledger.besu.ethereum.mainnet; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.hyperledger.besu.ethereum.mainnet.HardforkId.MainnetHardforkId.BERLIN; -import static org.hyperledger.besu.ethereum.mainnet.HardforkId.MainnetHardforkId.CANCUN; -import static org.hyperledger.besu.ethereum.mainnet.HardforkId.MainnetHardforkId.LONDON; -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.BERLIN; +import static org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId.CANCUN; +import static org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId.LONDON; +import static org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId.PRAGUE; +import static org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId.SHANGHAI; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java index 5dfb12f1d6..d6c5afdc4a 100644 --- a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java +++ b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java @@ -32,10 +32,10 @@ import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import java.math.BigInteger; import java.util.Arrays; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.function.Function; - -import com.google.common.collect.ImmutableMap; +import java.util.stream.Collectors; public class ReferenceTestProtocolSchedules { @@ -49,57 +49,67 @@ public class ReferenceTestProtocolSchedules { } public static ReferenceTestProtocolSchedules create(final StubGenesisConfigOptions genesisStub) { - final ImmutableMap.Builder builder = ImmutableMap.builder(); - builder.put("Frontier", createSchedule(genesisStub.clone())); - builder.put("FrontierToHomesteadAt5", createSchedule(genesisStub.clone().homesteadBlock(5))); - builder.put("Homestead", createSchedule(genesisStub.clone().homesteadBlock(0))); - builder.put( - "HomesteadToEIP150At5", - createSchedule(genesisStub.clone().homesteadBlock(0).eip150Block(5))); - builder.put( - "HomesteadToDaoAt5", createSchedule(genesisStub.clone().homesteadBlock(0).daoForkBlock(5))); - builder.put("EIP150", createSchedule(genesisStub.clone().eip150Block(0))); - builder.put("EIP158", createSchedule(genesisStub.clone().eip158Block(0))); - builder.put( - "EIP158ToByzantiumAt5", - createSchedule(genesisStub.clone().eip158Block(0).byzantiumBlock(5))); - builder.put("Byzantium", createSchedule(genesisStub.clone().byzantiumBlock(0))); - builder.put("Constantinople", createSchedule(genesisStub.clone().constantinopleBlock(0))); - builder.put("ConstantinopleFix", createSchedule(genesisStub.clone().petersburgBlock(0))); - builder.put("Petersburg", createSchedule(genesisStub.clone().petersburgBlock(0))); - builder.put("Istanbul", createSchedule(genesisStub.clone().istanbulBlock(0))); - builder.put("MuirGlacier", createSchedule(genesisStub.clone().muirGlacierBlock(0))); - builder.put("Berlin", createSchedule(genesisStub.clone().berlinBlock(0))); - // the following schedules activate EIP-1559, but may have non-default if (genesisStub.getBaseFeePerGas().isEmpty()) { genesisStub.baseFeePerGas(0x0a); } - builder.put("London", createSchedule(genesisStub.clone().londonBlock(0))); - builder.put("ArrowGlacier", createSchedule(genesisStub.clone().arrowGlacierBlock(0))); - builder.put("GrayGlacier", createSchedule(genesisStub.clone().grayGlacierBlock(0))); - builder.put("Merge", createSchedule(genesisStub.clone().mergeNetSplitBlock(0))); - builder.put("Paris", createSchedule(genesisStub.clone().mergeNetSplitBlock(0))); - builder.put("Shanghai", createSchedule(genesisStub.clone().shanghaiTime(0))); - builder.put( - "ShanghaiToCancunAtTime15k", - createSchedule(genesisStub.clone().shanghaiTime(0).cancunTime(15000))); - builder.put("Cancun", createSchedule(genesisStub.clone().cancunTime(0))); - builder.put("CancunEOF", createSchedule(genesisStub.clone().cancunEOFTime(0))); // also load KZG file for mainnet KZGPointEvalPrecompiledContract.init(); - builder.put( - "CancunToPragueAtTime15k", - createSchedule(genesisStub.clone().cancunTime(0).pragueTime(15000))); - builder.put("Prague", createSchedule(genesisStub.clone().pragueEOFTime(0))); - builder.put("Osaka", createSchedule(genesisStub.clone().futureEipsTime(0))); - builder.put("Amsterdam", createSchedule(genesisStub.clone().futureEipsTime(0))); - builder.put("Bogota", createSchedule(genesisStub.clone().futureEipsTime(0))); - builder.put("Polis", createSchedule(genesisStub.clone().futureEipsTime(0))); - builder.put("Bangkok", createSchedule(genesisStub.clone().futureEipsTime(0))); - builder.put("Future_EIPs", createSchedule(genesisStub.clone().futureEipsTime(0))); - builder.put("Experimental_EIPs", createSchedule(genesisStub.clone().experimentalEipsTime(0))); - return new ReferenceTestProtocolSchedules(builder.build()); + return new ReferenceTestProtocolSchedules( + Map.ofEntries( + Map.entry("Frontier", createSchedule(genesisStub.clone())), + Map.entry( + "FrontierToHomesteadAt5", + createSchedule(genesisStub.clone().homesteadBlock(5))), + Map.entry("Homestead", createSchedule(genesisStub.clone().homesteadBlock(0))), + Map.entry( + "HomesteadToEIP150At5", + createSchedule(genesisStub.clone().homesteadBlock(0).eip150Block(5))), + Map.entry( + "HomesteadToDaoAt5", + createSchedule(genesisStub.clone().homesteadBlock(0).daoForkBlock(5))), + Map.entry("EIP150", createSchedule(genesisStub.clone().eip150Block(0))), + Map.entry("EIP158", createSchedule(genesisStub.clone().eip158Block(0))), + Map.entry( + "EIP158ToByzantiumAt5", + createSchedule(genesisStub.clone().eip158Block(0).byzantiumBlock(5))), + Map.entry("Byzantium", createSchedule(genesisStub.clone().byzantiumBlock(0))), + Map.entry( + "Constantinople", createSchedule(genesisStub.clone().constantinopleBlock(0))), + Map.entry( + "ConstantinopleFix", createSchedule(genesisStub.clone().petersburgBlock(0))), + Map.entry("Petersburg", createSchedule(genesisStub.clone().petersburgBlock(0))), + Map.entry("Istanbul", createSchedule(genesisStub.clone().istanbulBlock(0))), + Map.entry("MuirGlacier", createSchedule(genesisStub.clone().muirGlacierBlock(0))), + Map.entry("Berlin", createSchedule(genesisStub.clone().berlinBlock(0))), + Map.entry("London", createSchedule(genesisStub.clone().londonBlock(0))), + Map.entry("ArrowGlacier", createSchedule(genesisStub.clone().arrowGlacierBlock(0))), + Map.entry("GrayGlacier", createSchedule(genesisStub.clone().grayGlacierBlock(0))), + Map.entry("Merge", createSchedule(genesisStub.clone().mergeNetSplitBlock(0))), + Map.entry("Paris", createSchedule(genesisStub.clone().mergeNetSplitBlock(0))), + Map.entry("Shanghai", createSchedule(genesisStub.clone().shanghaiTime(0))), + Map.entry( + "ShanghaiToCancunAtTime15k", + createSchedule(genesisStub.clone().shanghaiTime(0).cancunTime(15000))), + Map.entry("Cancun", createSchedule(genesisStub.clone().cancunTime(0))), + Map.entry("CancunEOF", createSchedule(genesisStub.clone().cancunEOFTime(0))), + Map.entry( + "CancunToPragueAtTime15k", + createSchedule(genesisStub.clone().cancunTime(0).pragueTime(15000))), + Map.entry("Prague", createSchedule(genesisStub.clone().pragueEOFTime(0))), + Map.entry("Osaka", createSchedule(genesisStub.clone().futureEipsTime(0))), + Map.entry("Amsterdam", createSchedule(genesisStub.clone().futureEipsTime(0))), + Map.entry("Bogota", createSchedule(genesisStub.clone().futureEipsTime(0))), + Map.entry("Polis", createSchedule(genesisStub.clone().futureEipsTime(0))), + Map.entry("Bangkok", createSchedule(genesisStub.clone().futureEipsTime(0))), + Map.entry("Future_EIPs", createSchedule(genesisStub.clone().futureEipsTime(0))), + Map.entry( + "Experimental_EIPs", + createSchedule(genesisStub.clone().experimentalEipsTime(0)))) + .entrySet() + .stream() + .map(e -> Map.entry(e.getKey().toLowerCase(Locale.ROOT), e.getValue())) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); } private final Map schedules; @@ -109,7 +119,7 @@ public class ReferenceTestProtocolSchedules { } public ProtocolSchedule getByName(final String name) { - return schedules.get(name); + return schedules.get(name.toLowerCase(Locale.ROOT)); } public ProtocolSpec geSpecByName(final String name) { diff --git a/evm/src/main/java/org/hyperledger/besu/evm/EvmSpecVersion.java b/evm/src/main/java/org/hyperledger/besu/evm/EvmSpecVersion.java index 5368a7fd74..7d4344c6bc 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/EvmSpecVersion.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/EvmSpecVersion.java @@ -14,6 +14,9 @@ */ package org.hyperledger.besu.evm; +import org.hyperledger.besu.datatypes.HardforkId; +import org.hyperledger.besu.datatypes.HardforkId.MainnetHardforkId; + import java.util.Comparator; import java.util.stream.Stream; @@ -23,65 +26,56 @@ import org.slf4j.LoggerFactory; /** The enum Evm spec version. */ public enum EvmSpecVersion { /** Frontier evm spec version. */ - FRONTIER(Integer.MAX_VALUE, Integer.MAX_VALUE, 0, true, "Frontier", "Finalized"), + FRONTIER(MainnetHardforkId.FRONTIER, Integer.MAX_VALUE, Integer.MAX_VALUE, 0), /** Homestead evm spec version. */ - HOMESTEAD(Integer.MAX_VALUE, Integer.MAX_VALUE, 0, true, "Homestead", "Finalized"), + HOMESTEAD(MainnetHardforkId.HOMESTEAD, Integer.MAX_VALUE, Integer.MAX_VALUE, 0), /** Tangerine Whistle evm spec version. */ - TANGERINE_WHISTLE( - Integer.MAX_VALUE, Integer.MAX_VALUE, 0, true, "Tangerine Whistle", "Finalized"), + TANGERINE_WHISTLE(MainnetHardforkId.TANGERINE_WHISTLE, Integer.MAX_VALUE, Integer.MAX_VALUE, 0), /** Spurious Dragon evm spec version. */ - SPURIOUS_DRAGON(0x6000, Integer.MAX_VALUE, 0, true, "Spuruous Dragon", "Finalized"), + SPURIOUS_DRAGON(MainnetHardforkId.SPURIOUS_DRAGON, 0x6000, Integer.MAX_VALUE, 0), /** Byzantium evm spec version. */ - BYZANTIUM(0x6000, Integer.MAX_VALUE, 0, true, "Byzantium", "Finalized"), + BYZANTIUM(MainnetHardforkId.BYZANTIUM, 0x6000, Integer.MAX_VALUE, 0), /** Constantinople evm spec version. */ - CONSTANTINOPLE(0x6000, Integer.MAX_VALUE, 0, true, "Constantinople", "Did not reach Mainnet"), + CONSTANTINOPLE(MainnetHardforkId.CONSTANTINOPLE, 0x6000, Integer.MAX_VALUE, 0), /** Petersburg / ConstantinopleFix evm spec version. */ - PETERSBURG( - 0x6000, - Integer.MAX_VALUE, - 0, - true, - "ConstantinopleFix", - "Finalized (also called Petersburg)"), + PETERSBURG(MainnetHardforkId.PETERSBURG, 0x6000, Integer.MAX_VALUE, 0), /** Istanbul evm spec version. */ - ISTANBUL(0x6000, Integer.MAX_VALUE, 0, true, "Istanbul", "Finalized"), + ISTANBUL(MainnetHardforkId.ISTANBUL, 0x6000, Integer.MAX_VALUE, 0), /** Berlin evm spec version */ - BERLIN(0x6000, Integer.MAX_VALUE, 0, true, "Berlin", "Finalized"), + BERLIN(MainnetHardforkId.BERLIN, 0x6000, Integer.MAX_VALUE, 0), /** London evm spec version. */ - LONDON(0x6000, Integer.MAX_VALUE, 0, true, "London", "Finalized"), + LONDON(MainnetHardforkId.LONDON, 0x6000, Integer.MAX_VALUE, 0), /** Paris evm spec version. */ - PARIS(0x6000, Integer.MAX_VALUE, 0, true, "Merge", "Finalized (also called Paris)"), + PARIS(MainnetHardforkId.PARIS, 0x6000, Integer.MAX_VALUE, 0), /** Shanghai evm spec version. */ - SHANGHAI(0x6000, 0xc000, 0, true, "Shanghai", "Finalized"), + SHANGHAI(MainnetHardforkId.SHANGHAI, 0x6000, 0xc000, 0), /** Cancun evm spec version. */ - CANCUN(0x6000, 0xc000, 0, true, "Cancun", "Finalized"), + CANCUN(MainnetHardforkId.CANCUN, 0x6000, 0xc000, 0), /** Cancun evm spec version. */ - CANCUN_EOF(0x6000, 0xc000, 1, false, "CancunEOF", "For Testing"), + CANCUN_EOF(MainnetHardforkId.CANCUN_EOF, 0x6000, 0xc000, 1), /** Prague evm spec version. */ - PRAGUE(0x6000, 0xc000, 0, false, "Prague", "In Development"), + PRAGUE(MainnetHardforkId.PRAGUE, 0x6000, 0xc000, 0), /** PragueEOF evm spec version. */ - PRAGUE_EOF(0x6000, 0xc000, 1, false, "PragueEOF", "Prague + EOF. In Development"), + PRAGUE_EOF(MainnetHardforkId.PRAGUE_EOF, 0x6000, 0xc000, 1), /** Osaka evm spec version. */ - OSAKA(0x6000, 0xc000, 1, false, "Osaka", "Placeholder"), + OSAKA(MainnetHardforkId.OSAKA, 0x6000, 0xc000, 1), /** Amsterdam evm spec version. */ - AMSTERDAM(0x6000, 0xc000, 1, false, "Amsterdam", "Placeholder"), + AMSTERDAM(MainnetHardforkId.AMSTERDAM, 0x6000, 0xc000, 1), /** Bogota evm spec version. */ - BOGOTA(0x6000, 0xc000, 1, false, "Bogota", "Placeholder"), + BOGOTA(MainnetHardforkId.BOGOTA, 0x6000, 0xc000, 1), /** Polis evm spec version. */ - POLIS(0x6000, 0xc000, 1, false, "Polis", "Placeholder"), - /** Bogota evm spec version. */ - BANGKOK(0x6000, 0xc000, 1, false, "Bangkok", "Placeholder"), + POLIS(MainnetHardforkId.POLIS, 0x6000, 0xc000, 1), + /** Bangkok evm spec version. */ + BANGKOK(MainnetHardforkId.BANGKOK, 0x6000, 0xc000, 1), /** Development fork for unscheduled EIPs */ - FUTURE_EIPS( - 0x6000, 0xc000, 1, false, "Future_EIPs", "Development, for accepted and unscheduled EIPs"), - /** Development fork for EIPs not accepted to Mainnet */ - EXPERIMENTAL_EIPS( - 0x6000, 0xc000, 1, false, "Experimental_EIPs", "Development, for experimental EIPs"); + FUTURE_EIPS(MainnetHardforkId.FUTURE_EIPS, 0x6000, 0xc000, 1), + /** Development fork for EIPs that are not yet accepted to Mainnet */ + EXPERIMENTAL_EIPS(MainnetHardforkId.EXPERIMENTAL_EIPS, 0x6000, 0xc000, 1); private static final Logger LOGGER = LoggerFactory.getLogger(EvmSpecVersion.class); - /** The Spec finalized. */ - final boolean specFinalized; + /** What hardfork did this VM version first show up in? */ + final HardforkId initialHardfork; /** The Max eof version. */ final int maxEofVersion; @@ -92,28 +86,18 @@ public enum EvmSpecVersion { /** Maximum size of initcode */ final int maxInitcodeSize; - /** Public name matching execution-spec-tests name */ - final String name; - - /** A brief description of the state of the fork */ - final String description; - /** The Version warned. */ boolean versionWarned = false; EvmSpecVersion( + final HardforkId initialHarfork, final int maxCodeSize, final int maxInitcodeSize, - final int maxEofVersion, - final boolean specFinalized, - final String name, - final String description) { + final int maxEofVersion) { + this.initialHardfork = initialHarfork; this.maxEofVersion = maxEofVersion; this.maxCodeSize = maxCodeSize; this.maxInitcodeSize = maxInitcodeSize; - this.specFinalized = specFinalized; - this.name = name; - this.description = description; } /** @@ -125,7 +109,7 @@ public enum EvmSpecVersion { public static EvmSpecVersion defaultVersion() { EvmSpecVersion answer = null; for (EvmSpecVersion version : EvmSpecVersion.values()) { - if (version.specFinalized) { + if (version.initialHardfork.finalized()) { answer = version; } } @@ -165,7 +149,7 @@ public enum EvmSpecVersion { * @return name of the fork */ public String getName() { - return name; + return initialHardfork.name(); } /** @@ -174,7 +158,7 @@ public enum EvmSpecVersion { * @return description */ public String getDescription() { - return description; + return initialHardfork.description(); } /** Maybe warn version. */ @@ -184,7 +168,7 @@ public enum EvmSpecVersion { return; } - if (!specFinalized) { + if (!initialHardfork.finalized()) { LOGGER.error( "****** Not for Production Network Use ******\nExecuting code from EVM Spec Version {}, which has not been finalized.\n****** Not for Production Network Use ******", this.name()); @@ -223,7 +207,7 @@ public enum EvmSpecVersion { */ public static EvmSpecVersion mostRecent() { return Stream.of(EvmSpecVersion.values()) - .filter(v -> v.specFinalized) + .filter(v -> v.initialHardfork.finalized()) .max(Comparator.naturalOrder()) .orElseThrow(); }