Retire ECIP-1049 network (#5371)

* Remove ECIP1049 network

Signed-off-by: Diego López León <dieguitoll@gmail.com>
pull/5142/head
Diego López León 2 years ago committed by GitHub
parent d4fee1f0dd
commit 031101603b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 2
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/config/BootNodesGenesisSetupTest.java
  3. 67
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/mining/KeccakMiningAcceptanceTest.java
  4. 4
      besu/src/main/java/org/hyperledger/besu/cli/config/NetworkName.java
  5. 4
      besu/src/test/java/org/hyperledger/besu/controller/BesuControllerBuilderTest.java
  6. 9
      config/src/main/java/org/hyperledger/besu/config/GenesisConfigFile.java
  7. 24
      config/src/main/java/org/hyperledger/besu/config/GenesisConfigOptions.java
  8. 31
      config/src/main/java/org/hyperledger/besu/config/JsonGenesisConfigOptions.java
  9. 60
      config/src/main/java/org/hyperledger/besu/config/Keccak256ConfigOptions.java
  10. 4
      config/src/main/java/org/hyperledger/besu/config/PowAlgorithm.java
  11. 35
      config/src/main/java/org/hyperledger/besu/config/StubGenesisConfigOptions.java
  12. 33
      config/src/main/resources/ecip1049_dev.json
  13. 21
      config/src/test/java/org/hyperledger/besu/config/GenesisConfigOptionsTest.java
  14. 3
      config/src/test/resources/all_forks.json
  15. 2
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/AdminNodeInfoTest.java
  16. 9
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyCalculators.java
  17. 28
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java
  18. 57
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/KeccakHasher.java
  19. 10
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecFactory.java
  20. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java
  21. 3
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java
  22. 33
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedProtocolScheduleTest.java
  23. 135
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/KeccakHasherTest.java

@ -7,6 +7,7 @@
- Remove GoQuorum-compatible privacy feature [#5303](https://github.com/hyperledger/besu/pull/5303)
- Remove launcher command line utility [#5355](https://github.com/hyperledger/besu/pull/5355)
- Remove deprecated `tx-pool-future-max-by-account` option, see instead: `tx-pool-limit-by-account-percentage` [#5361](https://github.com/hyperledger/besu/pull/5361)
- Default configuration for the deprecated ECIP-1049 network has been removed from the CLI network list [#5371](https://github.com/hyperledger/besu/pull/5371)
### Additions and Improvements
- Update most dependencies to latest version [#5269](https://github.com/hyperledger/besu/pull/5269)

@ -113,7 +113,7 @@ public class BootNodesGenesisSetupTest extends AcceptanceTestBase {
(nodes) ->
Optional.of(
String.format(
"{\"config\": {\"keccak256\": {}, \"discovery\": { \"bootnodes\": [\"enode://%s@127.0.0.1:%d\"]}}, \"gasLimit\": \"0x1\", \"difficulty\": \"0x1\"}",
"{\"config\": {\"ethash\": {}, \"discovery\": { \"bootnodes\": [\"enode://%s@127.0.0.1:%d\"]}}, \"gasLimit\": \"0x1\", \"difficulty\": \"0x1\"}",
peerPublicKey.toString().substring(2), peerP2pBindingPort)))
.bootnodeEligible(false)
.jsonRpcEnabled()

@ -1,67 +0,0 @@
/*
* 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.tests.acceptance.mining;
import org.hyperledger.besu.cli.config.NetworkName;
import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase;
import org.hyperledger.besu.tests.acceptance.dsl.account.Account;
import org.hyperledger.besu.tests.acceptance.dsl.node.Node;
import org.hyperledger.besu.tests.acceptance.dsl.node.configuration.BesuNodeConfigurationBuilder;
import org.junit.Before;
import org.junit.Test;
public class KeccakMiningAcceptanceTest extends AcceptanceTestBase {
private Node minerNode;
@Before
public void setUp() throws Exception {
minerNode =
besu.create(
new BesuNodeConfigurationBuilder()
.name("miner1")
.devMode(false)
.network(NetworkName.ECIP1049_DEV)
.miningEnabled()
.jsonRpcEnabled()
.webSocketEnabled()
.build());
cluster.start(minerNode);
}
@Test
public void shouldMineTransactions() {
final Account sender = accounts.createAccount("account1");
final Account receiver = accounts.createAccount("account2");
minerNode.execute(accountTransactions.createTransfer(sender, 50));
cluster.verify(sender.balanceEquals(50));
minerNode.execute(accountTransactions.createIncrementalTransfers(sender, receiver, 1));
cluster.verify(receiver.balanceEquals(1));
minerNode.execute(accountTransactions.createIncrementalTransfers(sender, receiver, 2));
cluster.verify(receiver.balanceEquals(3));
minerNode.execute(accountTransactions.createIncrementalTransfers(sender, receiver, 3));
cluster.verify(receiver.balanceEquals(6));
minerNode.execute(accountTransactions.createIncrementalTransfers(sender, receiver, 4));
cluster.verify(receiver.balanceEquals(10));
minerNode.execute(accountTransactions.createIncrementalTransfers(sender, receiver, 5));
cluster.verify(receiver.balanceEquals(15));
}
}

@ -40,9 +40,7 @@ public enum NetworkName {
/** Kotti network name. */
KOTTI("/kotti.json", BigInteger.valueOf(6)),
/** Mordor network name. */
MORDOR("/mordor.json", BigInteger.valueOf(7)),
/** Ecip 1049 dev network name. */
ECIP1049_DEV("/ecip1049_dev.json", BigInteger.valueOf(2021));
MORDOR("/mordor.json", BigInteger.valueOf(7));
private final String genesisFile;
private final BigInteger networkId;

@ -27,7 +27,6 @@ import org.hyperledger.besu.config.CheckpointConfigOptions;
import org.hyperledger.besu.config.EthashConfigOptions;
import org.hyperledger.besu.config.GenesisConfigFile;
import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.config.Keccak256ConfigOptions;
import org.hyperledger.besu.cryptoservices.NodeKey;
import org.hyperledger.besu.cryptoservices.NodeKeyUtils;
import org.hyperledger.besu.datatypes.Hash;
@ -82,7 +81,6 @@ public class BesuControllerBuilderTest {
@Mock GenesisConfigOptions genesisConfigOptions;
@Mock EthashConfigOptions ethashConfigOptions;
@Mock CheckpointConfigOptions checkpointConfigOptions;
@Mock Keccak256ConfigOptions keccak256ConfigOptions;
@Mock SynchronizerConfiguration synchronizerConfiguration;
@Mock EthProtocolConfiguration ethProtocolConfiguration;
@Mock MiningParameters miningParameters;
@ -114,8 +112,6 @@ public class BesuControllerBuilderTest {
when(genesisConfigOptions.getEthashConfigOptions()).thenReturn(ethashConfigOptions);
when(genesisConfigOptions.getCheckpointOptions()).thenReturn(checkpointConfigOptions);
when(ethashConfigOptions.getFixedDifficulty()).thenReturn(OptionalLong.empty());
when(genesisConfigOptions.getKeccak256ConfigOptions()).thenReturn(keccak256ConfigOptions);
when(keccak256ConfigOptions.getFixedDifficulty()).thenReturn(OptionalLong.empty());
when(storageProvider.getStorageBySegmentIdentifier(any()))
.thenReturn(new InMemoryKeyValueStorage());
when(storageProvider.createBlockchainStorage(any()))

@ -81,15 +81,6 @@ public class GenesisConfigFile {
return genesisFileFromResources("/dev.json");
}
/**
* Ecip 1049 dev genesis config file.
*
* @return the genesis config file
*/
public static GenesisConfigFile ecip1049dev() {
return genesisFileFromResources("/ecip1049_dev.json");
}
/**
* Genesis file from resources genesis config file.
*

@ -36,13 +36,6 @@ public interface GenesisConfigOptions {
*/
boolean isEthHash();
/**
* Is keccak 256 boolean.
*
* @return the boolean
*/
boolean isKeccak256();
/**
* Is ibft legacy boolean (NOTE this is a deprecated feature).
*
@ -129,13 +122,6 @@ public interface GenesisConfigOptions {
*/
EthashConfigOptions getEthashConfigOptions();
/**
* Gets keccak 256 config options.
*
* @return the keccak 256 config options
*/
Keccak256ConfigOptions getKeccak256ConfigOptions();
/**
* Gets homestead block number.
*
@ -425,16 +411,6 @@ public interface GenesisConfigOptions {
*/
OptionalLong getMystiqueBlockNumber();
/**
* 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 <a
* href="https://ecips.ethereumclassic.org/ECIPs/ecip-1049">https://ecips.ethereumclassic.org/ECIPs/ecip-1049</a>
*/
OptionalLong getEcip1049BlockNumber();
/**
* Gets chain id.
*

@ -38,7 +38,6 @@ import org.apache.tuweni.units.bigints.UInt256;
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";
@ -109,8 +108,6 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions {
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 (isQbft()) {
@ -127,11 +124,6 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions {
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);
@ -195,13 +187,6 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions {
.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;
@ -388,11 +373,6 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions {
return getOptionalLong("mystiqueblock");
}
@Override
public OptionalLong getEcip1049BlockNumber() {
return getOptionalLong("ecip1049block");
}
@Override
public Optional<BigInteger> getChainId() {
return getOptionalBigInteger("chainid");
@ -425,9 +405,7 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions {
@Override
public PowAlgorithm getPowAlgorithm() {
return isEthHash()
? PowAlgorithm.ETHASH
: isKeccak256() ? PowAlgorithm.KECCAK256 : PowAlgorithm.UNSUPPORTED;
return isEthHash() ? PowAlgorithm.ETHASH : PowAlgorithm.UNSUPPORTED;
}
@Override
@ -479,7 +457,6 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions {
getThanosBlockNumber().ifPresent(l -> builder.put("thanosBlock", l));
getMagnetoBlockNumber().ifPresent(l -> builder.put("magnetoBlock", l));
getMystiqueBlockNumber().ifPresent(l -> builder.put("mystiqueBlock", l));
getEcip1049BlockNumber().ifPresent(l -> builder.put("ecip1049Block", l));
getContractSizeLimit().ifPresent(l -> builder.put("contractSizeLimit", l));
getEvmStackSize().ifPresent(l -> builder.put("evmstacksize", l));
@ -491,9 +468,6 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions {
if (isEthHash()) {
builder.put("ethash", getEthashConfigOptions().asMap());
}
if (isKeccak256()) {
builder.put("keccak256", getKeccak256ConfigOptions().asMap());
}
if (isIbft2()) {
builder.put("ibft2", getBftConfigOptions().asMap());
}
@ -593,8 +567,7 @@ public class JsonGenesisConfigOptions implements GenesisConfigOptions {
getPhoenixBlockNumber(),
getThanosBlockNumber(),
getMagnetoBlockNumber(),
getMystiqueBlockNumber(),
getEcip1049BlockNumber());
getMystiqueBlockNumber());
// when adding forks add an entry to ${REPO_ROOT}/config/src/test/resources/all_forks.json
return forkBlockNumbers

@ -1,60 +0,0 @@
/*
* 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;
/** The Keccak256 config options. */
public class Keccak256ConfigOptions {
/** The constant DEFAULT. */
public static final Keccak256ConfigOptions DEFAULT =
new Keccak256ConfigOptions(JsonUtil.createEmptyObjectNode());
private final ObjectNode keccak256ConfigRoot;
/**
* Instantiates a new Keccak256 config options.
*
* @param keccak256ConfigRoot the keccak 256 config root
*/
Keccak256ConfigOptions(final ObjectNode keccak256ConfigRoot) {
this.keccak256ConfigRoot = keccak256ConfigRoot;
}
/**
* Gets fixed difficulty.
*
* @return the fixed difficulty
*/
public OptionalLong getFixedDifficulty() {
return JsonUtil.getLong(keccak256ConfigRoot, "fixeddifficulty");
}
/**
* As map.
*
* @return the map
*/
Map<String, Object> asMap() {
final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
getFixedDifficulty().ifPresent(l -> builder.put("fixeddifficulty", l));
return builder.build();
}
}

@ -19,9 +19,7 @@ public enum PowAlgorithm {
/** Unsupported pow algorithm. */
UNSUPPORTED,
/** Ethash pow algorithm. */
ETHASH,
/** Keccak 256 pow algorithm. */
KECCAK256;
ETHASH;
/**
* From string pow algorithm.

@ -65,7 +65,6 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions, Cloneable
private OptionalLong thanosBlockNumber = OptionalLong.empty();
private OptionalLong magnetoBlockNumber = OptionalLong.empty();
private OptionalLong mystiqueBlockNumber = OptionalLong.empty();
private OptionalLong ecip1049BlockNumber = OptionalLong.empty();
private Optional<BigInteger> chainId = Optional.empty();
private OptionalInt contractSizeLimit = OptionalInt.empty();
private OptionalInt stackSizeLimit = OptionalInt.empty();
@ -96,11 +95,6 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions, Cloneable
return true;
}
@Override
public boolean isKeccak256() {
return false;
}
@Override
public boolean isIbftLegacy() {
return false;
@ -151,11 +145,6 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions, Cloneable
return EthashConfigOptions.DEFAULT;
}
@Override
public Keccak256ConfigOptions getKeccak256ConfigOptions() {
return Keccak256ConfigOptions.DEFAULT;
}
@Override
public OptionalLong getHomesteadBlockNumber() {
return homesteadBlockNumber;
@ -321,11 +310,6 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions, Cloneable
return mystiqueBlockNumber;
}
@Override
public OptionalLong getEcip1049BlockNumber() {
return ecip1049BlockNumber;
}
@Override
public OptionalInt getContractSizeLimit() {
return contractSizeLimit;
@ -384,7 +368,6 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions, Cloneable
getThanosBlockNumber().ifPresent(l -> builder.put("thanosBlock", l));
getMagnetoBlockNumber().ifPresent(l -> builder.put("magnetoBlock", l));
getMystiqueBlockNumber().ifPresent(l -> builder.put("mystiqueBlock", l));
getEcip1049BlockNumber().ifPresent(l -> builder.put("ecip1049Block", l));
getContractSizeLimit().ifPresent(l -> builder.put("contractSizeLimit", l));
getEvmStackSize().ifPresent(l -> builder.put("evmStackSize", l));
@ -394,9 +377,6 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions, Cloneable
if (isEthHash()) {
builder.put("ethash", getEthashConfigOptions().asMap());
}
if (isKeccak256()) {
builder.put("keccak256", getKeccak256ConfigOptions().asMap());
}
if (isIbft2()) {
builder.put("ibft2", getBftConfigOptions().asMap());
}
@ -420,9 +400,7 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions, Cloneable
@Override
public PowAlgorithm getPowAlgorithm() {
return isEthHash()
? PowAlgorithm.ETHASH
: isKeccak256() ? PowAlgorithm.KECCAK256 : PowAlgorithm.UNSUPPORTED;
return isEthHash() ? PowAlgorithm.ETHASH : PowAlgorithm.UNSUPPORTED;
}
@Override
@ -820,17 +798,6 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions, Cloneable
return this;
}
/**
* Ecip 1049 stub genesis config options.
*
* @param blockNumber the block number
* @return the stub genesis config options
*/
public StubGenesisConfigOptions ecip1049(final long blockNumber) {
ecip1049BlockNumber = OptionalLong.of(blockNumber);
return this;
}
/**
* Chain id stub genesis config options.
*

@ -1,33 +0,0 @@
{
"config": {
"chainId": 2021,
"ecip1049Block": 0,
"keccak256": {
"fixeddifficulty": 10000
}
},
"nonce": "0x42",
"timestamp": "0x0",
"extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
"gasLimit": "0x1fffffffffffff",
"difficulty": "0x1000000",
"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"
}
}
}

@ -36,25 +36,12 @@ public class GenesisConfigOptionsTest {
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 shouldUseIbft2WhenIbft2InConfig() {
final GenesisConfigOptions config = fromConfigOptions(singletonMap("ibft2", emptyMap()));
@ -206,13 +193,6 @@ public class GenesisConfigOptionsTest {
assertThat(config.getExperimentalEipsTime()).hasValue(1337);
}
@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());
@ -234,7 +214,6 @@ public class GenesisConfigOptionsTest {
assertThat(config.getCancunTime()).isEmpty();
assertThat(config.getFutureEipsTime()).isEmpty();
assertThat(config.getExperimentalEipsTime()).isEmpty();
assertThat(config.getEcip1049BlockNumber()).isEmpty();
}
@Test

@ -27,7 +27,6 @@
"phoenixBlock": 108,
"thanosBlock": 109,
"magnetoBlock": 110,
"mystiqueBlock": 111,
"ecip1049Block": 199
"mystiqueBlock": 111
}
}

@ -374,7 +374,6 @@ public class AdminNodeInfoTest {
.phoenix(8)
.thanos(9)
.magneto(10)
.ecip1049(11)
.mystique(12);
final AdminNodeInfo methodClassic =
@ -401,7 +400,6 @@ public class AdminNodeInfoTest {
"phoenixBlock", 8L,
"thanosBlock", 9L,
"magnetoBlock", 10L));
expectedConfig.put("ecip1049Block", 11L);
expectedConfig.put("mystiqueBlock", 12L);
final JsonRpcResponse response = methodClassic.response(request);

@ -29,16 +29,11 @@ public class FixedDifficultyCalculators {
public static final int DEFAULT_DIFFICULTY = 100;
public static boolean isFixedDifficultyInConfig(final GenesisConfigOptions config) {
return config.getEthashConfigOptions().getFixedDifficulty().isPresent()
|| config.getKeccak256ConfigOptions().getFixedDifficulty().isPresent();
return config.getEthashConfigOptions().getFixedDifficulty().isPresent();
}
public static DifficultyCalculator calculator(final GenesisConfigOptions config) {
long difficulty =
config
.getEthashConfigOptions()
.getFixedDifficulty()
.orElseGet(() -> config.getKeccak256ConfigOptions().getFixedDifficulty().getAsLong());
long difficulty = config.getEthashConfigOptions().getFixedDifficulty().getAsLong();
return (time, parent, context) -> BigInteger.valueOf(difficulty);
}
}

@ -275,34 +275,6 @@ public class ClassicProtocolSpecs {
result.isSuccessful() ? 1 : 0, gasUsed, result.getLogs(), result.getRevertReason());
}
public static ProtocolSpecBuilder ecip1049Definition(
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
final OptionalInt configStackSizeLimit,
final boolean enableRevertReason,
final OptionalLong ecip1017EraRounds,
final EvmConfiguration evmConfiguration) {
return thanosDefinition(
chainId,
configContractSizeLimit,
configStackSizeLimit,
enableRevertReason,
ecip1017EraRounds,
evmConfiguration)
.blockHeaderValidatorBuilder(
feeMarket ->
MainnetBlockHeaderValidator.createPgaBlockHeaderValidator(
new EpochCalculator.Ecip1099EpochCalculator(),
powHasher(PowAlgorithm.KECCAK256)))
.ommerHeaderValidatorBuilder(
feeMarket ->
MainnetBlockHeaderValidator.createLegacyFeeMarketOmmerValidator(
new EpochCalculator.Ecip1099EpochCalculator(),
powHasher(PowAlgorithm.KECCAK256)))
.powHasher(powHasher(PowAlgorithm.KECCAK256))
.name("ecip1049");
}
public static ProtocolSpecBuilder magnetoDefinition(
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,

@ -1,57 +0,0 @@
/*
* 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.ethereum.mainnet;
import org.hyperledger.besu.datatypes.Hash;
import java.security.MessageDigest;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.bouncycastle.jcajce.provider.digest.Keccak;
/**
* Hasher for Keccak-256 PoW.
*
* <p>Block is valid if keccak256(keccak256(rlp(unsealed header)), nonce) is less than or equal to
* 2^256 / difficulty mixhash = keccak256(rlp(unsealed header)) which is stored in the block.
* Currently this process is ethash(rlp(unsealed header)) So to validate a block we check
* keccak256(mixhash, nonce) is less than or equal to 2^256 / difficulty
*/
public class KeccakHasher implements PoWHasher {
public static final KeccakHasher KECCAK256 = new KeccakHasher();
private KeccakHasher() {}
private static final ThreadLocal<MessageDigest> KECCAK_256 =
ThreadLocal.withInitial(Keccak.Digest256::new);
@Override
public PoWSolution hash(
final long nonce,
final long number,
final EpochCalculator epochCalc,
final Bytes prePowHash) {
MessageDigest digest = KECCAK_256.get();
digest.update(prePowHash.toArrayUnsafe());
digest.update(Bytes.ofUnsignedLong(nonce).toArrayUnsafe());
Bytes32 solution = Bytes32.wrap(digest.digest());
Hash mixHash = Hash.wrap(solution);
return new PoWSolution(nonce, mixHash, solution, prePowHash);
}
}

@ -287,14 +287,4 @@ public class MainnetProtocolSpecFactory {
ecip1017EraRounds,
evmConfiguration);
}
public ProtocolSpecBuilder ecip1049Definition() {
return ClassicProtocolSpecs.ecip1049Definition(
chainId,
contractSizeLimit,
evmStackSize,
isRevertReasonEnabled,
ecip1017EraRounds,
evmConfiguration);
}
}

@ -175,8 +175,6 @@ public abstract class MainnetProtocolSpecs {
switch (powAlgorithm) {
case ETHASH:
return PoWHasher.ETHASH_LIGHT;
case KECCAK256:
return KeccakHasher.KECCAK256;
case UNSUPPORTED:
default:
return PoWHasher.UNSUPPORTED;

@ -186,8 +186,7 @@ public class ProtocolScheduleBuilder extends AbstractProtocolScheduleBuilder {
blockNumberMilestone(config.getPhoenixBlockNumber(), specFactory.phoenixDefinition()),
blockNumberMilestone(config.getThanosBlockNumber(), specFactory.thanosDefinition()),
blockNumberMilestone(config.getMagnetoBlockNumber(), specFactory.magnetoDefinition()),
blockNumberMilestone(config.getMystiqueBlockNumber(), specFactory.mystiqueDefinition()),
blockNumberMilestone(config.getEcip1049BlockNumber(), specFactory.ecip1049Definition()));
blockNumberMilestone(config.getMystiqueBlockNumber(), specFactory.mystiqueDefinition()));
}
@Override

@ -59,39 +59,6 @@ public class FixedProtocolScheduleTest {
.isEqualTo(FixedDifficultyCalculators.DEFAULT_DIFFICULTY);
}
@Test
public void reportedDifficultyForAllBlocksIsAFixedValueKeccak() {
final ProtocolSchedule schedule =
FixedDifficultyProtocolSchedule.create(
GenesisConfigFile.ecip1049dev().getConfigOptions(), EvmConfiguration.DEFAULT);
final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture();
final BlockHeader parentHeader = headerBuilder.number(1).buildHeader();
assertThat(
schedule
.getByBlockHeader(blockHeader(0))
.getDifficultyCalculator()
.nextDifficulty(1, parentHeader, null))
.isEqualTo(10000);
assertThat(
schedule
.getByBlockHeader(blockHeader(500))
.getDifficultyCalculator()
.nextDifficulty(1, parentHeader, null))
.isEqualTo(10000);
assertThat(
schedule
.getByBlockHeader(blockHeader(500_000))
.getDifficultyCalculator()
.nextDifficulty(1, parentHeader, null))
.isEqualTo(10000);
}
private BlockHeader blockHeader(final long number) {
return new BlockHeaderTestFixture().number(number).buildHeader();
}

@ -1,135 +0,0 @@
/*
* 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.ethereum.mainnet;
import static org.assertj.core.api.Assertions.assertThat;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.DataGas;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.core.Difficulty;
import org.hyperledger.besu.ethereum.core.SealableBlockHeader;
import org.hyperledger.besu.evm.log.LogsBloomFilter;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.junit.Test;
public class KeccakHasherTest {
private static class KeccakSealableBlockHeader extends SealableBlockHeader {
protected KeccakSealableBlockHeader(
final Hash parentHash,
final Hash ommersHash,
final Address coinbase,
final Hash stateRoot,
final Hash transactionsRoot,
final Hash receiptsRoot,
final LogsBloomFilter logsBloom,
final Difficulty difficulty,
final long number,
final long gasLimit,
final long gasUsed,
final long timestamp,
final Bytes extraData,
final Wei baseFee,
final Bytes32 random,
final Hash withdrawalsRoot,
final DataGas excessDataGas,
final Hash depositsRoot) {
super(
parentHash,
ommersHash,
coinbase,
stateRoot,
transactionsRoot,
receiptsRoot,
logsBloom,
difficulty,
number,
gasLimit,
gasUsed,
timestamp,
extraData,
baseFee,
random,
withdrawalsRoot,
excessDataGas,
depositsRoot);
}
}
@Test
public void testHasher() {
PoWSolution solution =
KeccakHasher.KECCAK256.hash(
12345678L,
42L,
new EpochCalculator.DefaultEpochCalculator(),
Bytes.fromHexString(
"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"));
assertThat(solution.getMixHash())
.isEqualTo(
Bytes.fromHexString(
"0xeffd292d6666dba4d6a4c221dd6d4b34b4ec3972a4cb0d944a8a8936cceca713"));
}
@Test
public void testHasherFromBlock() {
KeccakSealableBlockHeader header =
new KeccakSealableBlockHeader(
Hash.fromHexString(
"0xad22d4d8f0e94032cb32e86027e0a5533d945ed95088264e91dd71e4fbaebeda"),
Hash.fromHexString(
"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"),
Address.fromHexString("0x6A9ECfa04e99726eC105517AC7ae1aba550BeA6c"),
Hash.fromHexString(
"0x43e3325393fbc583a5a0b56e98073fb81e82d992b52406a79d662b690a4d2753"),
Hash.fromHexString(
"0x40c339f7715932ec591d8c0c588bacfaed9bddc7519a1e6e87cf45be639de810"),
Hash.fromHexString(
"0xeb1e644436f93be8a9938dfe598cb7fd729f9d201b6f7c0695bee883b3ea6a5b"),
LogsBloomFilter.fromHexString(
"0x0800012104000104c00400108000400000003000000040008400000002800100000a00000000000001010401040001000001002000000000020020080000240200000000012260010000084800420200040000100000030800802000112020001a200800020000000000500010100a00000000020401480000000010001048000011104800c002410000000010800000000014200040000400000000000000600020c00000004010080000000020100200000200000800001024c4000000080100004002004808000102920408810000002000008000000008000120400020008200d80000000010010000008028004000010000008220000200000100100800"),
Difficulty.of(3963642329L),
4156209L,
8000000L,
7987824L,
1538483791L,
Bytes.fromHexString("0xd88301080f846765746888676f312e31302e31856c696e7578"),
null,
null,
null,
null,
null);
PoWSolution result =
KeccakHasher.KECCAK256.hash(
Bytes.fromHexString("0xf245822d3412da7f").toLong(),
4156209L,
new EpochCalculator.DefaultEpochCalculator(),
EthHash.hashHeader(header));
assertThat(result.getMixHash())
.isEqualTo(
Bytes.fromHexString(
"0xd033f82e170ff16640e902fad569243c39bce9e4da948ccc298c541b34cd263b"));
}
}
Loading…
Cancel
Save