diff --git a/config/src/main/java/org/hyperledger/besu/config/GenesisConfigFile.java b/config/src/main/java/org/hyperledger/besu/config/GenesisConfigFile.java index 6b8b4e4fe5b..815e9e4ea0f 100644 --- a/config/src/main/java/org/hyperledger/besu/config/GenesisConfigFile.java +++ b/config/src/main/java/org/hyperledger/besu/config/GenesisConfigFile.java @@ -67,6 +67,15 @@ public static GenesisConfigFile development() { } } + public static GenesisConfigFile ecip1049dev() { + try { + return fromConfig( + Resources.toString(GenesisConfigFile.class.getResource("/ecip1049_dev.json"), UTF_8)); + } catch (final IOException e) { + throw new IllegalStateException(e); + } + } + public static GenesisConfigFile fromConfig(final String jsonString) { return fromConfig(JsonUtil.objectNodeFromString(jsonString, false)); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyCalculators.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyCalculators.java index ceaf06e3530..7c64b570b0e 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyCalculators.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedDifficultyCalculators.java @@ -29,11 +29,16 @@ public class FixedDifficultyCalculators { public static final int DEFAULT_DIFFICULTY = 100; public static boolean isFixedDifficultyInConfig(final GenesisConfigOptions config) { - return config.getEthashConfigOptions().getFixedDifficulty().isPresent(); + return config.getEthashConfigOptions().getFixedDifficulty().isPresent() + || config.getKeccak256ConfigOptions().getFixedDifficulty().isPresent(); } public static DifficultyCalculator calculator(final GenesisConfigOptions config) { - long difficulty = config.getEthashConfigOptions().getFixedDifficulty().getAsLong(); + long difficulty = + config + .getEthashConfigOptions() + .getFixedDifficulty() + .orElseGet(() -> config.getKeccak256ConfigOptions().getFixedDifficulty().getAsLong()); return (time, parent, context) -> BigInteger.valueOf(difficulty); } } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedProtocolScheduleTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedProtocolScheduleTest.java index 4204a5e4d76..c03286af04b 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedProtocolScheduleTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/difficulty/fixed/FixedProtocolScheduleTest.java @@ -56,4 +56,36 @@ public void reportedDifficultyForAllBlocksIsAFixedValue() { .nextDifficulty(1, parentHeader, null)) .isEqualTo(FixedDifficultyCalculators.DEFAULT_DIFFICULTY); } + + @Test + public void reportedDifficultyForAllBlocksIsAFixedValueKeccak() { + + final ProtocolSchedule schedule = + FixedDifficultyProtocolSchedule.create(GenesisConfigFile.ecip1049dev().getConfigOptions()); + + final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture(); + + final BlockHeader parentHeader = headerBuilder.number(1).buildHeader(); + + assertThat( + schedule + .getByBlockNumber(0) + .getDifficultyCalculator() + .nextDifficulty(1, parentHeader, null)) + .isEqualTo(FixedDifficultyCalculators.DEFAULT_DIFFICULTY); + + assertThat( + schedule + .getByBlockNumber(500) + .getDifficultyCalculator() + .nextDifficulty(1, parentHeader, null)) + .isEqualTo(FixedDifficultyCalculators.DEFAULT_DIFFICULTY); + + assertThat( + schedule + .getByBlockNumber(500_000) + .getDifficultyCalculator() + .nextDifficulty(1, parentHeader, null)) + .isEqualTo(FixedDifficultyCalculators.DEFAULT_DIFFICULTY); + } }