diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index 8131eda92dd..48dbe52da23 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -1796,7 +1796,7 @@ private void configureNativeLibs() { if (kzgTrustedSetupFile != null) { KZGPointEvalPrecompiledContract.init(kzgTrustedSetupFile); } else { - KZGPointEvalPrecompiledContract.init(network.name()); + KZGPointEvalPrecompiledContract.init(); } } else if (kzgTrustedSetupFile != null) { throw new ParameterException( diff --git a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/GenerateBlockchainConfig.java b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/GenerateBlockchainConfig.java index 0fe2b2f2cf8..3dc02f0f2bf 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/GenerateBlockchainConfig.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/subcommands/operator/GenerateBlockchainConfig.java @@ -61,7 +61,7 @@ @Command( name = "generate-blockchain-config", - description = "Generates node keypairs and genesis file with RLP encoded extra data.", + description = "Generate node keypairs and genesis file with RLP encoded extra data.", mixinStandardHelpOptions = true, versionProvider = VersionProvider.class) class GenerateBlockchainConfig implements Runnable { diff --git a/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java b/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java index 7a83cd87515..a6c0c4919c8 100644 --- a/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java +++ b/besu/src/test/java/org/hyperledger/besu/ForkIdsNetworkConfigTest.java @@ -45,183 +45,173 @@ import com.google.common.collect.Streams; import org.apache.tuweni.bytes.Bytes; -import org.junit.Test; -import org.junit.experimental.runners.Enclosed; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -@RunWith(Enclosed.class) +@RunWith(Parameterized.class) public class ForkIdsNetworkConfigTest { - public static class NotParameterized { - @Test - public void testFromRaw() { - final ForkId forkId = new ForkId(Bytes.ofUnsignedInt(0xfe3366e7L), 1735371L); - final List> forkIdAsBytesList = List.of(forkId.getForkIdAsBytesList()); - assertThat(ForkId.fromRawForkId(forkIdAsBytesList).get()).isEqualTo(forkId); - } + @Parameterized.Parameter public NetworkName chainName; + + @Parameterized.Parameter(1) + public List expectedForkIds; + + @Parameterized.Parameters(name = "{0}") + public static Collection parameters() { + return List.of( + new Object[] { + NetworkName.SEPOLIA, + List.of( + new ForkId(Bytes.ofUnsignedInt(0xfe3366e7L), 1735371L), + new ForkId(Bytes.ofUnsignedInt(0xb96cbd13L), 1677557088L), + new ForkId(Bytes.ofUnsignedInt(0xf7f9bc08L), 1706655072L), + new ForkId(Bytes.ofUnsignedInt(0x88cf81d9L), 0L), + new ForkId(Bytes.ofUnsignedInt(0x88cf81d9L), 0L)) + }, + new Object[] { + NetworkName.HOLESKY, + List.of( + new ForkId(Bytes.ofUnsignedInt(0xc61a6098L), 1696000704L), + new ForkId(Bytes.ofUnsignedInt(0xfd4f016bL), 1707305664L), + new ForkId(Bytes.ofUnsignedInt(0x9b192ad0L), 0L), + new ForkId(Bytes.ofUnsignedInt(0x9b192ad0L), 0L)) + }, + new Object[] { + NetworkName.GOERLI, + List.of( + new ForkId(Bytes.ofUnsignedInt(0xa3f5ab08L), 1561651L), + new ForkId(Bytes.ofUnsignedInt(0xc25efa5cL), 4460644L), + new ForkId(Bytes.ofUnsignedInt(0x757a1c47L), 5062605L), + new ForkId(Bytes.ofUnsignedInt(0xb8c6299dL), 1678832736L), + new ForkId(Bytes.ofUnsignedInt(0xf9843abfL), 1705473120), + new ForkId(Bytes.ofUnsignedInt(0x70cc14e2L), 0L), + new ForkId(Bytes.ofUnsignedInt(0x70cc14e2L), 0L)) + }, + new Object[] { + NetworkName.MAINNET, + List.of( + new ForkId(Bytes.ofUnsignedInt(0xfc64ec04L), 1150000L), + new ForkId(Bytes.ofUnsignedInt(0x97c2c34cL), 1920000L), + new ForkId(Bytes.ofUnsignedInt(0x91d1f948L), 2463000L), + new ForkId(Bytes.ofUnsignedInt(0x91d1f948L), 2463000L), + new ForkId(Bytes.ofUnsignedInt(0x91d1f948L), 2463000L), + new ForkId(Bytes.ofUnsignedInt(0x7a64da13L), 2675000L), + new ForkId(Bytes.ofUnsignedInt(0x3edd5b10L), 4370000L), + new ForkId(Bytes.ofUnsignedInt(0xa00bc324L), 7280000L), + new ForkId(Bytes.ofUnsignedInt(0x668db0afL), 9069000L), + new ForkId(Bytes.ofUnsignedInt(0x879d6e30L), 9200000L), + new ForkId(Bytes.ofUnsignedInt(0xe029e991L), 12244000L), + new ForkId(Bytes.ofUnsignedInt(0xeb440f6L), 12965000L), + new ForkId(Bytes.ofUnsignedInt(0xb715077dL), 13773000L), + new ForkId(Bytes.ofUnsignedInt(0x20c327fcL), 15050000L), + new ForkId(Bytes.ofUnsignedInt(0xf0afd0e3L), 1681338455L), + new ForkId(Bytes.ofUnsignedInt(0xdce96c2dL), 0L), + new ForkId(Bytes.ofUnsignedInt(0xdce96c2dL), 0L)) + }, + new Object[] { + NetworkName.MORDOR, + List.of( + new ForkId(Bytes.ofUnsignedInt(0x175782aaL), 301243L), + new ForkId(Bytes.ofUnsignedInt(0x604f6ee1L), 999983L), + new ForkId(Bytes.ofUnsignedInt(0xf42f5539L), 2520000L), + new ForkId(Bytes.ofUnsignedInt(0x66b5c286L), 3985893), + new ForkId(Bytes.ofUnsignedInt(0x92b323e0L), 5520000L), + new ForkId(Bytes.ofUnsignedInt(0x8c9b1797L), 9957000L), + new ForkId(Bytes.ofUnsignedInt(0x3a6b00d7L), 0L), + new ForkId(Bytes.ofUnsignedInt(0x3a6b00d7L), 0L)) + }, + new Object[] { + NetworkName.CLASSIC, + List.of( + new ForkId(Bytes.ofUnsignedInt(0xfc64ec04L), 1150000L), + new ForkId(Bytes.ofUnsignedInt(0x97c2c34cL), 2500000L), + new ForkId(Bytes.ofUnsignedInt(0x97c2c34cL), 2500000L), + new ForkId(Bytes.ofUnsignedInt(0x97c2c34cL), 2500000L), + new ForkId(Bytes.ofUnsignedInt(0xdb06803fL), 3000000L), + new ForkId(Bytes.ofUnsignedInt(0xaff4bed4L), 5000000L), + new ForkId(Bytes.ofUnsignedInt(0xf79a63c0L), 5900000L), + new ForkId(Bytes.ofUnsignedInt(0x744899d6L), 8772000L), + new ForkId(Bytes.ofUnsignedInt(0x518b59c6L), 9573000L), + new ForkId(Bytes.ofUnsignedInt(0x7ba22882L), 10500839L), + new ForkId(Bytes.ofUnsignedInt(0x9007bfccL), 11700000L), + new ForkId(Bytes.ofUnsignedInt(0xdb63a1caL), 13189133), + new ForkId(Bytes.ofUnsignedInt(0x0f6bf187L), 14525000L), + new ForkId(Bytes.ofUnsignedInt(0x7fd1bb25L), 19250000L), + new ForkId(Bytes.ofUnsignedInt(0xbe46d57cL), 0L), + new ForkId(Bytes.ofUnsignedInt(0xbe46d57cL), 0L)) + }); } - @RunWith(Parameterized.class) - public static class ParametrizedForkIdTest { - - @Parameterized.Parameter public NetworkName chainName; - - @Parameterized.Parameter(1) - public List expectedForkIds; - - @Parameterized.Parameters(name = "{0}") - public static Collection parameters() { - return List.of( - new Object[] { - NetworkName.SEPOLIA, - List.of( - new ForkId(Bytes.ofUnsignedInt(0xfe3366e7L), 1735371L), - new ForkId(Bytes.ofUnsignedInt(0xb96cbd13L), 1677557088L), - new ForkId(Bytes.ofUnsignedInt(0xf7f9bc08L), 0L), - new ForkId(Bytes.ofUnsignedInt(0xf7f9bc08L), 0L)) - }, - new Object[] { - NetworkName.HOLESKY, - List.of( - new ForkId(Bytes.ofUnsignedInt(0xc61a6098L), 1696000704L), - new ForkId(Bytes.ofUnsignedInt(0xfd4f016bL), 0L), - new ForkId(Bytes.ofUnsignedInt(0xfd4f016bL), 0L)) - }, - new Object[] { - NetworkName.GOERLI, - List.of( - new ForkId(Bytes.ofUnsignedInt(0xa3f5ab08L), 1561651L), - new ForkId(Bytes.ofUnsignedInt(0xc25efa5cL), 4460644L), - new ForkId(Bytes.ofUnsignedInt(0x757a1c47L), 5062605L), - new ForkId(Bytes.ofUnsignedInt(0xb8c6299dL), 1678832736L), - new ForkId(Bytes.ofUnsignedInt(0xf9843abfL), 0L), - new ForkId(Bytes.ofUnsignedInt(0xf9843abfL), 0L)) - }, - new Object[] { - NetworkName.MAINNET, - List.of( - new ForkId(Bytes.ofUnsignedInt(0xfc64ec04L), 1150000L), - new ForkId(Bytes.ofUnsignedInt(0x97c2c34cL), 1920000L), - new ForkId(Bytes.ofUnsignedInt(0x91d1f948L), 2463000L), - new ForkId(Bytes.ofUnsignedInt(0x91d1f948L), 2463000L), - new ForkId(Bytes.ofUnsignedInt(0x91d1f948L), 2463000L), - new ForkId(Bytes.ofUnsignedInt(0x7a64da13L), 2675000L), - new ForkId(Bytes.ofUnsignedInt(0x3edd5b10L), 4370000L), - new ForkId(Bytes.ofUnsignedInt(0xa00bc324L), 7280000L), - new ForkId(Bytes.ofUnsignedInt(0x668db0afL), 9069000L), - new ForkId(Bytes.ofUnsignedInt(0x879d6e30L), 9200000L), - new ForkId(Bytes.ofUnsignedInt(0xe029e991L), 12244000L), - new ForkId(Bytes.ofUnsignedInt(0xeb440f6L), 12965000L), - new ForkId(Bytes.ofUnsignedInt(0xb715077dL), 13773000L), - new ForkId(Bytes.ofUnsignedInt(0x20c327fcL), 15050000L), - new ForkId(Bytes.ofUnsignedInt(0xf0afd0e3L), 1681338455L), - new ForkId(Bytes.ofUnsignedInt(0xdce96c2dL), 0L), - new ForkId(Bytes.ofUnsignedInt(0xdce96c2dL), 0L)) - }, - new Object[] { - NetworkName.MORDOR, - List.of( - new ForkId(Bytes.ofUnsignedInt(0x175782aaL), 301243L), - new ForkId(Bytes.ofUnsignedInt(0x604f6ee1L), 999983L), - new ForkId(Bytes.ofUnsignedInt(0xf42f5539L), 2520000L), - new ForkId(Bytes.ofUnsignedInt(0x66b5c286L), 3985893), - new ForkId(Bytes.ofUnsignedInt(0x92b323e0L), 5520000L), - new ForkId(Bytes.ofUnsignedInt(0x8c9b1797L), 9957000L), - new ForkId(Bytes.ofUnsignedInt(0x3a6b00d7L), 0L), - new ForkId(Bytes.ofUnsignedInt(0x3a6b00d7L), 0L)) - }, - new Object[] { - NetworkName.CLASSIC, - List.of( - new ForkId(Bytes.ofUnsignedInt(0xfc64ec04L), 1150000L), - new ForkId(Bytes.ofUnsignedInt(0x97c2c34cL), 2500000L), - new ForkId(Bytes.ofUnsignedInt(0x97c2c34cL), 2500000L), - new ForkId(Bytes.ofUnsignedInt(0x97c2c34cL), 2500000L), - new ForkId(Bytes.ofUnsignedInt(0xdb06803fL), 3000000L), - new ForkId(Bytes.ofUnsignedInt(0xaff4bed4L), 5000000L), - new ForkId(Bytes.ofUnsignedInt(0xf79a63c0L), 5900000L), - new ForkId(Bytes.ofUnsignedInt(0x744899d6L), 8772000L), - new ForkId(Bytes.ofUnsignedInt(0x518b59c6L), 9573000L), - new ForkId(Bytes.ofUnsignedInt(0x7ba22882L), 10500839L), - new ForkId(Bytes.ofUnsignedInt(0x9007bfccL), 11700000L), - new ForkId(Bytes.ofUnsignedInt(0xdb63a1caL), 13189133), - new ForkId(Bytes.ofUnsignedInt(0x0f6bf187L), 14525000L), - new ForkId(Bytes.ofUnsignedInt(0x7fd1bb25L), 19250000L), - new ForkId(Bytes.ofUnsignedInt(0xbe46d57cL), 0L), - new ForkId(Bytes.ofUnsignedInt(0xbe46d57cL), 0L)) - }); - } - - @Test - public void testForkId() { - final GenesisConfigFile genesisConfigFile = - GenesisConfigFile.fromConfig(EthNetworkConfig.jsonConfig(chainName)); - final MilestoneStreamingTransitionProtocolSchedule schedule = - createSchedule(genesisConfigFile); - final GenesisState genesisState = GenesisState.fromConfig(genesisConfigFile, schedule); - final Blockchain mockBlockchain = mock(Blockchain.class); - final BlockHeader mockBlockHeader = mock(BlockHeader.class); - - when(mockBlockchain.getGenesisBlock()).thenReturn(genesisState.getBlock()); - - final AtomicLong blockNumber = new AtomicLong(); - when(mockBlockchain.getChainHeadHeader()).thenReturn(mockBlockHeader); - when(mockBlockHeader.getNumber()).thenAnswer(o -> blockNumber.get()); - when(mockBlockHeader.getTimestamp()).thenAnswer(o -> blockNumber.get()); - - final ForkIdManager forkIdManager = - new ForkIdManager( - mockBlockchain, - genesisConfigFile.getForkBlockNumbers(), - genesisConfigFile.getForkTimestamps(), - false); - - final List actualForkIds = - Streams.concat(schedule.streamMilestoneBlocks(), Stream.of(Long.MAX_VALUE)) - .map( - block -> { - blockNumber.set(block); - return forkIdManager.getForkIdForChainHead(); - }) - .collect(Collectors.toList()); - - assertThat(actualForkIds).containsExactlyElementsOf(expectedForkIds); - } + @ParameterizedTest + @MethodSource("parameters") + public void testForkId(final NetworkName chainName, final List expectedForkIds) { + final GenesisConfigFile genesisConfigFile = + GenesisConfigFile.fromConfig(EthNetworkConfig.jsonConfig(chainName)); + final MilestoneStreamingTransitionProtocolSchedule schedule = createSchedule(genesisConfigFile); + final GenesisState genesisState = GenesisState.fromConfig(genesisConfigFile, schedule); + final Blockchain mockBlockchain = mock(Blockchain.class); + final BlockHeader mockBlockHeader = mock(BlockHeader.class); + + when(mockBlockchain.getGenesisBlock()).thenReturn(genesisState.getBlock()); + + final AtomicLong blockNumber = new AtomicLong(); + when(mockBlockchain.getChainHeadHeader()).thenReturn(mockBlockHeader); + when(mockBlockHeader.getNumber()).thenAnswer(o -> blockNumber.get()); + when(mockBlockHeader.getTimestamp()).thenAnswer(o -> blockNumber.get()); + + final ForkIdManager forkIdManager = + new ForkIdManager( + mockBlockchain, + genesisConfigFile.getForkBlockNumbers(), + genesisConfigFile.getForkTimestamps(), + false); + + final List actualForkIds = + Streams.concat(schedule.streamMilestoneBlocks(), Stream.of(Long.MAX_VALUE)) + .map( + block -> { + blockNumber.set(block); + return forkIdManager.getForkIdForChainHead(); + }) + .collect(Collectors.toList()); + + assertThat(actualForkIds).containsExactlyElementsOf(expectedForkIds); + } - private static MilestoneStreamingTransitionProtocolSchedule createSchedule( - final GenesisConfigFile genesisConfigFile) { - final GenesisConfigOptions configOptions = genesisConfigFile.getConfigOptions(); - MilestoneStreamingProtocolSchedule preMergeProtocolSchedule = - new MilestoneStreamingProtocolSchedule( - (DefaultProtocolSchedule) MainnetProtocolSchedule.fromConfig(configOptions)); - MilestoneStreamingProtocolSchedule postMergeProtocolSchedule = - new MilestoneStreamingProtocolSchedule( - (DefaultProtocolSchedule) MergeProtocolSchedule.create(configOptions, false)); - final MilestoneStreamingTransitionProtocolSchedule schedule = - new MilestoneStreamingTransitionProtocolSchedule( - preMergeProtocolSchedule, postMergeProtocolSchedule); - return schedule; - } + private static MilestoneStreamingTransitionProtocolSchedule createSchedule( + final GenesisConfigFile genesisConfigFile) { + final GenesisConfigOptions configOptions = genesisConfigFile.getConfigOptions(); + MilestoneStreamingProtocolSchedule preMergeProtocolSchedule = + new MilestoneStreamingProtocolSchedule( + (DefaultProtocolSchedule) MainnetProtocolSchedule.fromConfig(configOptions)); + MilestoneStreamingProtocolSchedule postMergeProtocolSchedule = + new MilestoneStreamingProtocolSchedule( + (DefaultProtocolSchedule) MergeProtocolSchedule.create(configOptions, false)); + final MilestoneStreamingTransitionProtocolSchedule schedule = + new MilestoneStreamingTransitionProtocolSchedule( + preMergeProtocolSchedule, postMergeProtocolSchedule); + return schedule; + } - public static class MilestoneStreamingTransitionProtocolSchedule - extends TransitionProtocolSchedule { + public static class MilestoneStreamingTransitionProtocolSchedule + extends TransitionProtocolSchedule { - private final TransitionUtils transitionUtils; + private final TransitionUtils transitionUtils; - public MilestoneStreamingTransitionProtocolSchedule( - final MilestoneStreamingProtocolSchedule preMergeProtocolSchedule, - final MilestoneStreamingProtocolSchedule postMergeProtocolSchedule) { - super(preMergeProtocolSchedule, postMergeProtocolSchedule, PostMergeContext.get()); - transitionUtils = - new TransitionUtils<>( - preMergeProtocolSchedule, postMergeProtocolSchedule, PostMergeContext.get()); - } + public MilestoneStreamingTransitionProtocolSchedule( + final MilestoneStreamingProtocolSchedule preMergeProtocolSchedule, + final MilestoneStreamingProtocolSchedule postMergeProtocolSchedule) { + super(preMergeProtocolSchedule, postMergeProtocolSchedule, PostMergeContext.get()); + transitionUtils = + new TransitionUtils<>( + preMergeProtocolSchedule, postMergeProtocolSchedule, PostMergeContext.get()); + } - public Stream streamMilestoneBlocks() { - return transitionUtils.dispatchFunctionAccordingToMergeState( - MilestoneStreamingProtocolSchedule::streamMilestoneBlocks); - } + public Stream streamMilestoneBlocks() { + return transitionUtils.dispatchFunctionAccordingToMergeState( + MilestoneStreamingProtocolSchedule::streamMilestoneBlocks); } } } diff --git a/besu/src/test/java/org/hyperledger/besu/RawForkIdTest.java b/besu/src/test/java/org/hyperledger/besu/RawForkIdTest.java new file mode 100644 index 00000000000..fac1095424e --- /dev/null +++ b/besu/src/test/java/org/hyperledger/besu/RawForkIdTest.java @@ -0,0 +1,34 @@ +/* + * Copyright Hyperledger Besu contributors. + * + * 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; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.hyperledger.besu.ethereum.forkid.ForkId; + +import java.util.List; + +import org.apache.tuweni.bytes.Bytes; +import org.junit.jupiter.api.Test; + +public class RawForkIdTest { + @Test + public void testFromRaw() { + final ForkId forkId = new ForkId(Bytes.ofUnsignedInt(0xfe3366e7L), 1735371L); + final List> forkIdAsBytesList = List.of(forkId.getForkIdAsBytesList()); + assertThat(ForkId.fromRawForkId(forkIdAsBytesList).get()).isEqualTo(forkId); + } +} diff --git a/besu/src/test/java/org/hyperledger/besu/cli/operator/OperatorSubCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/subcommands/operator/OperatorSubCommandTest.java similarity index 98% rename from besu/src/test/java/org/hyperledger/besu/cli/operator/OperatorSubCommandTest.java rename to besu/src/test/java/org/hyperledger/besu/cli/subcommands/operator/OperatorSubCommandTest.java index ac1ec2e5777..7e9a36719d7 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/operator/OperatorSubCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/subcommands/operator/OperatorSubCommandTest.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.operator; +package org.hyperledger.besu.cli.subcommands.operator; import static java.lang.String.format; import static java.lang.System.currentTimeMillis; @@ -22,11 +22,10 @@ import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.contentOf; -import static org.hyperledger.besu.cli.operator.OperatorSubCommandTest.Cmd.cmd; +import static org.hyperledger.besu.cli.subcommands.operator.OperatorSubCommandTest.Cmd.cmd; import org.hyperledger.besu.BesuInfo; import org.hyperledger.besu.cli.CommandTestAbstract; -import org.hyperledger.besu.cli.subcommands.operator.OperatorSubCommand; import org.hyperledger.besu.crypto.SECP256K1; import org.hyperledger.besu.crypto.SECP256R1; import org.hyperledger.besu.crypto.SECPPrivateKey; @@ -72,7 +71,7 @@ public class OperatorSubCommandTest extends CommandTestAbstract { + System.lineSeparator() + "Commands:" + System.lineSeparator() - + " generate-blockchain-config Generates node keypairs and genesis file with RLP" + + " generate-blockchain-config Generate node keypairs and genesis file with RLP" + System.lineSeparator() + " encoded extra data." + System.lineSeparator() diff --git a/besu/src/test/java/org/hyperledger/besu/cli/rlp/RLPSubCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/subcommands/rlp/RLPSubCommandTest.java similarity index 99% rename from besu/src/test/java/org/hyperledger/besu/cli/rlp/RLPSubCommandTest.java rename to besu/src/test/java/org/hyperledger/besu/cli/subcommands/rlp/RLPSubCommandTest.java index 3eca54df252..8c9b9aad932 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/rlp/RLPSubCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/subcommands/rlp/RLPSubCommandTest.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.cli.rlp; +package org.hyperledger.besu.cli.subcommands.rlp; import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; diff --git a/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerBuilderTest.java index bb7304d9f77..dd9452e7806 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerBuilderTest.java @@ -16,6 +16,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; @@ -58,21 +59,21 @@ import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; import java.math.BigInteger; +import java.nio.file.Path; import java.time.Clock; import java.util.OptionalLong; import com.google.common.collect.Range; import org.apache.tuweni.bytes.Bytes; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; import org.mockito.Answers; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class BesuControllerBuilderTest { private BesuControllerBuilder besuControllerBuilder; @@ -100,9 +101,9 @@ public class BesuControllerBuilderTest { BigInteger networkId = BigInteger.ONE; - @Rule public final TemporaryFolder tempDirRule = new TemporaryFolder(); + @TempDir Path tempDir; - @Before + @BeforeEach public void setup() { when(genesisConfigFile.getParentHash()).thenReturn(Hash.ZERO.toHexString()); when(genesisConfigFile.getDifficulty()).thenReturn(Bytes.of(0).toHexString()); @@ -129,14 +130,18 @@ public void setup() { when(synchronizerConfiguration.getBlockPropagationRange()).thenReturn(Range.closed(1L, 2L)); - when(storageProvider.createWorldStateStorage(DataStorageFormat.FOREST)) + lenient() + .when(storageProvider.createWorldStateStorage(DataStorageFormat.FOREST)) .thenReturn(worldStateStorage); - when(storageProvider.createWorldStatePreimageStorage()).thenReturn(worldStatePreimageStorage); + lenient() + .when(storageProvider.createWorldStatePreimageStorage()) + .thenReturn(worldStatePreimageStorage); - when(worldStateStorage.isWorldStateAvailable(any(), any())).thenReturn(true); - when(worldStatePreimageStorage.updater()) + lenient().when(worldStateStorage.isWorldStateAvailable(any(), any())).thenReturn(true); + lenient() + .when(worldStatePreimageStorage.updater()) .thenReturn(mock(WorldStatePreimageStorage.Updater.class)); - when(worldStateStorage.updater()).thenReturn(mock(WorldStateStorage.Updater.class)); + lenient().when(worldStateStorage.updater()).thenReturn(mock(WorldStateStorage.Updater.class)); besuControllerBuilder = spy(visitWithMockConfigs(new MainnetBesuControllerBuilder())); } @@ -149,7 +154,7 @@ BesuControllerBuilder visitWithMockConfigs(final BesuControllerBuilder builder) .miningParameters(miningParameters) .metricsSystem(observableMetricsSystem) .privacyParameters(privacyParameters) - .dataDirectory(tempDirRule.getRoot().toPath()) + .dataDirectory(tempDir) .clock(clock) .transactionPoolConfiguration(poolConfiguration) .nodeKey(nodeKey) diff --git a/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerTest.java b/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerTest.java index e6b631a4e88..29667c9c0bf 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/BesuControllerTest.java @@ -37,13 +37,13 @@ import java.util.OptionalLong; import com.google.common.io.Resources; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.Spy; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class BesuControllerTest { @Spy private GenesisConfigFile genesisConfigFile = GenesisConfigFile.mainnet(); diff --git a/besu/src/test/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilderTest.java index 4e1d87f4a68..cf98ec49add 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/ConsensusScheduleBesuControllerBuilderTest.java @@ -54,13 +54,13 @@ import java.util.function.BiFunction; import org.assertj.core.api.SoftAssertions; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class ConsensusScheduleBesuControllerBuilderTest { private @Mock BiFunction< NavigableSet>, Optional, ProtocolSchedule> diff --git a/besu/src/test/java/org/hyperledger/besu/controller/MergeBesuControllerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/controller/MergeBesuControllerBuilderTest.java index 33a539f8bc2..4368e831381 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/MergeBesuControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/MergeBesuControllerBuilderTest.java @@ -18,6 +18,7 @@ import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; @@ -61,6 +62,7 @@ import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; import java.math.BigInteger; +import java.nio.file.Path; import java.time.Clock; import java.util.Collections; import java.util.Optional; @@ -70,16 +72,15 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.apache.tuweni.units.bigints.UInt256; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; import org.mockito.Answers; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class MergeBesuControllerBuilderTest { private MergeBesuControllerBuilder besuControllerBuilder; @@ -108,46 +109,54 @@ public class MergeBesuControllerBuilderTest { TransactionPoolConfiguration.DEFAULT; private final ObservableMetricsSystem observableMetricsSystem = new NoOpMetricsSystem(); - @Rule public final TemporaryFolder tempDirRule = new TemporaryFolder(); + @TempDir Path tempDir; - @Before + @BeforeEach public void setup() { - when(genesisConfigFile.getParentHash()).thenReturn(Hash.ZERO.toHexString()); - when(genesisConfigFile.getDifficulty()).thenReturn(Bytes.of(0).toHexString()); - when(genesisConfigFile.getExtraData()).thenReturn(Bytes.EMPTY.toHexString()); - when(genesisConfigFile.getMixHash()).thenReturn(Hash.ZERO.toHexString()); - when(genesisConfigFile.getNonce()).thenReturn(Long.toHexString(1)); - when(genesisConfigFile.getConfigOptions(any())).thenReturn(genesisConfigOptions); - when(genesisConfigFile.getConfigOptions()).thenReturn(genesisConfigOptions); - when(genesisConfigOptions.getCheckpointOptions()).thenReturn(checkpointConfigOptions); + lenient().when(genesisConfigFile.getParentHash()).thenReturn(Hash.ZERO.toHexString()); + lenient().when(genesisConfigFile.getDifficulty()).thenReturn(Bytes.of(0).toHexString()); + lenient().when(genesisConfigFile.getExtraData()).thenReturn(Bytes.EMPTY.toHexString()); + lenient().when(genesisConfigFile.getMixHash()).thenReturn(Hash.ZERO.toHexString()); + lenient().when(genesisConfigFile.getNonce()).thenReturn(Long.toHexString(1)); + lenient().when(genesisConfigFile.getConfigOptions(any())).thenReturn(genesisConfigOptions); + lenient().when(genesisConfigFile.getConfigOptions()).thenReturn(genesisConfigOptions); + lenient().when(genesisConfigOptions.getCheckpointOptions()).thenReturn(checkpointConfigOptions); when(genesisConfigOptions.getTerminalTotalDifficulty()) .thenReturn((Optional.of(UInt256.valueOf(100L)))); when(genesisConfigOptions.getThanosBlockNumber()).thenReturn(OptionalLong.empty()); when(genesisConfigOptions.getTerminalBlockHash()).thenReturn(Optional.of(Hash.ZERO)); - when(genesisConfigOptions.getTerminalBlockNumber()).thenReturn(OptionalLong.of(1L)); - when(storageProvider.createBlockchainStorage(any(), any())) + lenient().when(genesisConfigOptions.getTerminalBlockNumber()).thenReturn(OptionalLong.of(1L)); + lenient() + .when(storageProvider.createBlockchainStorage(any(), any())) .thenReturn( new KeyValueStoragePrefixedKeyBlockchainStorage( new InMemoryKeyValueStorage(), new VariablesKeyValueStorage(new InMemoryKeyValueStorage()), new MainnetBlockHeaderFunctions())); - when(storageProvider.getStorageBySegmentIdentifier(any())) + lenient() + .when(storageProvider.getStorageBySegmentIdentifier(any())) .thenReturn(new InMemoryKeyValueStorage()); - when(synchronizerConfiguration.getDownloaderParallelism()).thenReturn(1); - when(synchronizerConfiguration.getTransactionsParallelism()).thenReturn(1); - when(synchronizerConfiguration.getComputationParallelism()).thenReturn(1); + lenient().when(synchronizerConfiguration.getDownloaderParallelism()).thenReturn(1); + lenient().when(synchronizerConfiguration.getTransactionsParallelism()).thenReturn(1); + lenient().when(synchronizerConfiguration.getComputationParallelism()).thenReturn(1); - when(synchronizerConfiguration.getBlockPropagationRange()).thenReturn(Range.closed(1L, 2L)); + lenient() + .when(synchronizerConfiguration.getBlockPropagationRange()) + .thenReturn(Range.closed(1L, 2L)); - when(storageProvider.createWorldStateStorage(DataStorageFormat.FOREST)) + lenient() + .when(storageProvider.createWorldStateStorage(DataStorageFormat.FOREST)) .thenReturn(worldStateStorage); - when(storageProvider.createWorldStatePreimageStorage()).thenReturn(worldStatePreimageStorage); + lenient() + .when(storageProvider.createWorldStatePreimageStorage()) + .thenReturn(worldStatePreimageStorage); - when(worldStateStorage.isWorldStateAvailable(any(), any())).thenReturn(true); - when(worldStatePreimageStorage.updater()) + lenient().when(worldStateStorage.isWorldStateAvailable(any(), any())).thenReturn(true); + lenient() + .when(worldStatePreimageStorage.updater()) .thenReturn(mock(WorldStatePreimageStorage.Updater.class)); - when(worldStateStorage.updater()).thenReturn(mock(WorldStateStorage.Updater.class)); - when(miningParameters.getTargetGasLimit()).thenReturn(OptionalLong.empty()); + lenient().when(worldStateStorage.updater()).thenReturn(mock(WorldStateStorage.Updater.class)); + lenient().when(miningParameters.getTargetGasLimit()).thenReturn(OptionalLong.empty()); besuControllerBuilder = visitWithMockConfigs(new MergeBesuControllerBuilder()); } @@ -162,7 +171,7 @@ MergeBesuControllerBuilder visitWithMockConfigs(final MergeBesuControllerBuilder .miningParameters(miningParameters) .metricsSystem(observableMetricsSystem) .privacyParameters(privacyParameters) - .dataDirectory(tempDirRule.getRoot().toPath()) + .dataDirectory(tempDir) .clock(clock) .transactionPoolConfiguration(poolConfiguration) .nodeKey(nodeKey) diff --git a/besu/src/test/java/org/hyperledger/besu/controller/QbftBesuControllerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/controller/QbftBesuControllerBuilderTest.java index 585f138027e..75fecf3f96e 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/QbftBesuControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/QbftBesuControllerBuilderTest.java @@ -17,6 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -56,20 +57,20 @@ import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; import java.math.BigInteger; +import java.nio.file.Path; import java.time.Clock; import java.util.List; import com.google.common.collect.Range; import org.apache.tuweni.bytes.Bytes; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class QbftBesuControllerBuilderTest { private BesuControllerBuilder qbftBesuControllerBuilder; @@ -92,43 +93,54 @@ public class QbftBesuControllerBuilderTest { TransactionPoolConfiguration.DEFAULT; private final ObservableMetricsSystem observableMetricsSystem = new NoOpMetricsSystem(); - @Rule public final TemporaryFolder tempDirRule = new TemporaryFolder(); + @TempDir Path tempDir; - @Before + @BeforeEach public void setup() { // besu controller setup - when(genesisConfigFile.getParentHash()).thenReturn(Hash.ZERO.toHexString()); - when(genesisConfigFile.getDifficulty()).thenReturn(Bytes.of(0).toHexString()); + lenient().when(genesisConfigFile.getParentHash()).thenReturn(Hash.ZERO.toHexString()); + lenient().when(genesisConfigFile.getDifficulty()).thenReturn(Bytes.of(0).toHexString()); when(genesisConfigFile.getExtraData()).thenReturn(Bytes.EMPTY.toHexString()); - when(genesisConfigFile.getMixHash()).thenReturn(Hash.ZERO.toHexString()); - when(genesisConfigFile.getNonce()).thenReturn(Long.toHexString(1)); - when(genesisConfigFile.getConfigOptions(any())).thenReturn(genesisConfigOptions); - when(genesisConfigFile.getConfigOptions()).thenReturn(genesisConfigOptions); - when(genesisConfigOptions.getCheckpointOptions()).thenReturn(checkpointConfigOptions); - when(storageProvider.createBlockchainStorage(any(), any())) + lenient().when(genesisConfigFile.getMixHash()).thenReturn(Hash.ZERO.toHexString()); + lenient().when(genesisConfigFile.getNonce()).thenReturn(Long.toHexString(1)); + lenient().when(genesisConfigFile.getConfigOptions(any())).thenReturn(genesisConfigOptions); + lenient().when(genesisConfigFile.getConfigOptions()).thenReturn(genesisConfigOptions); + lenient().when(genesisConfigOptions.getCheckpointOptions()).thenReturn(checkpointConfigOptions); + lenient() + .when(storageProvider.createBlockchainStorage(any(), any())) .thenReturn( new KeyValueStoragePrefixedKeyBlockchainStorage( new InMemoryKeyValueStorage(), new VariablesKeyValueStorage(new InMemoryKeyValueStorage()), new MainnetBlockHeaderFunctions())); - when(storageProvider.createWorldStateStorage(DataStorageFormat.FOREST)) + lenient() + .when(storageProvider.createWorldStateStorage(DataStorageFormat.FOREST)) .thenReturn(worldStateStorage); - when(worldStateStorage.isWorldStateAvailable(any(), any())).thenReturn(true); - when(worldStateStorage.updater()).thenReturn(mock(WorldStateStorage.Updater.class)); - when(worldStatePreimageStorage.updater()) + lenient().when(worldStateStorage.isWorldStateAvailable(any(), any())).thenReturn(true); + lenient().when(worldStateStorage.updater()).thenReturn(mock(WorldStateStorage.Updater.class)); + lenient() + .when(worldStatePreimageStorage.updater()) .thenReturn(mock(WorldStatePreimageStorage.Updater.class)); - when(storageProvider.createWorldStatePreimageStorage()).thenReturn(worldStatePreimageStorage); - when(synchronizerConfiguration.getDownloaderParallelism()).thenReturn(1); - when(synchronizerConfiguration.getTransactionsParallelism()).thenReturn(1); - when(synchronizerConfiguration.getComputationParallelism()).thenReturn(1); + lenient() + .when(storageProvider.createWorldStatePreimageStorage()) + .thenReturn(worldStatePreimageStorage); + lenient().when(synchronizerConfiguration.getDownloaderParallelism()).thenReturn(1); + lenient().when(synchronizerConfiguration.getTransactionsParallelism()).thenReturn(1); + lenient().when(synchronizerConfiguration.getComputationParallelism()).thenReturn(1); - when(synchronizerConfiguration.getBlockPropagationRange()).thenReturn(Range.closed(1L, 2L)); + lenient() + .when(synchronizerConfiguration.getBlockPropagationRange()) + .thenReturn(Range.closed(1L, 2L)); // qbft prepForBuild setup - when(genesisConfigOptions.getQbftConfigOptions()) + lenient() + .when(genesisConfigOptions.getQbftConfigOptions()) .thenReturn(new MutableQbftConfigOptions(JsonQbftConfigOptions.DEFAULT)); - when(genesisConfigOptions.getTransitions()).thenReturn(mock(TransitionsConfigOptions.class)); - when(genesisConfigFile.getExtraData()) + lenient() + .when(genesisConfigOptions.getTransitions()) + .thenReturn(mock(TransitionsConfigOptions.class)); + lenient() + .when(genesisConfigFile.getExtraData()) .thenReturn( QbftExtraDataCodec.createGenesisExtraDataString(List.of(Address.fromHexString("1")))); @@ -141,7 +153,7 @@ public void setup() { .miningParameters(miningParameters) .metricsSystem(observableMetricsSystem) .privacyParameters(privacyParameters) - .dataDirectory(tempDirRule.getRoot().toPath()) + .dataDirectory(tempDir) .clock(clock) .transactionPoolConfiguration(poolConfiguration) .nodeKey(nodeKey) diff --git a/besu/src/test/java/org/hyperledger/besu/controller/TransitionControllerBuilderTest.java b/besu/src/test/java/org/hyperledger/besu/controller/TransitionControllerBuilderTest.java index ab914ad4f5f..9b2011612a1 100644 --- a/besu/src/test/java/org/hyperledger/besu/controller/TransitionControllerBuilderTest.java +++ b/besu/src/test/java/org/hyperledger/besu/controller/TransitionControllerBuilderTest.java @@ -16,6 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; @@ -53,18 +54,18 @@ import java.util.Optional; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Answers; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; /** * We only bother testing transitionControllerBuilder for PoW and Clique since those are the only * network types that are transitioning to PoS. */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class TransitionControllerBuilderTest { @Mock ProtocolSchedule preMergeProtocolSchedule; @@ -87,7 +88,7 @@ public class TransitionControllerBuilderTest { TransitionProtocolSchedule transitionProtocolSchedule; - @Before + @BeforeEach public void setup() { transitionProtocolSchedule = spy( @@ -99,13 +100,22 @@ public void setup() { powBuilder.genesisConfigFile(GenesisConfigFile.DEFAULT); postMergeBuilder.genesisConfigFile(GenesisConfigFile.DEFAULT); postMergeBuilder.storageProvider(storageProvider); - when(protocolContext.getBlockchain()).thenReturn(mockBlockchain); - when(transitionProtocolSchedule.getPostMergeSchedule()).thenReturn(postMergeProtocolSchedule); - when(transitionProtocolSchedule.getPreMergeSchedule()).thenReturn(preMergeProtocolSchedule); - when(protocolContext.getConsensusContext(CliqueContext.class)) + lenient().when(protocolContext.getBlockchain()).thenReturn(mockBlockchain); + lenient() + .when(transitionProtocolSchedule.getPostMergeSchedule()) + .thenReturn(postMergeProtocolSchedule); + lenient() + .when(transitionProtocolSchedule.getPreMergeSchedule()) + .thenReturn(preMergeProtocolSchedule); + lenient() + .when(protocolContext.getConsensusContext(CliqueContext.class)) .thenReturn(mock(CliqueContext.class)); - when(protocolContext.getConsensusContext(PostMergeContext.class)).thenReturn(mergeContext); - when(protocolContext.getConsensusContext(MergeContext.class)).thenReturn(mergeContext); + lenient() + .when(protocolContext.getConsensusContext(PostMergeContext.class)) + .thenReturn(mergeContext); + lenient() + .when(protocolContext.getConsensusContext(MergeContext.class)) + .thenReturn(mergeContext); when(ethProtocolManager.ethContext().getScheduler()) .thenReturn(new DeterministicEthScheduler()); miningParameters = MiningParameters.newDefault(); diff --git a/config/src/main/resources/goerli.json b/config/src/main/resources/goerli.json index 5ccc9e420ad..08ca292794a 100644 --- a/config/src/main/resources/goerli.json +++ b/config/src/main/resources/goerli.json @@ -7,6 +7,7 @@ "londonBlock":5062605, "terminalTotalDifficulty": 10790000, "shanghaiTime": 1678832736, + "cancunTime": 1705473120, "clique":{ "blockperiodseconds":15, "epochlength":30000 diff --git a/config/src/main/resources/holesky.json b/config/src/main/resources/holesky.json index a8ae193c856..63f2b53a0dc 100644 --- a/config/src/main/resources/holesky.json +++ b/config/src/main/resources/holesky.json @@ -14,6 +14,7 @@ "preMergeForkBlock": 0, "terminalTotalDifficulty": 0, "shanghaiTime": 1696000704, + "cancunTime": 1707305664, "ethash": {}, "discovery": { "bootnodes": [ diff --git a/config/src/main/resources/sepolia.json b/config/src/main/resources/sepolia.json index 8a0799ce0cc..713e46ff640 100644 --- a/config/src/main/resources/sepolia.json +++ b/config/src/main/resources/sepolia.json @@ -14,6 +14,7 @@ "mergeNetSplitBlock": 1735371, "terminalTotalDifficulty": 17000000000000000, "shanghaiTime": 1677557088, + "cancunTime": 1706655072, "ethash":{}, "discovery": { "dns": "enrtree://AKA3AM6LPBYEUDMVNU3BSVQJ5AD45Y7YPOHJLEF6W26QOE4VTUDPE@all.sepolia.ethdisco.net", diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiValue.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiValue.java index 5d14c882750..c4f8ab0efd0 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiValue.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/BonsaiValue.java @@ -24,18 +24,22 @@ public class BonsaiValue implements TrieLog.LogTuple { private T prior; private T updated; - private boolean cleared; + private boolean lastStepCleared; + + private boolean clearedAtLeastOnce; public BonsaiValue(final T prior, final T updated) { this.prior = prior; this.updated = updated; - this.cleared = false; + this.lastStepCleared = false; + this.clearedAtLeastOnce = false; } - public BonsaiValue(final T prior, final T updated, final boolean cleared) { + public BonsaiValue(final T prior, final T updated, final boolean lastStepCleared) { this.prior = prior; this.updated = updated; - this.cleared = cleared; + this.lastStepCleared = lastStepCleared; + this.clearedAtLeastOnce = lastStepCleared; } @Override @@ -54,18 +58,27 @@ public BonsaiValue setPrior(final T prior) { } public BonsaiValue setUpdated(final T updated) { - this.cleared = updated == null; + this.lastStepCleared = updated == null; + if (lastStepCleared) { + this.clearedAtLeastOnce = true; + } this.updated = updated; return this; } public void setCleared() { - this.cleared = true; + this.lastStepCleared = true; + this.clearedAtLeastOnce = true; + } + + @Override + public boolean isLastStepCleared() { + return lastStepCleared; } @Override - public boolean isCleared() { - return cleared; + public boolean isClearedAtLeastOnce() { + return clearedAtLeastOnce; } @Override @@ -76,7 +89,7 @@ public String toString() { + ", updated=" + updated + ", cleared=" - + cleared + + lastStepCleared + '}'; } @@ -90,7 +103,7 @@ public boolean equals(final Object o) { } BonsaiValue that = (BonsaiValue) o; return new EqualsBuilder() - .append(cleared, that.cleared) + .append(lastStepCleared, that.lastStepCleared) .append(prior, that.prior) .append(updated, that.updated) .isEquals(); @@ -98,6 +111,10 @@ public boolean equals(final Object o) { @Override public int hashCode() { - return new HashCodeBuilder(17, 37).append(prior).append(updated).append(cleared).toHashCode(); + return new HashCodeBuilder(17, 37) + .append(prior) + .append(updated) + .append(lastStepCleared) + .toHashCode(); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogFactoryImpl.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogFactoryImpl.java index 36a6510c91e..2915a671820 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogFactoryImpl.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/trielog/TrieLogFactoryImpl.java @@ -248,7 +248,7 @@ public static void writeInnerRlp( } else { writer.accept(output, value.getUpdated()); } - if (!value.isCleared()) { + if (!value.isLastStepCleared()) { output.writeNull(); } else { output.writeInt(1); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldState.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldState.java index b9cfcbeb368..323a9e510e5 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldState.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldState.java @@ -59,6 +59,7 @@ import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; +import org.apache.tuweni.rlp.RLP; import org.apache.tuweni.units.bigints.UInt256; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -361,14 +362,24 @@ private void clearStorage( (location, key) -> getStorageTrieNode(addressHash, location, key), oldAccount.getStorageRoot()); try { + + final StorageConsumingMap> storageToDelete = + worldStateUpdater.getStorageToUpdate().get(address); Map entriesToDelete = storageTrie.entriesFrom(Bytes32.ZERO, 256); while (!entriesToDelete.isEmpty()) { - entriesToDelete - .keySet() - .forEach( - k -> - bonsaiUpdater.removeStorageValueBySlotHash( - address.addressHash(), Hash.wrap(k))); + entriesToDelete.forEach( + (k, v) -> { + final StorageSlotKey storageSlotKey = + new StorageSlotKey(Hash.wrap(k), Optional.empty()); + final UInt256 slotValue = + UInt256.fromBytes(Bytes32.leftPad(RLP.decodeValue(v))); + bonsaiUpdater.removeStorageValueBySlotHash( + address.addressHash(), storageSlotKey.getSlotHash()); + storageToDelete + .computeIfAbsent( + storageSlotKey, key -> new BonsaiValue<>(slotValue, null, true)) + .setPrior(slotValue); + }); entriesToDelete.keySet().forEach(storageTrie::remove); if (entriesToDelete.size() == 256) { entriesToDelete = storageTrie.entriesFrom(Bytes32.ZERO, 256); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldStateUpdateAccumulator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldStateUpdateAccumulator.java index 285d0de1f34..6e4458c937c 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldStateUpdateAccumulator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/trie/bonsai/worldview/BonsaiWorldStateUpdateAccumulator.java @@ -459,7 +459,7 @@ public UInt256 getPriorStorageValue(final Address address, final UInt256 storage if (localAccountStorage != null) { final BonsaiValue value = localAccountStorage.get(storageSlotKey); if (value != null) { - if (value.isCleared()) { + if (value.isLastStepCleared()) { return UInt256.ZERO; } final UInt256 updated = value.getUpdated(); diff --git a/evm/src/main/java/org/hyperledger/besu/evm/precompile/KZGPointEvalPrecompiledContract.java b/evm/src/main/java/org/hyperledger/besu/evm/precompile/KZGPointEvalPrecompiledContract.java index f4bcd7b8ab1..25968d67b1d 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/precompile/KZGPointEvalPrecompiledContract.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/precompile/KZGPointEvalPrecompiledContract.java @@ -39,7 +39,7 @@ public class KZGPointEvalPrecompiledContract implements PrecompiledContract { private static Bytes successResult; - private static void init() { + private static void loadLib() { CKZG4844JNI.loadNativeLibrary(); Bytes fieldElementsPerBlob = Bytes32.wrap(Words.intBytes(CKZG4844JNI.FIELD_ELEMENTS_PER_BLOB).xor(Bytes32.ZERO)); @@ -57,7 +57,7 @@ private static void init() { */ public static void init(final Path trustedSetupFile) { if (loaded.compareAndSet(false, true)) { - init(); + loadLib(); final String trustedSetupResourceName = trustedSetupFile.toAbsolutePath().toString(); LOG.info("Loading trusted setup from user-specified resource {}", trustedSetupResourceName); CKZG4844JNI.loadTrustedSetup(trustedSetupResourceName); @@ -67,17 +67,14 @@ public static void init(final Path trustedSetupFile) { } /** - * Init the C-KZG native lib using a resource identified by the passed network name as trusted - * setup + * Init the C-KZG native lib using mainnet trusted setup * - * @param networkName used to select the resource in /kzg-trusted-setups/ to use. * @throws IllegalStateException is the trusted setup was already loaded */ - public static void init(final String networkName) { + public static void init() { if (loaded.compareAndSet(false, true)) { - init(); - final String trustedSetupResourceName = - "/kzg-trusted-setups/" + networkName.toLowerCase() + ".txt"; + loadLib(); + final String trustedSetupResourceName = "/kzg-trusted-setups/mainnet.txt"; LOG.info( "Loading network trusted setup from classpath resource {}", trustedSetupResourceName); CKZG4844JNI.loadTrustedSetupFromResource( diff --git a/evm/src/test/java/org/hyperledger/besu/evm/precompile/KZGPointEvalPrecompileContractTest.java b/evm/src/test/java/org/hyperledger/besu/evm/precompile/KZGPointEvalPrecompileContractTest.java index bc531cb0c30..b368ce48d24 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/precompile/KZGPointEvalPrecompileContractTest.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/precompile/KZGPointEvalPrecompileContractTest.java @@ -44,7 +44,7 @@ public class KZGPointEvalPrecompileContractTest { @BeforeAll public static void init() { - KZGPointEvalPrecompiledContract.init("mainnet"); + KZGPointEvalPrecompiledContract.init(); contract = new KZGPointEvalPrecompiledContract(); } @@ -55,7 +55,7 @@ public static void tearDown() { @ParameterizedTest(name = "{index}") @MethodSource("getPointEvaluationPrecompileTestVectors") - public void testComputePrecompile(final PrecompileTestParameters parameters) { + void testComputePrecompile(final PrecompileTestParameters parameters) { when(toRun.getVersionedHashes()).thenReturn(Optional.of(List.of(parameters.versionedHash))); PrecompiledContract.PrecompileContractResult result = contract.computePrecompile(parameters.input, toRun); diff --git a/plugin-api/build.gradle b/plugin-api/build.gradle index 81723ff1e42..eab4d630b64 100644 --- a/plugin-api/build.gradle +++ b/plugin-api/build.gradle @@ -69,7 +69,7 @@ Calculated : ${currentHash} tasks.register('checkAPIChanges', FileStateChecker) { description = "Checks that the API for the Plugin-API project does not change without deliberate thought" files = sourceSets.main.allJava.files - knownHash = 'nB1LhUpMWYFQpBdNJ/3Q79c8kLgUgPmEFzlRMlLUl1Y=' + knownHash = 'N583pqJipDs4kJkgL0cPq9PBsYdsLzvUlu2I8Kk+w7g=' } check.dependsOn('checkAPIChanges') diff --git a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/trielogs/TrieLog.java b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/trielogs/TrieLog.java index 1a763ade96e..9bfe505fb1c 100644 --- a/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/trielogs/TrieLog.java +++ b/plugin-api/src/main/java/org/hyperledger/besu/plugin/services/trielogs/TrieLog.java @@ -167,10 +167,17 @@ default boolean isUnchanged() { } /** - * Checks if the updated value represents a cleared state. + * Checks if the last step performed a 'clear'. * - * @return true if the updated value is cleared, false otherwise + * @return true if the last step performed a 'clear', false otherwise. */ - boolean isCleared(); + boolean isLastStepCleared(); + + /** + * Checks if a 'clear' has been performed at least once. + * + * @return true if a 'clear' has been performed at least once, false otherwise. + */ + boolean isClearedAtLeastOnce(); } }