diff --git a/besu/src/main/java/org/hyperledger/besu/chainimport/JsonBlockImporter.java b/besu/src/main/java/org/hyperledger/besu/chainimport/JsonBlockImporter.java index 6bde34d3519..455001681c0 100644 --- a/besu/src/main/java/org/hyperledger/besu/chainimport/JsonBlockImporter.java +++ b/besu/src/main/java/org/hyperledger/besu/chainimport/JsonBlockImporter.java @@ -120,7 +120,7 @@ private void setOptionalFields( final BlockData blockData, final GenesisConfigOptions genesisConfig) { // Some fields can only be configured for ethash - if (genesisConfig.getPowAlgorithm() != PowAlgorithm.NONE) { + if (genesisConfig.getPowAlgorithm() != PowAlgorithm.UNSUPPORTED) { // For simplicity only set these for ethash. Other consensus algorithms use these fields for // special purposes or ignore them miner.setCoinbase(blockData.getCoinbase().orElse(Address.ZERO)); diff --git a/besu/src/main/java/org/hyperledger/besu/cli/config/EthNetworkConfig.java b/besu/src/main/java/org/hyperledger/besu/cli/config/EthNetworkConfig.java index d59db1ff232..61fedb32be6 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/config/EthNetworkConfig.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/config/EthNetworkConfig.java @@ -47,6 +47,7 @@ public class EthNetworkConfig { public static final BigInteger RINKEBY_NETWORK_ID = BigInteger.valueOf(4); public static final BigInteger GOERLI_NETWORK_ID = BigInteger.valueOf(5); public static final BigInteger DEV_NETWORK_ID = BigInteger.valueOf(2018); + public static final BigInteger ECIP1049_DEV_NETWORK_ID = BigInteger.valueOf(2021); public static final BigInteger CLASSIC_NETWORK_ID = BigInteger.valueOf(1); public static final BigInteger KOTTI_NETWORK_ID = BigInteger.valueOf(6); public static final BigInteger MORDOR_NETWORK_ID = BigInteger.valueOf(7); @@ -56,6 +57,7 @@ public class EthNetworkConfig { private static final String RINKEBY_GENESIS = "/rinkeby.json"; private static final String GOERLI_GENESIS = "/goerli.json"; private static final String DEV_GENESIS = "/dev.json"; + private static final String ECIP1049_DEV_GENESIS = "/ecip1049_dev.json"; private static final String CLASSIC_GENESIS = "/classic.json"; private static final String KOTTI_GENESIS = "/kotti.json"; private static final String MORDOR_GENESIS = "/mordor.json"; @@ -154,6 +156,9 @@ public static EthNetworkConfig getNetworkConfig(final NetworkName networkName) { case CLASSIC: return new EthNetworkConfig( jsonConfig(CLASSIC_GENESIS), CLASSIC_NETWORK_ID, CLASSIC_BOOTSTRAP_NODES, null); + case ECIP1049_DEV: + return new EthNetworkConfig( + jsonConfig(ECIP1049_DEV_GENESIS), ECIP1049_DEV_NETWORK_ID, new ArrayList<>(), null); case KOTTI: return new EthNetworkConfig( jsonConfig(KOTTI_GENESIS), KOTTI_NETWORK_ID, KOTTI_BOOTSTRAP_NODES, null); @@ -194,6 +199,8 @@ public static String jsonConfig(final NetworkName network) { return jsonConfig(GOERLI_GENESIS); case DEV: return jsonConfig(DEV_GENESIS); + case ECIP1049_DEV: + return jsonConfig(ECIP1049_DEV_GENESIS); case CLASSIC: return jsonConfig(CLASSIC_GENESIS); case KOTTI: diff --git a/besu/src/main/java/org/hyperledger/besu/cli/config/NetworkName.java b/besu/src/main/java/org/hyperledger/besu/cli/config/NetworkName.java index 7f47f44efd8..66494726778 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/config/NetworkName.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/config/NetworkName.java @@ -23,5 +23,6 @@ public enum NetworkName { CLASSIC, KOTTI, MORDOR, - YOLO_V2 + YOLO_V2, + ECIP1049_DEV } diff --git a/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java b/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java index eb24c8cd8e0..db4c31f9ab0 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuController.java @@ -192,7 +192,7 @@ BesuControllerBuilder fromGenesisConfig( genesisConfig.getConfigOptions(genesisConfigOverrides); final BesuControllerBuilder builder; - if (configOptions.getPowAlgorithm() != PowAlgorithm.NONE) { + if (configOptions.getPowAlgorithm() != PowAlgorithm.UNSUPPORTED) { builder = new MainnetBesuControllerBuilder(); } else if (configOptions.isIbft2()) { builder = new IbftBesuControllerBuilder(); diff --git a/config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java b/config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java index b815e86e604..59be52cf799 100644 --- a/config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java +++ b/config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java @@ -25,6 +25,8 @@ public interface GenesisConfigOptions { boolean isEthHash(); + boolean isKeccak256(); + boolean isIbftLegacy(); boolean isIbft2(); @@ -43,6 +45,8 @@ public interface GenesisConfigOptions { EthashConfigOptions getEthashConfigOptions(); + Keccak256ConfigOptions getKeccak256ConfigOptions(); + OptionalLong getHomesteadBlockNumber(); OptionalLong getDaoForkBlock(); @@ -173,6 +177,16 @@ public interface GenesisConfigOptions { */ OptionalLong getThanosBlockNumber(); + /** + * Block number to activate ECIP-1049 on Classic networks. Changes the hashing algorithm to + * keccak-256. + * + * @return block number of ECIP-1049 fork on Classic networks + * @see https://ecips.ethereumclassic.org/ECIPs/ecip-1049 + */ + OptionalLong getEcip1049BlockNumber(); + Optional getChainId(); OptionalInt getContractSizeLimit(); diff --git a/config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java b/config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java index 109af498f58..404ae8746b6 100644 --- a/config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java +++ b/config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java @@ -37,6 +37,7 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions { private static final String ETHASH_CONFIG_KEY = "ethash"; + private static final String KECCAK256_CONFIG_KEY = "keccak256"; private static final String IBFT_LEGACY_CONFIG_KEY = "ibft"; private static final String IBFT2_CONFIG_KEY = "ibft2"; private static final String QBFT_CONFIG_KEY = "qbft"; @@ -94,6 +95,8 @@ private JsonGenesisConfigOptions( public String getConsensusEngine() { if (isEthHash()) { return ETHASH_CONFIG_KEY; + } else if (isKeccak256()) { + return KECCAK256_CONFIG_KEY; } else if (isIbft2()) { return IBFT2_CONFIG_KEY; } else if (isIbftLegacy()) { @@ -112,6 +115,11 @@ public boolean isEthHash() { return configRoot.has(ETHASH_CONFIG_KEY); } + @Override + public boolean isKeccak256() { + return configRoot.has(KECCAK256_CONFIG_KEY); + } + @Override public boolean isIbftLegacy() { return configRoot.has(IBFT_LEGACY_CONFIG_KEY); @@ -161,6 +169,13 @@ public EthashConfigOptions getEthashConfigOptions() { .orElse(EthashConfigOptions.DEFAULT); } + @Override + public Keccak256ConfigOptions getKeccak256ConfigOptions() { + return JsonUtil.getObjectNode(configRoot, KECCAK256_CONFIG_KEY) + .map(Keccak256ConfigOptions::new) + .orElse(Keccak256ConfigOptions.DEFAULT); + } + @Override public TransitionsConfigOptions getTransitions() { return transitions; @@ -292,6 +307,11 @@ public OptionalLong getThanosBlockNumber() { return getOptionalLong("thanosblock"); } + @Override + public OptionalLong getEcip1049BlockNumber() { + return getOptionalLong("ecip1049block"); + } + @Override public Optional getChainId() { return getOptionalBigInteger("chainid"); @@ -324,7 +344,9 @@ public OptionalLong getQip714BlockNumber() { @Override public PowAlgorithm getPowAlgorithm() { - return isEthHash() ? PowAlgorithm.ETHASH : PowAlgorithm.NONE; + return isEthHash() + ? PowAlgorithm.ETHASH + : isKeccak256() ? PowAlgorithm.KECCAK256 : PowAlgorithm.UNSUPPORTED; } @Override @@ -365,6 +387,9 @@ public Map asMap() { if (isEthHash()) { builder.put("ethash", getEthashConfigOptions().asMap()); } + if (isKeccak256()) { + builder.put("keccak256", getKeccak256ConfigOptions().asMap()); + } if (isIbftLegacy()) { builder.put("ibft", getIbftLegacyConfigOptions().asMap()); } diff --git a/config/src/main/java/org/hyperledger/besu/config/Keccak256ConfigOptions.java b/config/src/main/java/org/hyperledger/besu/config/Keccak256ConfigOptions.java new file mode 100644 index 00000000000..474768be375 --- /dev/null +++ b/config/src/main/java/org/hyperledger/besu/config/Keccak256ConfigOptions.java @@ -0,0 +1,43 @@ +/* + * Copyright ConsenSys AG. + * + * 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.config; + +import java.util.Map; +import java.util.OptionalLong; + +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.google.common.collect.ImmutableMap; + +public class Keccak256ConfigOptions { + + public static final Keccak256ConfigOptions DEFAULT = + new Keccak256ConfigOptions(JsonUtil.createEmptyObjectNode()); + + private final ObjectNode keccak256ConfigRoot; + + Keccak256ConfigOptions(final ObjectNode keccak256ConfigRoot) { + this.keccak256ConfigRoot = keccak256ConfigRoot; + } + + public OptionalLong getFixedDifficulty() { + return JsonUtil.getLong(keccak256ConfigRoot, "fixeddifficulty"); + } + + Map asMap() { + final ImmutableMap.Builder builder = ImmutableMap.builder(); + getFixedDifficulty().ifPresent(l -> builder.put("fixeddifficulty", l)); + return builder.build(); + } +} diff --git a/config/src/main/java/org/hyperledger/besu/config/PowAlgorithm.java b/config/src/main/java/org/hyperledger/besu/config/PowAlgorithm.java index 3b776780976..1949218a988 100644 --- a/config/src/main/java/org/hyperledger/besu/config/PowAlgorithm.java +++ b/config/src/main/java/org/hyperledger/besu/config/PowAlgorithm.java @@ -17,7 +17,8 @@ /** An enumeration of supported Proof-of-work algorithms. */ public enum PowAlgorithm { ETHASH, - NONE; + UNSUPPORTED, + KECCAK256; public static PowAlgorithm fromString(final String str) { for (final PowAlgorithm powAlgorithm : PowAlgorithm.values()) { diff --git a/config/src/main/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java b/config/src/main/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java index 8bb666a70d6..7dd08c90d7a 100644 --- a/config/src/main/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java +++ b/config/src/main/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java @@ -49,6 +49,7 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions { private final OptionalLong aghartaBlockNumber = OptionalLong.empty(); private final OptionalLong phoenixBlockNumber = OptionalLong.empty(); private final OptionalLong thanosBlockNumber = OptionalLong.empty(); + private final OptionalLong ecip1049BlockNumber = OptionalLong.empty(); private Optional chainId = Optional.empty(); private OptionalInt contractSizeLimit = OptionalInt.empty(); private OptionalInt stackSizeLimit = OptionalInt.empty(); @@ -64,6 +65,11 @@ public boolean isEthHash() { return true; } + @Override + public boolean isKeccak256() { + return false; + } + @Override public boolean isIbftLegacy() { return false; @@ -104,6 +110,11 @@ public EthashConfigOptions getEthashConfigOptions() { return EthashConfigOptions.DEFAULT; } + @Override + public Keccak256ConfigOptions getKeccak256ConfigOptions() { + return Keccak256ConfigOptions.DEFAULT; + } + @Override public OptionalLong getHomesteadBlockNumber() { return homesteadBlockNumber; @@ -205,6 +216,11 @@ public OptionalLong getThanosBlockNumber() { return thanosBlockNumber; } + @Override + public OptionalLong getEcip1049BlockNumber() { + return ecip1049BlockNumber; + } + @Override public OptionalInt getContractSizeLimit() { return contractSizeLimit; @@ -257,6 +273,9 @@ public Map asMap() { if (isEthHash()) { builder.put("ethash", getEthashConfigOptions().asMap()); } + if (isKeccak256()) { + builder.put("keccak256", getKeccak256ConfigOptions().asMap()); + } if (isIbftLegacy()) { builder.put("ibft", getIbftLegacyConfigOptions().asMap()); } @@ -283,7 +302,9 @@ public OptionalLong getQip714BlockNumber() { @Override public PowAlgorithm getPowAlgorithm() { - return isEthHash() ? PowAlgorithm.ETHASH : PowAlgorithm.NONE; + return isEthHash() + ? PowAlgorithm.ETHASH + : isKeccak256() ? PowAlgorithm.KECCAK256 : PowAlgorithm.UNSUPPORTED; } @Override diff --git a/config/src/main/resources/ecip1049_dev.json b/config/src/main/resources/ecip1049_dev.json new file mode 100644 index 00000000000..10828c22695 --- /dev/null +++ b/config/src/main/resources/ecip1049_dev.json @@ -0,0 +1,43 @@ +{ + "config": { + "chainId": 2021, + "homesteadBlock": 0, + "classicForkBlock": 0, + "ecip1015Block": 0, + "diehardBlock": 0, + "gothamBlock": 0, + "ecip1041Block": 0, + "atlantisBlock": 0, + "aghartaBlock": 0, + "phoenixBlock": 0, + "thanosBlock": 0, + "ecip1049Block": 0, + "keccak256": { + "fixeddifficulty": 100 + } + }, + "nonce": "0x42", + "timestamp": "0x0", + "extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa", + "gasLimit": "0x1fffffffffffff", + "difficulty": "0x10000", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "coinbase": "0x0000000000000000000000000000000000000000", + "alloc": { + "fe3b557e8fb62b89f4916b721be55ceb828dbd73": { + "privateKey": "8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63", + "comment": "private key and this comment are ignored. In a real chain, the private key should NOT be stored", + "balance": "0xad78ebc5ac6200000" + }, + "627306090abaB3A6e1400e9345bC60c78a8BEf57": { + "privateKey": "c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3", + "comment": "private key and this comment are ignored. In a real chain, the private key should NOT be stored", + "balance": "90000000000000000000000" + }, + "f17f52151EbEF6C7334FAD080c5704D77216b732": { + "privateKey": "ae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f", + "comment": "private key and this comment are ignored. In a real chain, the private key should NOT be stored", + "balance": "90000000000000000000000" + } + } +} diff --git a/config/src/test/java/org/hyperledger/besu/config/GenesisConfigOptionsTest.java b/config/src/test/java/org/hyperledger/besu/config/GenesisConfigOptionsTest.java index 930f20f8f73..e0cce4de11a 100644 --- a/config/src/test/java/org/hyperledger/besu/config/GenesisConfigOptionsTest.java +++ b/config/src/test/java/org/hyperledger/besu/config/GenesisConfigOptionsTest.java @@ -37,12 +37,25 @@ public void shouldUseEthHashWhenEthHashInConfig() { assertThat(config.getConsensusEngine()).isEqualTo("ethash"); } + @Test + public void shouldUseKeccak256WhenKeccak256InConfig() { + final GenesisConfigOptions config = fromConfigOptions(singletonMap("keccak256", emptyMap())); + assertThat(config.isKeccak256()).isTrue(); + assertThat(config.getConsensusEngine()).isEqualTo("keccak256"); + } + @Test public void shouldNotUseEthHashIfEthHashNotPresent() { final GenesisConfigOptions config = fromConfigOptions(emptyMap()); assertThat(config.isEthHash()).isFalse(); } + @Test + public void shouldNotUseKeccak256IfEthHashNotPresent() { + final GenesisConfigOptions config = fromConfigOptions(emptyMap()); + assertThat(config.isKeccak256()).isFalse(); + } + @Test public void shouldUseIbftLegacyWhenIbftInConfig() { final GenesisConfigOptions config = fromConfigOptions(singletonMap("ibft", emptyMap())); @@ -195,6 +208,13 @@ public void shouldGetEIP1559BlockNumber() { } } + @Test + // TODO ECIP-1049 change for the actual fork name when known + public void shouldGetECIP1049BlockNumber() { + final GenesisConfigOptions config = fromConfigOptions(singletonMap("ecip1049block", 1000)); + assertThat(config.getEcip1049BlockNumber()).hasValue(1000); + } + @Test public void shouldNotReturnEmptyOptionalWhenBlockNumberNotSpecified() { final GenesisConfigOptions config = fromConfigOptions(emptyMap()); @@ -208,6 +228,7 @@ public void shouldNotReturnEmptyOptionalWhenBlockNumberNotSpecified() { assertThat(config.getIstanbulBlockNumber()).isEmpty(); assertThat(config.getMuirGlacierBlockNumber()).isEmpty(); assertThat(config.getBerlinBlockNumber()).isEmpty(); + assertThat(config.getEcip1049BlockNumber()).isEmpty(); } @Test diff --git a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java index 93da6e4cd9f..edc506b86ae 100644 --- a/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java +++ b/consensus/clique/src/main/java/org/hyperledger/besu/consensus/clique/CliqueProtocolSchedule.java @@ -74,8 +74,7 @@ public static ProtocolSchedule create( privacyParameters.getGoQuorumPrivacyParameters().isPresent()), privacyParameters, isRevertReasonEnabled, - config.isQuorum(), - config.getPowAlgorithm()) + config.isQuorum()) .createProtocolSchedule(); } diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BftProtocolSchedule.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BftProtocolSchedule.java index 9bfe9772d7b..1cb61c18e7f 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BftProtocolSchedule.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/BftProtocolSchedule.java @@ -46,8 +46,7 @@ public static ProtocolSchedule create( builder -> applyBftChanges(config.getBftConfigOptions(), builder, config.isQuorum()), privacyParameters, isRevertReasonEnabled, - config.isQuorum(), - config.getPowAlgorithm()) + config.isQuorum()) .createProtocolSchedule(); } diff --git a/consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/IbftProtocolSchedule.java b/consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/IbftProtocolSchedule.java index b18cf529754..058f548ba3a 100644 --- a/consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/IbftProtocolSchedule.java +++ b/consensus/ibftlegacy/src/main/java/org/hyperledger/besu/consensus/ibftlegacy/IbftProtocolSchedule.java @@ -47,8 +47,7 @@ public static ProtocolSchedule create( builder -> applyIbftChanges(blockPeriod, builder, config.isQuorum()), privacyParameters, isRevertReasonEnabled, - config.isQuorum(), - config.getPowAlgorithm()) + config.isQuorum()) .createProtocolSchedule(); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java index ad6f70f62ca..f76813dddbe 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java @@ -104,7 +104,7 @@ public class EthGetTransactionReceiptTest { Optional.empty(), TransactionGasBudgetCalculator.frontier(), null, - PoWHasher.LIGHT); + PoWHasher.ETHASH_LIGHT); private final ProtocolSpec statusTransactionTypeSpec = new ProtocolSpec( "status", @@ -130,7 +130,7 @@ public class EthGetTransactionReceiptTest { Optional.empty(), TransactionGasBudgetCalculator.frontier(), null, - PoWHasher.LIGHT); + PoWHasher.ETHASH_LIGHT); @SuppressWarnings("unchecked") private final ProtocolSchedule protocolSchedule = mock(ProtocolSchedule.class); diff --git a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java index 61da05ee342..b659999137a 100644 --- a/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java +++ b/ethereum/blockcreation/src/test/java/org/hyperledger/besu/ethereum/blockcreation/PoWBlockCreatorTest.java @@ -74,15 +74,14 @@ public void createMainnetBlock1() throws IOException { Function.identity(), PrivacyParameters.DEFAULT, false, - genesisConfigOptions.isQuorum(), - genesisConfigOptions.getPowAlgorithm()) + genesisConfigOptions.isQuorum()) .createProtocolSchedule()) .build(); final PoWSolver solver = new PoWSolver( Lists.newArrayList(BLOCK_1_NONCE), - PoWHasher.LIGHT, + PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator()); @@ -134,15 +133,14 @@ public void createMainnetBlock1_fixedDifficulty1() { Function.identity(), PrivacyParameters.DEFAULT, false, - genesisConfigOptions.isQuorum(), - genesisConfigOptions.getPowAlgorithm()) + genesisConfigOptions.isQuorum()) .createProtocolSchedule()) .build(); final PoWSolver solver = new PoWSolver( Lists.newArrayList(BLOCK_1_NONCE), - PoWHasher.LIGHT, + PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator()); @@ -189,15 +187,14 @@ public void rewardBeneficiary_zeroReward_skipZeroRewardsFalse() { Function.identity(), PrivacyParameters.DEFAULT, false, - genesisConfigOptions.isQuorum(), - genesisConfigOptions.getPowAlgorithm()) + genesisConfigOptions.isQuorum()) .createProtocolSchedule()) .build(); final PoWSolver solver = new PoWSolver( Lists.newArrayList(BLOCK_1_NONCE), - PoWHasher.LIGHT, + PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator()); @@ -260,15 +257,14 @@ public void rewardBeneficiary_zeroReward_skipZeroRewardsTrue() { Function.identity(), PrivacyParameters.DEFAULT, false, - genesisConfigOptions.isQuorum(), - genesisConfigOptions.getPowAlgorithm()) + genesisConfigOptions.isQuorum()) .createProtocolSchedule()) .build(); final PoWSolver solver = new PoWSolver( Lists.newArrayList(BLOCK_1_NONCE), - PoWHasher.LIGHT, + PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator()); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java index 505598c6c60..014ea997fa4 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyProtocolSchedule.java @@ -31,8 +31,7 @@ public static ProtocolSchedule create( builder -> builder.difficultyCalculator(FixedDifficultyCalculators.calculator(config)), privacyParameters, isRevertReasonEnabled, - config.isQuorum(), - config.getPowAlgorithm()) + config.isQuorum()) .createProtocolSchedule(); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java index 3b7815c65fb..512b5ccb1a8 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java @@ -40,12 +40,10 @@ public class ClassicProtocolSpecs { public static ProtocolSpecBuilder classicRecoveryInitDefinition( final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { + final boolean quorumCompatibilityMode) { return MainnetProtocolSpecs.homesteadDefinition( - contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode, powAlgorithm) - .blockHeaderValidatorBuilder( - MainnetBlockHeaderValidator.createClassicValidator(powHasher(powAlgorithm))) + contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode) + .blockHeaderValidatorBuilder(MainnetBlockHeaderValidator.createClassicValidator()) .name("ClassicRecoveryInit"); } @@ -53,10 +51,9 @@ public static ProtocolSpecBuilder tangerineWhistleDefinition( final Optional chainId, final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { + final boolean quorumCompatibilityMode) { return MainnetProtocolSpecs.homesteadDefinition( - contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode, powAlgorithm) + contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode) .gasCalculator(TangerineWhistleGasCalculator::new) .transactionValidatorBuilder( gasCalculator -> @@ -69,14 +66,9 @@ public static ProtocolSpecBuilder dieHardDefinition( final Optional chainId, final OptionalInt configContractSizeLimit, final OptionalInt configStackSizeLimit, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { + final boolean quorumCompatibilityMode) { return tangerineWhistleDefinition( - chainId, - OptionalInt.empty(), - configStackSizeLimit, - quorumCompatibilityMode, - powAlgorithm) + chainId, OptionalInt.empty(), configStackSizeLimit, quorumCompatibilityMode) .gasCalculator(DieHardGasCalculator::new) .difficultyCalculator(ClassicDifficultyCalculators.DIFFICULTY_BOMB_PAUSED) .name("DieHard"); @@ -87,10 +79,9 @@ public static ProtocolSpecBuilder gothamDefinition( final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, final OptionalLong ecip1017EraRounds, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { + final boolean quorumCompatibilityMode) { return dieHardDefinition( - chainId, contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode, powAlgorithm) + chainId, contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode) .blockReward(MAX_BLOCK_REWARD) .difficultyCalculator(ClassicDifficultyCalculators.DIFFICULTY_BOMB_DELAYED) .blockProcessorBuilder( @@ -116,15 +107,13 @@ public static ProtocolSpecBuilder defuseDifficultyBombDefinition( final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, final OptionalLong ecip1017EraRounds, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { + final boolean quorumCompatibilityMode) { return gothamDefinition( chainId, contractSizeLimit, configStackSizeLimit, ecip1017EraRounds, - quorumCompatibilityMode, - powAlgorithm) + quorumCompatibilityMode) .difficultyCalculator(ClassicDifficultyCalculators.DIFFICULTY_BOMB_REMOVED) .transactionValidatorBuilder( gasCalculator -> @@ -139,8 +128,7 @@ public static ProtocolSpecBuilder atlantisDefinition( final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final OptionalLong ecip1017EraRounds, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { + final boolean quorumCompatibilityMode) { final int contractSizeLimit = configContractSizeLimit.orElse(MainnetProtocolSpecs.SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT); final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE); @@ -149,8 +137,7 @@ public static ProtocolSpecBuilder atlantisDefinition( configContractSizeLimit, configStackSizeLimit, ecip1017EraRounds, - quorumCompatibilityMode, - powAlgorithm) + quorumCompatibilityMode) .evmBuilder(MainnetEvmRegistries::byzantium) .gasCalculator(SpuriousDragonGasCalculator::new) .skipZeroBlockRewards(true) @@ -195,16 +182,14 @@ public static ProtocolSpecBuilder aghartaDefinition( final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final OptionalLong ecip1017EraRounds, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { + final boolean quorumCompatibilityMode) { return atlantisDefinition( chainId, configContractSizeLimit, configStackSizeLimit, enableRevertReason, ecip1017EraRounds, - quorumCompatibilityMode, - powAlgorithm) + quorumCompatibilityMode) .evmBuilder(MainnetEvmRegistries::constantinople) .gasCalculator(PetersburgGasCalculator::new) .evmBuilder(gasCalculator -> MainnetEvmRegistries.constantinople(gasCalculator)) @@ -218,16 +203,14 @@ public static ProtocolSpecBuilder phoenixDefinition( final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final OptionalLong ecip1017EraRounds, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { + final boolean quorumCompatibilityMode) { return aghartaDefinition( chainId, configContractSizeLimit, configStackSizeLimit, enableRevertReason, ecip1017EraRounds, - quorumCompatibilityMode, - powAlgorithm) + quorumCompatibilityMode) .gasCalculator(IstanbulGasCalculator::new) .evmBuilder( gasCalculator -> @@ -242,22 +225,20 @@ public static ProtocolSpecBuilder thanosDefinition( final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final OptionalLong ecip1017EraRounds, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { + final boolean quorumCompatibilityMode) { return phoenixDefinition( chainId, configContractSizeLimit, configStackSizeLimit, enableRevertReason, ecip1017EraRounds, - quorumCompatibilityMode, - powAlgorithm) + quorumCompatibilityMode) .blockHeaderValidatorBuilder( MainnetBlockHeaderValidator.createBlockHeaderValidator( - new EpochCalculator.Ecip1099EpochCalculator(), powHasher(powAlgorithm))) + new EpochCalculator.Ecip1099EpochCalculator(), powHasher(PowAlgorithm.ETHASH))) .ommerHeaderValidatorBuilder( MainnetBlockHeaderValidator.createOmmerValidator( - new EpochCalculator.Ecip1099EpochCalculator(), powHasher(powAlgorithm))) + new EpochCalculator.Ecip1099EpochCalculator(), powHasher(PowAlgorithm.ETHASH))) .name("Thanos"); } @@ -280,4 +261,28 @@ private static TransactionReceipt byzantiumTransactionReceiptFactoryWithReasonEn return new TransactionReceipt( result.isSuccessful() ? 1 : 0, gasUsed, result.getLogs(), result.getRevertReason()); } + + public static ProtocolSpecBuilder ecip1049Definition( + final Optional chainId, + final OptionalInt configContractSizeLimit, + final OptionalInt configStackSizeLimit, + final boolean enableRevertReason, + final OptionalLong ecip1017EraRounds, + final boolean quorumCompatibilityMode) { + return thanosDefinition( + chainId, + configContractSizeLimit, + configStackSizeLimit, + enableRevertReason, + ecip1017EraRounds, + quorumCompatibilityMode) + .blockHeaderValidatorBuilder( + MainnetBlockHeaderValidator.createBlockHeaderValidator( + new EpochCalculator.Ecip1099EpochCalculator(), powHasher(PowAlgorithm.KECCAK256))) + .ommerHeaderValidatorBuilder( + MainnetBlockHeaderValidator.createOmmerValidator( + new EpochCalculator.Ecip1099EpochCalculator(), powHasher(PowAlgorithm.KECCAK256))) + .powHasher(powHasher(PowAlgorithm.KECCAK256)) + .name("ecip1049"); + } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/KeccakHasher.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/KeccakHasher.java new file mode 100644 index 00000000000..af528576e60 --- /dev/null +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/KeccakHasher.java @@ -0,0 +1,18 @@ +package org.hyperledger.besu.ethereum.mainnet; + +public class KeccakHasher implements PoWHasher { + + public static final KeccakHasher KECCAK256 = new KeccakHasher(); + + private KeccakHasher() {} + + @Override + public void hash( + final byte[] buffer, + final long nonce, + final long number, + final EpochCalculator epochCalc, + final byte[] headerHash) { + throw new UnsupportedOperationException("TODO"); // TODO + } +} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockHeaderValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockHeaderValidator.java index 94a6b5653e5..85b71268c1f 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockHeaderValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockHeaderValidator.java @@ -40,17 +40,25 @@ public final class MainnetBlockHeaderValidator { public static final Bytes CLASSIC_FORK_BLOCK_HEADER = Bytes.fromHexString("0x94365e3a8c0b35089c1d1195081fe7489b528a84b22199c916180db8b28ade7f"); + public static BlockHeaderValidator.Builder create() { + return createValidator(PoWHasher.ETHASH_LIGHT); + } + public static BlockHeaderValidator.Builder create(final PoWHasher hasher) { return createValidator(hasher); } - public static BlockHeaderValidator.Builder createDaoValidator(final PoWHasher hasher) { - return createValidator(hasher) + public static BlockHeaderValidator.Builder createDaoValidator() { + return createValidator() .addRule( new ConstantFieldValidationRule<>( "extraData", BlockHeader::getExtraData, DAO_EXTRA_DATA)); } + public static BlockHeaderValidator.Builder createClassicValidator() { + return createClassicValidator(PoWHasher.ETHASH_LIGHT); + } + public static BlockHeaderValidator.Builder createClassicValidator(final PoWHasher hasher) { return createValidator(hasher) .addRule( @@ -68,6 +76,11 @@ public static boolean validateHeaderForClassicFork(final BlockHeader header) { return header.getNumber() != 1_920_000 || header.getHash().equals(CLASSIC_FORK_BLOCK_HEADER); } + static BlockHeaderValidator.Builder createOmmerValidator() { + return createOmmerValidator( + new EpochCalculator.DefaultEpochCalculator(), PoWHasher.ETHASH_LIGHT); + } + static BlockHeaderValidator.Builder createOmmerValidator(final PoWHasher hasher) { return createOmmerValidator(new EpochCalculator.DefaultEpochCalculator(), hasher); } @@ -84,6 +97,10 @@ static BlockHeaderValidator.Builder createOmmerValidator( .addRule(new ProofOfWorkValidationRule(epochCalculator, false, hasher)); } + private static BlockHeaderValidator.Builder createValidator() { + return createValidator(PoWHasher.ETHASH_LIGHT); + } + private static BlockHeaderValidator.Builder createValidator(final PoWHasher hasher) { return createBlockHeaderValidator(new EpochCalculator.DefaultEpochCalculator(), hasher); } @@ -101,8 +118,7 @@ static BlockHeaderValidator.Builder createBlockHeaderValidator( .addRule(new ProofOfWorkValidationRule(epochCalculator, false, hasher)); } - static BlockHeaderValidator.Builder createEip1559Validator( - final EIP1559 eip1559, final PoWHasher hasher) { + static BlockHeaderValidator.Builder createEip1559Validator(final EIP1559 eip1559) { ExperimentalEIPs.eip1559MustBeEnabled(); return new BlockHeaderValidator.Builder() .addRule(CalculatedDifficultyValidationRule::new) @@ -113,12 +129,11 @@ static BlockHeaderValidator.Builder createEip1559Validator( .addRule(new ExtraDataMaxLengthValidationRule(BlockHeader.MAX_EXTRA_DATA_BYTES)) .addRule( new ProofOfWorkValidationRule( - new EpochCalculator.DefaultEpochCalculator(), true, hasher)) + new EpochCalculator.DefaultEpochCalculator(), true, PoWHasher.ETHASH_LIGHT)) .addRule((new EIP1559BlockHeaderGasPriceValidationRule(eip1559))); } - static BlockHeaderValidator.Builder createEip1559OmmerValidator( - final EIP1559 eip1559, final PoWHasher hasher) { + static BlockHeaderValidator.Builder createEip1559OmmerValidator(final EIP1559 eip1559) { ExperimentalEIPs.eip1559MustBeEnabled(); return new BlockHeaderValidator.Builder() .addRule(CalculatedDifficultyValidationRule::new) @@ -128,7 +143,7 @@ static BlockHeaderValidator.Builder createEip1559OmmerValidator( .addRule(new ExtraDataMaxLengthValidationRule(BlockHeader.MAX_EXTRA_DATA_BYTES)) .addRule( new ProofOfWorkValidationRule( - new EpochCalculator.DefaultEpochCalculator(), true, hasher)) + new EpochCalculator.DefaultEpochCalculator(), true, PoWHasher.ETHASH_LIGHT)) .addRule((new EIP1559BlockHeaderGasPriceValidationRule(eip1559))); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSchedule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSchedule.java index 15c00effd9b..3fcc0eaf4a4 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSchedule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSchedule.java @@ -50,8 +50,7 @@ public static ProtocolSchedule fromConfig( Function.identity(), privacyParameters, isRevertReasonEnabled, - config.isQuorum(), - config.getPowAlgorithm()) + config.isQuorum()) .createProtocolSchedule(); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java index 5f2138d98a3..83f867a7a77 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java @@ -87,8 +87,7 @@ private MainnetProtocolSpecs() {} public static ProtocolSpecBuilder frontierDefinition( final OptionalInt configContractSizeLimit, final OptionalInt configStackSizeLimit, - final boolean goQuorumMode, - final PowAlgorithm powAlgorithm) { + final boolean goQuorumMode) { final int contractSizeLimit = configContractSizeLimit.orElse(FRONTIER_CONTRACT_SIZE_LIMIT); final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE); return new ProtocolSpecBuilder() @@ -139,9 +138,8 @@ public static ProtocolSpecBuilder frontierDefinition( Account.DEFAULT_VERSION, new PrivateTransactionValidator(Optional.empty()))) .difficultyCalculator(MainnetDifficultyCalculators.FRONTIER) - .blockHeaderValidatorBuilder(MainnetBlockHeaderValidator.create(powHasher(powAlgorithm))) - .ommerHeaderValidatorBuilder( - MainnetBlockHeaderValidator.createOmmerValidator(powHasher(powAlgorithm))) + .blockHeaderValidatorBuilder(MainnetBlockHeaderValidator.create()) + .ommerHeaderValidatorBuilder(MainnetBlockHeaderValidator.createOmmerValidator()) .blockBodyValidatorBuilder(MainnetBlockBodyValidator::new) .transactionReceiptFactory(MainnetProtocolSpecs::frontierTransactionReceiptFactory) .blockReward(FRONTIER_BLOCK_REWARD) @@ -151,20 +149,21 @@ public static ProtocolSpecBuilder frontierDefinition( .blockImporterBuilder(MainnetBlockImporter::new) .blockHeaderFunctions(new MainnetBlockHeaderFunctions()) .miningBeneficiaryCalculator(BlockHeader::getCoinbase) - .powHasher(powHasher(powAlgorithm)) .name("Frontier"); } public static PoWHasher powHasher(final PowAlgorithm powAlgorithm) { if (powAlgorithm == null) { - return PoWHasher.NOOP; + return PoWHasher.UNSUPPORTED; } switch (powAlgorithm) { case ETHASH: - return PoWHasher.LIGHT; - case NONE: + return PoWHasher.ETHASH_LIGHT; + case KECCAK256: + return KeccakHasher.KECCAK256; + case UNSUPPORTED: default: - return PoWHasher.NOOP; + return PoWHasher.UNSUPPORTED; } } @@ -187,11 +186,10 @@ public static BlockProcessorBuilder blockProcessorBuilder(final boolean goQuorum public static ProtocolSpecBuilder homesteadDefinition( final OptionalInt configContractSizeLimit, final OptionalInt configStackSizeLimit, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { + final boolean quorumCompatibilityMode) { final int contractSizeLimit = configContractSizeLimit.orElse(FRONTIER_CONTRACT_SIZE_LIMIT); return frontierDefinition( - configContractSizeLimit, configStackSizeLimit, quorumCompatibilityMode, powAlgorithm) + configContractSizeLimit, configStackSizeLimit, quorumCompatibilityMode) .gasCalculator(HomesteadGasCalculator::new) .evmBuilder(MainnetEvmRegistries::homestead) .contractCreationProcessorBuilder( @@ -213,12 +211,9 @@ public static ProtocolSpecBuilder homesteadDefinition( public static ProtocolSpecBuilder daoRecoveryInitDefinition( final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { - return homesteadDefinition( - contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode, powAlgorithm) - .blockHeaderValidatorBuilder( - MainnetBlockHeaderValidator.createDaoValidator(powHasher(powAlgorithm))) + final boolean quorumCompatibilityMode) { + return homesteadDefinition(contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode) + .blockHeaderValidatorBuilder(MainnetBlockHeaderValidator.createDaoValidator()) .blockProcessorBuilder( (transactionProcessor, transactionReceiptFactory, @@ -242,10 +237,9 @@ public static ProtocolSpecBuilder daoRecoveryInitDefinition( public static ProtocolSpecBuilder daoRecoveryTransitionDefinition( final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { + final boolean quorumCompatibilityMode) { return daoRecoveryInitDefinition( - contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode, powAlgorithm) + contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode) .blockProcessorBuilder(MainnetBlockProcessor::new) .name("DaoRecoveryTransition"); } @@ -253,10 +247,8 @@ public static ProtocolSpecBuilder daoRecoveryTransitionDefinition( public static ProtocolSpecBuilder tangerineWhistleDefinition( final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { - return homesteadDefinition( - contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode, powAlgorithm) + final boolean quorumCompatibilityMode) { + return homesteadDefinition(contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode) .gasCalculator(TangerineWhistleGasCalculator::new) .name("TangerineWhistle"); } @@ -265,14 +257,13 @@ public static ProtocolSpecBuilder spuriousDragonDefinition( final Optional chainId, final OptionalInt configContractSizeLimit, final OptionalInt configStackSizeLimit, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { + final boolean quorumCompatibilityMode) { final int contractSizeLimit = configContractSizeLimit.orElse(SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT); final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE); return tangerineWhistleDefinition( - OptionalInt.empty(), configStackSizeLimit, quorumCompatibilityMode, powAlgorithm) + OptionalInt.empty(), configStackSizeLimit, quorumCompatibilityMode) .gasCalculator(SpuriousDragonGasCalculator::new) .skipZeroBlockRewards(true) .messageCallProcessorBuilder( @@ -317,11 +308,10 @@ public static ProtocolSpecBuilder byzantiumDefinition( final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, final boolean enableRevertReason, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { + final boolean quorumCompatibilityMode) { final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE); return spuriousDragonDefinition( - chainId, contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode, powAlgorithm) + chainId, contractSizeLimit, configStackSizeLimit, quorumCompatibilityMode) .gasCalculator(ByzantiumGasCalculator::new) .evmBuilder(MainnetEvmRegistries::byzantium) .precompileContractRegistryBuilder(MainnetPrecompiledContractRegistries::byzantium) @@ -355,15 +345,13 @@ public static ProtocolSpecBuilder constantinopleDefinition( final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, final boolean enableRevertReason, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { + final boolean quorumCompatibilityMode) { return byzantiumDefinition( chainId, contractSizeLimit, configStackSizeLimit, enableRevertReason, - quorumCompatibilityMode, - powAlgorithm) + quorumCompatibilityMode) .difficultyCalculator(MainnetDifficultyCalculators.CONSTANTINOPLE) .gasCalculator(ConstantinopleGasCalculator::new) .evmBuilder(MainnetEvmRegistries::constantinople) @@ -376,15 +364,13 @@ public static ProtocolSpecBuilder petersburgDefinition( final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, final boolean enableRevertReason, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { + final boolean quorumCompatibilityMode) { return constantinopleDefinition( chainId, contractSizeLimit, configStackSizeLimit, enableRevertReason, - quorumCompatibilityMode, - powAlgorithm) + quorumCompatibilityMode) .gasCalculator(PetersburgGasCalculator::new) .name("Petersburg"); } @@ -394,8 +380,7 @@ public static ProtocolSpecBuilder istanbulDefinition( final OptionalInt configContractSizeLimit, final OptionalInt configStackSizeLimit, final boolean enableRevertReason, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { + final boolean quorumCompatibilityMode) { final int contractSizeLimit = configContractSizeLimit.orElse(SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT); return petersburgDefinition( @@ -403,8 +388,7 @@ public static ProtocolSpecBuilder istanbulDefinition( configContractSizeLimit, configStackSizeLimit, enableRevertReason, - quorumCompatibilityMode, - powAlgorithm) + quorumCompatibilityMode) .gasCalculator(IstanbulGasCalculator::new) .evmBuilder( gasCalculator -> @@ -427,15 +411,13 @@ static ProtocolSpecBuilder muirGlacierDefinition( final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, final boolean enableRevertReason, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { + final boolean quorumCompatibilityMode) { return istanbulDefinition( chainId, contractSizeLimit, configStackSizeLimit, enableRevertReason, - quorumCompatibilityMode, - powAlgorithm) + quorumCompatibilityMode) .difficultyCalculator(MainnetDifficultyCalculators.MUIR_GLACIER) .name("MuirGlacier"); } @@ -445,8 +427,7 @@ static ProtocolSpecBuilder berlinDefinition( final OptionalInt contractSizeLimit, final OptionalInt configStackSizeLimit, final boolean enableRevertReason, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { + final boolean quorumCompatibilityMode) { if (!ExperimentalEIPs.berlinEnabled) { throw new RuntimeException("Berlin feature flag must be enabled --Xberlin-enabled"); } @@ -455,8 +436,7 @@ static ProtocolSpecBuilder berlinDefinition( contractSizeLimit, configStackSizeLimit, enableRevertReason, - quorumCompatibilityMode, - powAlgorithm) + quorumCompatibilityMode) .gasCalculator(BerlinGasCalculator::new) .transactionValidatorBuilder( gasCalculator -> @@ -485,8 +465,7 @@ static ProtocolSpecBuilder eip1559Definition( final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { + final boolean quorumCompatibilityMode) { ExperimentalEIPs.eip1559MustBeEnabled(); final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE); final EIP1559 eip1559 = new EIP1559(genesisConfigOptions.getEIP1559BlockNumber().orElse(0)); @@ -495,8 +474,7 @@ static ProtocolSpecBuilder eip1559Definition( contractSizeLimit, configStackSizeLimit, enableRevertReason, - quorumCompatibilityMode, - powAlgorithm) + quorumCompatibilityMode) .transactionValidatorBuilder( gasCalculator -> new MainnetTransactionValidator( @@ -525,12 +503,9 @@ static ProtocolSpecBuilder eip1559Definition( .transactionPriceCalculator(transactionPriceCalculator.orElseThrow()) .eip1559(Optional.of(eip1559)) .gasBudgetCalculator(TransactionGasBudgetCalculator.eip1559(eip1559)) - .blockHeaderValidatorBuilder( - MainnetBlockHeaderValidator.createEip1559Validator(eip1559, powHasher(powAlgorithm))) + .blockHeaderValidatorBuilder(MainnetBlockHeaderValidator.createEip1559Validator(eip1559)) .ommerHeaderValidatorBuilder( - MainnetBlockHeaderValidator.createEip1559OmmerValidator( - eip1559, powHasher(powAlgorithm))) - .powHasher(powHasher(powAlgorithm)); + MainnetBlockHeaderValidator.createEip1559OmmerValidator(eip1559)); } private static TransactionReceipt frontierTransactionReceiptFactory( diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWHasher.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWHasher.java index d62105e70d3..31aa26a4f9a 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWHasher.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/PoWHasher.java @@ -16,8 +16,8 @@ public interface PoWHasher { - PoWHasher LIGHT = new Light(); - PoWHasher NOOP = new NoOp(); + PoWHasher ETHASH_LIGHT = new EthashLight(); + PoWHasher UNSUPPORTED = new Unsupported(); /** * Hash of a particular block and nonce. @@ -31,11 +31,11 @@ public interface PoWHasher { void hash(byte[] buffer, long nonce, long number, EpochCalculator epochCalc, byte[] headerHash); /** Implementation of Ethash Hashimoto Light Implementation. */ - final class Light implements PoWHasher { + final class EthashLight implements PoWHasher { private static final EthHashCacheFactory cacheFactory = new EthHashCacheFactory(); - private Light() {} + private EthashLight() {} @Override public void hash( @@ -53,9 +53,9 @@ public void hash( } /** Implementation of an inoperative hasher. */ - final class NoOp implements PoWHasher { + final class Unsupported implements PoWHasher { - private NoOp() {} + private Unsupported() {} @Override public void hash( 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 9ae009aa519..9ab0503e0a6 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,7 +15,6 @@ package org.hyperledger.besu.ethereum.mainnet; import org.hyperledger.besu.config.GenesisConfigOptions; -import org.hyperledger.besu.config.PowAlgorithm; import org.hyperledger.besu.config.experimental.ExperimentalEIPs; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.PrivacyParameters; @@ -40,7 +39,6 @@ public class ProtocolScheduleBuilder { private final boolean isRevertReasonEnabled; private final BadBlockManager badBlockManager = new BadBlockManager(); private final boolean quorumCompatibilityMode; - private final PowAlgorithm powAlgorithm; public ProtocolScheduleBuilder( final GenesisConfigOptions config, @@ -48,16 +46,14 @@ public ProtocolScheduleBuilder( final Function protocolSpecAdapter, final PrivacyParameters privacyParameters, final boolean isRevertReasonEnabled, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { + final boolean quorumCompatibilityMode) { this( config, Optional.of(defaultChainId), protocolSpecAdapter, privacyParameters, isRevertReasonEnabled, - quorumCompatibilityMode, - powAlgorithm); + quorumCompatibilityMode); } public ProtocolScheduleBuilder( @@ -65,16 +61,14 @@ public ProtocolScheduleBuilder( final Function protocolSpecAdapter, final PrivacyParameters privacyParameters, final boolean isRevertReasonEnabled, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { + final boolean quorumCompatibilityMode) { this( config, Optional.empty(), protocolSpecAdapter, privacyParameters, isRevertReasonEnabled, - quorumCompatibilityMode, - powAlgorithm); + quorumCompatibilityMode); } private ProtocolScheduleBuilder( @@ -83,15 +77,13 @@ private ProtocolScheduleBuilder( final Function protocolSpecAdapter, final PrivacyParameters privacyParameters, final boolean isRevertReasonEnabled, - final boolean quorumCompatibilityMode, - final PowAlgorithm powAlgorithm) { + final boolean quorumCompatibilityMode) { this.config = config; this.defaultChainId = defaultChainId; this.protocolSpecAdapter = protocolSpecAdapter; this.privacyParameters = privacyParameters; this.isRevertReasonEnabled = isRevertReasonEnabled; this.quorumCompatibilityMode = quorumCompatibilityMode; - this.powAlgorithm = powAlgorithm; } public ProtocolSchedule createProtocolSchedule() { @@ -105,18 +97,12 @@ public ProtocolSchedule createProtocolSchedule() { protocolSchedule, OptionalLong.of(0), MainnetProtocolSpecs.frontierDefinition( - config.getContractSizeLimit(), - config.getEvmStackSize(), - quorumCompatibilityMode, - powAlgorithm)); + config.getContractSizeLimit(), config.getEvmStackSize(), quorumCompatibilityMode)); addProtocolSpec( protocolSchedule, config.getHomesteadBlockNumber(), MainnetProtocolSpecs.homesteadDefinition( - config.getContractSizeLimit(), - config.getEvmStackSize(), - quorumCompatibilityMode, - powAlgorithm)); + config.getContractSizeLimit(), config.getEvmStackSize(), quorumCompatibilityMode)); config .getDaoForkBlock() @@ -130,16 +116,14 @@ public ProtocolSchedule createProtocolSchedule() { MainnetProtocolSpecs.daoRecoveryInitDefinition( config.getContractSizeLimit(), config.getEvmStackSize(), - quorumCompatibilityMode, - powAlgorithm)); + quorumCompatibilityMode)); addProtocolSpec( protocolSchedule, OptionalLong.of(daoBlockNumber + 1), MainnetProtocolSpecs.daoRecoveryTransitionDefinition( config.getContractSizeLimit(), config.getEvmStackSize(), - quorumCompatibilityMode, - powAlgorithm)); + quorumCompatibilityMode)); // Return to the previous protocol spec after the dao fork has completed. protocolSchedule.putMilestone(daoBlockNumber + 10, originalProtocolSpec); @@ -149,10 +133,7 @@ public ProtocolSchedule createProtocolSchedule() { protocolSchedule, config.getTangerineWhistleBlockNumber(), MainnetProtocolSpecs.tangerineWhistleDefinition( - config.getContractSizeLimit(), - config.getEvmStackSize(), - quorumCompatibilityMode, - powAlgorithm)); + config.getContractSizeLimit(), config.getEvmStackSize(), quorumCompatibilityMode)); addProtocolSpec( protocolSchedule, config.getSpuriousDragonBlockNumber(), @@ -160,8 +141,7 @@ public ProtocolSchedule createProtocolSchedule() { chainId, config.getContractSizeLimit(), config.getEvmStackSize(), - quorumCompatibilityMode, - powAlgorithm)); + quorumCompatibilityMode)); addProtocolSpec( protocolSchedule, config.getByzantiumBlockNumber(), @@ -170,8 +150,7 @@ public ProtocolSchedule createProtocolSchedule() { config.getContractSizeLimit(), config.getEvmStackSize(), isRevertReasonEnabled, - quorumCompatibilityMode, - powAlgorithm)); + quorumCompatibilityMode)); addProtocolSpec( protocolSchedule, config.getConstantinopleBlockNumber(), @@ -180,8 +159,7 @@ public ProtocolSchedule createProtocolSchedule() { config.getContractSizeLimit(), config.getEvmStackSize(), isRevertReasonEnabled, - quorumCompatibilityMode, - powAlgorithm)); + quorumCompatibilityMode)); addProtocolSpec( protocolSchedule, config.getPetersburgBlockNumber(), @@ -190,8 +168,7 @@ public ProtocolSchedule createProtocolSchedule() { config.getContractSizeLimit(), config.getEvmStackSize(), isRevertReasonEnabled, - quorumCompatibilityMode, - powAlgorithm)); + quorumCompatibilityMode)); addProtocolSpec( protocolSchedule, config.getIstanbulBlockNumber(), @@ -200,8 +177,7 @@ public ProtocolSchedule createProtocolSchedule() { config.getContractSizeLimit(), config.getEvmStackSize(), isRevertReasonEnabled, - quorumCompatibilityMode, - powAlgorithm)); + quorumCompatibilityMode)); addProtocolSpec( protocolSchedule, config.getMuirGlacierBlockNumber(), @@ -210,8 +186,7 @@ public ProtocolSchedule createProtocolSchedule() { config.getContractSizeLimit(), config.getEvmStackSize(), isRevertReasonEnabled, - quorumCompatibilityMode, - powAlgorithm)); + quorumCompatibilityMode)); if (ExperimentalEIPs.berlinEnabled) { addProtocolSpec( @@ -222,8 +197,7 @@ public ProtocolSchedule createProtocolSchedule() { config.getContractSizeLimit(), config.getEvmStackSize(), isRevertReasonEnabled, - quorumCompatibilityMode, - powAlgorithm)); + quorumCompatibilityMode)); } if (ExperimentalEIPs.eip1559Enabled) { @@ -239,8 +213,7 @@ public ProtocolSchedule createProtocolSchedule() { config.getEvmStackSize(), isRevertReasonEnabled, config, - quorumCompatibilityMode, - powAlgorithm)); + quorumCompatibilityMode)); } // specs for classic network @@ -256,8 +229,7 @@ public ProtocolSchedule createProtocolSchedule() { ClassicProtocolSpecs.classicRecoveryInitDefinition( config.getContractSizeLimit(), config.getEvmStackSize(), - quorumCompatibilityMode, - powAlgorithm)); + quorumCompatibilityMode)); protocolSchedule.putMilestone(classicBlockNumber + 1, originalProtocolSpec); }); @@ -268,8 +240,7 @@ public ProtocolSchedule createProtocolSchedule() { chainId, config.getContractSizeLimit(), config.getEvmStackSize(), - quorumCompatibilityMode, - powAlgorithm)); + quorumCompatibilityMode)); addProtocolSpec( protocolSchedule, config.getDieHardBlockNumber(), @@ -277,8 +248,7 @@ public ProtocolSchedule createProtocolSchedule() { chainId, config.getContractSizeLimit(), config.getEvmStackSize(), - quorumCompatibilityMode, - powAlgorithm)); + quorumCompatibilityMode)); addProtocolSpec( protocolSchedule, config.getGothamBlockNumber(), @@ -287,8 +257,7 @@ public ProtocolSchedule createProtocolSchedule() { config.getContractSizeLimit(), config.getEvmStackSize(), config.getEcip1017EraRounds(), - quorumCompatibilityMode, - powAlgorithm)); + quorumCompatibilityMode)); addProtocolSpec( protocolSchedule, config.getDefuseDifficultyBombBlockNumber(), @@ -297,8 +266,7 @@ public ProtocolSchedule createProtocolSchedule() { config.getContractSizeLimit(), config.getEvmStackSize(), config.getEcip1017EraRounds(), - quorumCompatibilityMode, - powAlgorithm)); + quorumCompatibilityMode)); addProtocolSpec( protocolSchedule, config.getAtlantisBlockNumber(), @@ -308,8 +276,7 @@ public ProtocolSchedule createProtocolSchedule() { config.getEvmStackSize(), isRevertReasonEnabled, config.getEcip1017EraRounds(), - quorumCompatibilityMode, - powAlgorithm)); + quorumCompatibilityMode)); addProtocolSpec( protocolSchedule, config.getAghartaBlockNumber(), @@ -319,8 +286,7 @@ public ProtocolSchedule createProtocolSchedule() { config.getEvmStackSize(), isRevertReasonEnabled, config.getEcip1017EraRounds(), - quorumCompatibilityMode, - powAlgorithm)); + quorumCompatibilityMode)); addProtocolSpec( protocolSchedule, config.getPhoenixBlockNumber(), @@ -330,8 +296,7 @@ public ProtocolSchedule createProtocolSchedule() { config.getEvmStackSize(), isRevertReasonEnabled, config.getEcip1017EraRounds(), - quorumCompatibilityMode, - powAlgorithm)); + quorumCompatibilityMode)); addProtocolSpec( protocolSchedule, config.getThanosBlockNumber(), @@ -341,8 +306,17 @@ public ProtocolSchedule createProtocolSchedule() { config.getEvmStackSize(), isRevertReasonEnabled, config.getEcip1017EraRounds(), - quorumCompatibilityMode, - powAlgorithm)); + quorumCompatibilityMode)); + addProtocolSpec( + protocolSchedule, + config.getEcip1049BlockNumber(), + ClassicProtocolSpecs.ecip1049Definition( + chainId, + config.getContractSizeLimit(), + config.getEvmStackSize(), + isRevertReasonEnabled, + config.getEcip1017EraRounds(), + quorumCompatibilityMode)); LOG.info("Protocol schedule created with milestones: {}", protocolSchedule.listMilestones()); return protocolSchedule; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java index de43689982e..4577b0894b9 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java @@ -72,7 +72,7 @@ public class ProtocolSpecBuilder { private TransactionGasBudgetCalculator gasBudgetCalculator = TransactionGasBudgetCalculator.frontier(); private BadBlockManager badBlockManager; - private PoWHasher powHasher; + private PoWHasher powHasher = PoWHasher.ETHASH_LIGHT; public ProtocolSpecBuilder gasCalculator(final Supplier gasCalculatorBuilder) { this.gasCalculatorBuilder = gasCalculatorBuilder; diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java index 78573d065b9..cea7d932d55 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/ExecutionContextTestFixture.java @@ -119,8 +119,7 @@ public ExecutionContextTestFixture build() { Function.identity(), new PrivacyParameters(), false, - genesisConfigFile.getConfigOptions().isQuorum(), - genesisConfigFile.getConfigOptions().getPowAlgorithm()) + genesisConfigFile.getConfigOptions().isQuorum()) .createProtocolSchedule(); } if (keyValueStorage == null) { diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockHeaderValidatorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockHeaderValidatorTest.java index db43882d546..bb34dc7b5a9 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockHeaderValidatorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockHeaderValidatorTest.java @@ -30,7 +30,7 @@ public final class MainnetBlockHeaderValidatorTest { @Test public void validHeaderFrontier() throws Exception { final BlockHeaderValidator headerValidator = - MainnetBlockHeaderValidator.create(PoWHasher.LIGHT) + MainnetBlockHeaderValidator.create(PoWHasher.ETHASH_LIGHT) .difficultyCalculator(MainnetDifficultyCalculators.FRONTIER) .build(); assertThat( @@ -45,7 +45,7 @@ public void validHeaderFrontier() throws Exception { @Test public void validHeaderHomestead() throws Exception { final BlockHeaderValidator headerValidator = - MainnetBlockHeaderValidator.create(PoWHasher.LIGHT) + MainnetBlockHeaderValidator.create(PoWHasher.ETHASH_LIGHT) .difficultyCalculator(MainnetDifficultyCalculators.HOMESTEAD) .build(); assertThat( @@ -60,7 +60,7 @@ public void validHeaderHomestead() throws Exception { @Test public void invalidParentHash() throws Exception { final BlockHeaderValidator headerValidator = - MainnetBlockHeaderValidator.create(PoWHasher.LIGHT) + MainnetBlockHeaderValidator.create(PoWHasher.ETHASH_LIGHT) .difficultyCalculator(MainnetDifficultyCalculators.FRONTIER) .build(); assertThat( @@ -75,7 +75,7 @@ public void invalidParentHash() throws Exception { @Test public void validHeaderByzantium() throws Exception { final BlockHeaderValidator headerValidator = - MainnetBlockHeaderValidator.create(PoWHasher.LIGHT) + MainnetBlockHeaderValidator.create(PoWHasher.ETHASH_LIGHT) .difficultyCalculator(MainnetDifficultyCalculators.BYZANTIUM) .build(); assertThat( diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/PoWSolverTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/PoWSolverTest.java index c1db4660aa6..7f4362048e9 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/PoWSolverTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/PoWSolverTest.java @@ -42,7 +42,7 @@ public void emptyHashRateAndWorkDefinitionIsReportedPriorToSolverStarting() { final PoWSolver solver = new PoWSolver( noncesToTry, - PoWHasher.LIGHT, + PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator()); @@ -131,7 +131,7 @@ public void ifInvokedTwiceProducesCorrectAnswerForSecondInvocation() final PoWSolver solver = new PoWSolver( Lists.newArrayList(expectedFirstOutput.getNonce(), 0L, expectedSecondOutput.getNonce()), - PoWHasher.LIGHT, + PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator()); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRuleTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRuleTest.java index df01e4c7c8a..6174ec3954d 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRuleTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/headervalidationrules/ProofOfWorkValidationRuleTest.java @@ -54,7 +54,7 @@ public ProofOfWorkValidationRuleTest(final long parentBlockNum, final long block parentHeader = ValidationTestUtils.readHeader(blockNum); validationRule = new ProofOfWorkValidationRule( - new EpochCalculator.DefaultEpochCalculator(), false, PoWHasher.LIGHT); + new EpochCalculator.DefaultEpochCalculator(), false, PoWHasher.ETHASH_LIGHT); } @Parameters(name = "block {1}") @@ -95,7 +95,7 @@ public void passesBlockWithOneValuedDifficulty() { final byte[] hashBuffer = new byte[64]; final Hash headerHash = validationRule.hashHeader(preHeader); - PoWHasher.LIGHT.hash( + PoWHasher.ETHASH_LIGHT.hash( hashBuffer, preHeader.getNonce(), preHeader.getNumber(), diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/VMReferenceTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/VMReferenceTest.java index 5411a3af493..1dc5c1bf85b 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/VMReferenceTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/VMReferenceTest.java @@ -17,7 +17,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assume.assumeTrue; -import org.hyperledger.besu.config.PowAlgorithm; import org.hyperledger.besu.ethereum.chain.BadBlockManager; import org.hyperledger.besu.ethereum.core.Gas; import org.hyperledger.besu.ethereum.core.MutableWorldState; @@ -99,8 +98,7 @@ protected void runTest() { final EnvironmentInformation execEnv = spec.getExec(); final ProtocolSpec protocolSpec = - MainnetProtocolSpecs.frontierDefinition( - OptionalInt.empty(), OptionalInt.empty(), false, PowAlgorithm.ETHASH) + MainnetProtocolSpecs.frontierDefinition(OptionalInt.empty(), OptionalInt.empty(), false) .privacyParameters(PrivacyParameters.DEFAULT) .privateTransactionValidatorBuilder(() -> new PrivateTransactionValidator(CHAIN_ID)) .badBlocksManager(new BadBlockManager()) 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 7c6e3a64e6a..ff0f758c6eb 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 @@ -86,8 +86,7 @@ private static ProtocolSchedule createSchedule(final GenesisConfigOptions option Function.identity(), PrivacyParameters.DEFAULT, false, - options.isQuorum(), - options.getPowAlgorithm()) + options.isQuorum()) .createProtocolSchedule(); } diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java index 5a538a6fb53..78040490be8 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java @@ -171,7 +171,7 @@ private boolean buildContext( new EpochCalculator.DefaultEpochCalculator()) : new PoWSolver( nonceGenerator, - PoWHasher.LIGHT, + PoWHasher.ETHASH_LIGHT, false, Subscribers.none(), new EpochCalculator.DefaultEpochCalculator());