diff --git a/ethereum/eth/src/jmh/java/org/hyperledger/besu/ethereum/eth/sync/worldstate/WorldStateDownloaderBenchmark.java b/ethereum/eth/src/jmh/java/org/hyperledger/besu/ethereum/eth/sync/worldstate/WorldStateDownloaderBenchmark.java index 079b6ba47f..f4764f129d 100644 --- a/ethereum/eth/src/jmh/java/org/hyperledger/besu/ethereum/eth/sync/worldstate/WorldStateDownloaderBenchmark.java +++ b/ethereum/eth/src/jmh/java/org/hyperledger/besu/ethereum/eth/sync/worldstate/WorldStateDownloaderBenchmark.java @@ -27,6 +27,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; @@ -94,12 +95,14 @@ public class WorldStateDownloaderBenchmark { tempDir = Files.createTempDir().toPath(); ethProtocolManager = - EthProtocolManagerTestUtil.create( - new EthScheduler( - syncConfig.getDownloaderParallelism(), - syncConfig.getTransactionsParallelism(), - syncConfig.getComputationParallelism(), - metricsSystem)); + EthProtocolManagerTestBuilder.builder() + .setEthScheduler( + new EthScheduler( + syncConfig.getDownloaderParallelism(), + syncConfig.getTransactionsParallelism(), + syncConfig.getComputationParallelism(), + metricsSystem)) + .build(); peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, blockHeader.getNumber()); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthPeersTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthPeersTest.java index f6c635aa51..2cd5026904 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthPeersTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthPeersTest.java @@ -58,7 +58,7 @@ public class EthPeersTest { @BeforeEach public void setup() throws Exception { when(peerRequest.sendRequest(any())).thenReturn(responseStream); - ethProtocolManager = EthProtocolManagerTestUtil.create(); + ethProtocolManager = EthProtocolManagerTestBuilder.builder().build(); ethPeers = ethProtocolManager.ethContext().getEthPeers(); final ChainHeadTracker mock = mock(ChainHeadTracker.class); final BlockHeader blockHeader = mock(BlockHeader.class); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java index b7c346af69..52fcf322c5 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java @@ -77,6 +77,7 @@ import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; +import org.hyperledger.besu.testutil.DeterministicEthScheduler; import org.hyperledger.besu.testutil.TestClock; import java.math.BigInteger; @@ -132,13 +133,14 @@ public final class EthProtocolManagerTest { @Test public void handleMalformedRequestIdMessage() { try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig())) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build()) { // this is a non-request id message, but we'll be processing it with eth66, make sure we // disconnect the peer gracefully final MessageData messageData = GetBlockHeadersMessage.create(1, 1, 0, false); @@ -151,13 +153,14 @@ public final class EthProtocolManagerTest { @Test public void disconnectOnUnsolicitedMessage() { try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig())) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build()) { final MessageData messageData = BlockHeadersMessage.create(Collections.singletonList(blockchain.getBlockHeader(1).get())); final MockPeerConnection peer = setupPeer(ethManager, (cap, msg, conn) -> {}); @@ -169,13 +172,14 @@ public final class EthProtocolManagerTest { @Test public void disconnectOnFailureToSendStatusMessage() { try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig())) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build()) { final MessageData messageData = BlockHeadersMessage.create(Collections.singletonList(blockchain.getBlockHeader(1).get())); final MockPeerConnection peer = @@ -188,13 +192,14 @@ public final class EthProtocolManagerTest { @Test public void disconnectOnWrongChainId() { try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig())) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build()) { final MessageData messageData = BlockHeadersMessage.create(Collections.singletonList(blockchain.getBlockHeader(1).get())); final MockPeerConnection peer = @@ -219,13 +224,14 @@ public final class EthProtocolManagerTest { public void disconnectNewPoWPeers() { final MergePeerFilter mergePeerFilter = new MergePeerFilter(); try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig(), - Optional.of(mergePeerFilter))) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .setMergePeerFilter(Optional.of(mergePeerFilter)) + .build()) { final MockPeerConnection workPeer = setupPeer(ethManager, (cap, msg, conn) -> {}); final MockPeerConnection stakePeer = setupPeer(ethManager, (cap, msg, conn) -> {}); @@ -267,13 +273,14 @@ public final class EthProtocolManagerTest { @Test public void doNotDisconnectOnLargeMessageWithinLimits() { try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig())) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build()) { final MessageData messageData = mock(MessageData.class); when(messageData.getSize()).thenReturn(EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE); when(messageData.getCode()).thenReturn(EthPV62.TRANSACTIONS); @@ -287,13 +294,14 @@ public final class EthProtocolManagerTest { @Test public void disconnectOnWrongGenesisHash() { try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig())) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build()) { final MessageData messageData = BlockHeadersMessage.create(Collections.singletonList(blockchain.getBlockHeader(1).get())); final MockPeerConnection peer = @@ -317,13 +325,14 @@ public final class EthProtocolManagerTest { @Test public void doNotDisconnectOnValidMessage() { try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig())) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build()) { final MessageData messageData = GetBlockBodiesMessage.create(Collections.singletonList(gen.hash())); final MockPeerConnection peer = setupPeer(ethManager, (cap, msg, conn) -> {}); @@ -339,13 +348,14 @@ public final class EthProtocolManagerTest { public void respondToGetHeaders() throws ExecutionException, InterruptedException { final CompletableFuture done = new CompletableFuture<>(); try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig())) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build()) { final long startBlock = 5L; final int blockCount = 5; final MessageData messageData = @@ -379,13 +389,14 @@ public final class EthProtocolManagerTest { final EthProtocolConfiguration config = EthProtocolConfiguration.builder().maxGetBlockHeaders(limit).build(); try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - config)) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(config) + .build()) { final long startBlock = 5L; final int blockCount = 10; final MessageData messageData = @@ -416,13 +427,14 @@ public final class EthProtocolManagerTest { public void respondToGetHeadersReversed() throws ExecutionException, InterruptedException { final CompletableFuture done = new CompletableFuture<>(); try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig())) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build()) { final long endBlock = 10L; final int blockCount = 5; @@ -453,13 +465,14 @@ public final class EthProtocolManagerTest { public void respondToGetHeadersWithSkip() throws ExecutionException, InterruptedException { final CompletableFuture done = new CompletableFuture<>(); try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig())) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build()) { final long startBlock = 5L; final int blockCount = 5; @@ -493,13 +506,14 @@ public final class EthProtocolManagerTest { throws ExecutionException, InterruptedException { final CompletableFuture done = new CompletableFuture<>(); try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig())) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build()) { final long endBlock = 10L; final int blockCount = 5; @@ -557,13 +571,14 @@ public final class EthProtocolManagerTest { public void respondToGetHeadersPartial() throws ExecutionException, InterruptedException { final CompletableFuture done = new CompletableFuture<>(); try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig())) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build()) { final long startBlock = blockchain.getChainHeadBlockNumber() - 1L; final int blockCount = 5; @@ -595,13 +610,14 @@ public final class EthProtocolManagerTest { public void respondToGetHeadersEmpty() throws ExecutionException, InterruptedException { final CompletableFuture done = new CompletableFuture<>(); try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig())) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build()) { final long startBlock = blockchain.getChainHeadBlockNumber() + 1; final int blockCount = 5; @@ -630,13 +646,14 @@ public final class EthProtocolManagerTest { public void respondToGetBodies() throws ExecutionException, InterruptedException { final CompletableFuture done = new CompletableFuture<>(); try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig())) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build()) { // Setup blocks query final long startBlock = blockchain.getChainHeadBlockNumber() - 5; @@ -683,13 +700,14 @@ public final class EthProtocolManagerTest { final EthProtocolConfiguration config = EthProtocolConfiguration.builder().maxGetBlockBodies(limit).build(); try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - config)) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(config) + .build()) { // Setup blocks query final int blockCount = 10; final long startBlock = blockchain.getChainHeadBlockNumber() - blockCount; @@ -732,13 +750,14 @@ public final class EthProtocolManagerTest { public void respondToGetBodiesPartial() throws ExecutionException, InterruptedException { final CompletableFuture done = new CompletableFuture<>(); try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig())) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build()) { // Setup blocks query final long expectedBlockNumber = blockchain.getChainHeadBlockNumber() - 1; final BlockHeader header = blockchain.getBlockHeader(expectedBlockNumber).get(); @@ -775,13 +794,14 @@ public final class EthProtocolManagerTest { public void respondToGetReceipts() throws ExecutionException, InterruptedException { final CompletableFuture done = new CompletableFuture<>(); try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig())) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build()) { // Setup blocks query final long startBlock = blockchain.getChainHeadBlockNumber() - 5; final int blockCount = 2; @@ -826,13 +846,14 @@ public final class EthProtocolManagerTest { final EthProtocolConfiguration config = EthProtocolConfiguration.builder().maxGetReceipts(limit).build(); try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - config)) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(config) + .build()) { // Setup blocks query final int blockCount = 10; final long startBlock = blockchain.getChainHeadBlockNumber() - blockCount; @@ -874,13 +895,14 @@ public final class EthProtocolManagerTest { public void respondToGetReceiptsPartial() throws ExecutionException, InterruptedException { final CompletableFuture done = new CompletableFuture<>(); try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig())) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build()) { // Setup blocks query final long blockNumber = blockchain.getChainHeadBlockNumber() - 5; final BlockHeader header = blockchain.getBlockHeader(blockNumber).get(); @@ -919,13 +941,14 @@ public final class EthProtocolManagerTest { final WorldStateArchive worldStateArchive = protocolContext.getWorldStateArchive(); try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig())) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build()) { // Setup node data query final List expectedResults = new ArrayList<>(); @@ -967,13 +990,14 @@ public final class EthProtocolManagerTest { @Test public void newBlockMinedSendsNewBlockMessageToAllPeers() { try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig())) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build()) { // Define handler to validate response final PeerSendHandler onSend = mock(PeerSendHandler.class); final List peers = Lists.newArrayList(); @@ -1038,13 +1062,14 @@ public final class EthProtocolManagerTest { final CompletableFuture done = new CompletableFuture<>(); try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig())) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build()) { final long startBlock = 1L; final int requestedBlockCount = 13; @@ -1105,13 +1130,14 @@ public final class EthProtocolManagerTest { final TransactionsMessage transactionMessage = TransactionsMessage.readFrom(raw); try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - ethScheduler, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig())) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(ethScheduler) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build()) { // Create a transaction pool. This has a side effect of registering a listener for the // transactions message. TransactionPoolFactory.createTransactionPool( @@ -1141,15 +1167,17 @@ public final class EthProtocolManagerTest { public void forkIdForChainHeadLegacyNoForksNotEmpty() { final EthScheduler ethScheduler = mock(EthScheduler.class); try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - ethScheduler, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig(), - new ForkIdManager( - blockchain, Collections.emptyList(), Collections.emptyList(), true))) { + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(ethScheduler) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .setForkIdManager( + new ForkIdManager( + blockchain, Collections.emptyList(), Collections.emptyList(), true)) + .build()) { assertThat(ethManager.getForkIdAsBytesList()).isNotEmpty(); final CRC32 genesisHashCRC = new CRC32(); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTestBuilder.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTestBuilder.java new file mode 100644 index 0000000000..0a267022b9 --- /dev/null +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTestBuilder.java @@ -0,0 +1,245 @@ +/* + * Copyright contributors to Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.eth.manager; + +import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain; +import static org.mockito.Mockito.mock; + +import org.hyperledger.besu.config.GenesisConfigFile; +import org.hyperledger.besu.ethereum.chain.Blockchain; +import org.hyperledger.besu.ethereum.chain.GenesisState; +import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; +import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; +import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; +import org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator; +import org.hyperledger.besu.ethereum.eth.sync.SyncMode; +import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; +import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; +import org.hyperledger.besu.ethereum.forkid.ForkIdManager; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; +import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; +import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; +import org.hyperledger.besu.testutil.DeterministicEthScheduler; +import org.hyperledger.besu.testutil.TestClock; + +import java.math.BigInteger; +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +import org.apache.tuweni.bytes.Bytes; + +public class EthProtocolManagerTestBuilder { + private static final BigInteger DEFAULT_NETWORK_ID = BigInteger.ONE; + private static final ProtocolSchedule DEFAULT_PROTOCOL_SCHEDULE = ProtocolScheduleFixture.MAINNET; + + private ProtocolSchedule protocolSchedule; + private GenesisConfigFile genesisConfigFile; + private GenesisState genesisState; + private Blockchain blockchain; + private BigInteger networkId; + private WorldStateArchive worldStateArchive; + private TransactionPool transactionPool; + private EthProtocolConfiguration ethereumWireProtocolConfiguration; + private ForkIdManager forkIdManager; + private EthPeers ethPeers; + private EthMessages ethMessages; + private EthMessages snapMessages; + private EthScheduler ethScheduler; + private EthContext ethContext; + private List peerValidators; + private Optional mergePeerFilter; + private SynchronizerConfiguration synchronizerConfiguration; + + public static EthProtocolManagerTestBuilder builder() { + return new EthProtocolManagerTestBuilder(); + } + + public EthProtocolManagerTestBuilder setProtocolSchedule( + final ProtocolSchedule protocolSchedule) { + this.protocolSchedule = protocolSchedule; + return this; + } + + public EthProtocolManagerTestBuilder setGenesisConfigFile( + final GenesisConfigFile genesisConfigFile) { + this.genesisConfigFile = genesisConfigFile; + return this; + } + + public EthProtocolManagerTestBuilder setGenesisState(final GenesisState genesisState) { + this.genesisState = genesisState; + return this; + } + + public EthProtocolManagerTestBuilder setBlockchain(final Blockchain blockchain) { + this.blockchain = blockchain; + return this; + } + + public EthProtocolManagerTestBuilder setNetworkId(final BigInteger networkId) { + this.networkId = networkId; + return this; + } + + public EthProtocolManagerTestBuilder setWorldStateArchive( + final WorldStateArchive worldStateArchive) { + this.worldStateArchive = worldStateArchive; + return this; + } + + public EthProtocolManagerTestBuilder setTransactionPool(final TransactionPool transactionPool) { + this.transactionPool = transactionPool; + return this; + } + + public EthProtocolManagerTestBuilder setEthereumWireProtocolConfiguration( + final EthProtocolConfiguration ethereumWireProtocolConfiguration) { + this.ethereumWireProtocolConfiguration = ethereumWireProtocolConfiguration; + return this; + } + + public EthProtocolManagerTestBuilder setForkIdManager(final ForkIdManager forkIdManager) { + this.forkIdManager = forkIdManager; + return this; + } + + public EthProtocolManagerTestBuilder setEthPeers(final EthPeers ethPeers) { + this.ethPeers = ethPeers; + return this; + } + + public EthProtocolManagerTestBuilder setEthMessages(final EthMessages ethMessages) { + this.ethMessages = ethMessages; + return this; + } + + public EthProtocolManagerTestBuilder setSnapMessages(final EthMessages snapMessages) { + this.snapMessages = snapMessages; + return this; + } + + public EthProtocolManagerTestBuilder setEthContext(final EthContext ethContext) { + this.ethContext = ethContext; + return this; + } + + public EthProtocolManagerTestBuilder setPeerValidators(final List peerValidators) { + this.peerValidators = peerValidators; + return this; + } + + public EthProtocolManagerTestBuilder setMergePeerFilter( + final Optional mergePeerFilter) { + this.mergePeerFilter = mergePeerFilter; + return this; + } + + public EthProtocolManagerTestBuilder setSynchronizerConfiguration( + final SynchronizerConfiguration synchronizerConfiguration) { + this.synchronizerConfiguration = synchronizerConfiguration; + return this; + } + + public EthProtocolManagerTestBuilder setEthScheduler(final EthScheduler ethScheduler) { + this.ethScheduler = ethScheduler; + return this; + } + + public EthProtocolManager build() { + if (protocolSchedule == null) { + protocolSchedule = DEFAULT_PROTOCOL_SCHEDULE; + } + if (genesisConfigFile == null) { + genesisConfigFile = GenesisConfigFile.mainnet(); + } + if (genesisState == null) { + genesisState = GenesisState.fromConfig(genesisConfigFile, protocolSchedule); + } + if (blockchain == null) { + blockchain = createInMemoryBlockchain(genesisState.getBlock()); + } + if (networkId == null) { + networkId = DEFAULT_NETWORK_ID; + } + if (worldStateArchive == null) { + worldStateArchive = + BlockchainSetupUtil.forTesting(DataStorageFormat.FOREST).getWorldArchive(); + } + if (transactionPool == null) { + transactionPool = mock(TransactionPool.class); + } + if (ethereumWireProtocolConfiguration == null) { + ethereumWireProtocolConfiguration = EthProtocolConfiguration.defaultConfig(); + } + if (forkIdManager == null) { + forkIdManager = + new ForkIdManager(blockchain, Collections.emptyList(), Collections.emptyList(), false); + } + if (ethPeers == null) { + ethPeers = + new EthPeers( + () -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()), + TestClock.fixed(), + new NoOpMetricsSystem(), + EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE, + Collections.emptyList(), + Bytes.random(64), + 25, + 25, + false, + SyncMode.FAST, + forkIdManager); + } + ethPeers.setChainHeadTracker(EthProtocolManagerTestUtil.getChainHeadTrackerMock()); + if (ethMessages == null) { + ethMessages = new EthMessages(); + } + if (snapMessages == null) { + snapMessages = new EthMessages(); + } + if (ethScheduler == null) { + ethScheduler = + new DeterministicEthScheduler(DeterministicEthScheduler.TimeoutPolicy.NEVER_TIMEOUT); + } + if (ethContext == null) { + ethContext = new EthContext(ethPeers, ethMessages, snapMessages, ethScheduler); + } + if (peerValidators == null) { + peerValidators = Collections.emptyList(); + } + if (mergePeerFilter == null) { + mergePeerFilter = Optional.of(new MergePeerFilter()); + } + if (synchronizerConfiguration == null) { + synchronizerConfiguration = SynchronizerConfiguration.builder().build(); + } + return new EthProtocolManager( + blockchain, + networkId, + worldStateArchive, + transactionPool, + ethereumWireProtocolConfiguration, + ethPeers, + ethMessages, + ethContext, + peerValidators, + mergePeerFilter, + synchronizerConfiguration, + ethScheduler, + forkIdManager); + } +} diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTestUtil.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTestUtil.java index 3415a897a2..a91dd17a53 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTestUtil.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTestUtil.java @@ -15,229 +15,29 @@ package org.hyperledger.besu.ethereum.eth.manager; import static com.google.common.base.Preconditions.checkArgument; -import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; -import org.hyperledger.besu.config.GenesisConfigFile; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.ChainHead; -import org.hyperledger.besu.ethereum.chain.GenesisState; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; import org.hyperledger.besu.ethereum.eth.EthProtocol; -import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.snap.SnapProtocolManager; import org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator; import org.hyperledger.besu.ethereum.eth.sync.ChainHeadTracker; -import org.hyperledger.besu.ethereum.eth.sync.SyncMode; -import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; -import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; -import org.hyperledger.besu.ethereum.forkid.ForkIdManager; -import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.DefaultMessage; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; -import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; -import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; -import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; import org.hyperledger.besu.testutil.DeterministicEthScheduler; -import org.hyperledger.besu.testutil.DeterministicEthScheduler.TimeoutPolicy; -import org.hyperledger.besu.testutil.TestClock; -import java.math.BigInteger; -import java.util.Collections; -import java.util.Optional; import java.util.OptionalLong; import java.util.concurrent.CompletableFuture; -import org.apache.tuweni.bytes.Bytes; import org.mockito.Mockito; public class EthProtocolManagerTestUtil { - public static EthProtocolManager create( - final ProtocolSchedule protocolSchedule, - final Blockchain blockchain, - final TimeoutPolicy timeoutPolicy, - final WorldStateArchive worldStateArchive, - final TransactionPool transactionPool, - final EthProtocolConfiguration ethereumWireProtocolConfiguration) { - return create( - protocolSchedule, - blockchain, - new DeterministicEthScheduler(timeoutPolicy), - worldStateArchive, - transactionPool, - ethereumWireProtocolConfiguration); - } - - public static EthProtocolManager create( - final ProtocolSchedule protocolSchedule, - final Blockchain blockchain, - final WorldStateArchive worldStateArchive, - final TransactionPool transactionPool, - final EthProtocolConfiguration ethereumWireProtocolConfiguration, - final Optional mergePeerFilter) { - - final EthPeers peers = - new EthPeers( - () -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()), - TestClock.fixed(), - new NoOpMetricsSystem(), - EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE, - Collections.emptyList(), - Bytes.random(64), - 25, - 25, - false, - SyncMode.FAST, - new ForkIdManager(blockchain, Collections.emptyList(), Collections.emptyList(), false)); - - final ChainHeadTracker chainHeadTrackerMock = getChainHeadTrackerMock(); - peers.setChainHeadTracker(chainHeadTrackerMock); - - final EthMessages messages = new EthMessages(); - final EthScheduler ethScheduler = new DeterministicEthScheduler(TimeoutPolicy.NEVER_TIMEOUT); - final EthContext ethContext = new EthContext(peers, messages, ethScheduler); - - return new EthProtocolManager( - blockchain, - BigInteger.ONE, - worldStateArchive, - transactionPool, - ethereumWireProtocolConfiguration, - peers, - messages, - ethContext, - Collections.emptyList(), - mergePeerFilter, - mock(SynchronizerConfiguration.class), - ethScheduler, - new ForkIdManager(blockchain, Collections.emptyList(), Collections.emptyList(), false)); - } - - public static EthProtocolManager create( - final Blockchain blockchain, - final EthScheduler ethScheduler, - final WorldStateArchive worldStateArchive, - final TransactionPool transactionPool, - final EthProtocolConfiguration ethereumWireProtocolConfiguration, - final EthPeers ethPeers, - final EthMessages ethMessages, - final EthContext ethContext) { - return create( - blockchain, - ethScheduler, - worldStateArchive, - transactionPool, - ethereumWireProtocolConfiguration, - ethPeers, - ethMessages, - ethContext, - new ForkIdManager(blockchain, Collections.emptyList(), Collections.emptyList(), false)); - } - - public static EthProtocolManager create( - final Blockchain blockchain, - final EthScheduler ethScheduler, - final WorldStateArchive worldStateArchive, - final TransactionPool transactionPool, - final EthProtocolConfiguration ethereumWireProtocolConfiguration, - final EthPeers ethPeers, - final EthMessages ethMessages, - final EthContext ethContext, - final ForkIdManager forkIdManager) { - - ethPeers.setChainHeadTracker(getChainHeadTrackerMock()); - - final BigInteger networkId = BigInteger.ONE; - return new EthProtocolManager( - blockchain, - networkId, - worldStateArchive, - transactionPool, - ethereumWireProtocolConfiguration, - ethPeers, - ethMessages, - ethContext, - Collections.emptyList(), - Optional.empty(), - mock(SynchronizerConfiguration.class), - ethScheduler, - forkIdManager); - } - - public static EthProtocolManager create(final Blockchain blockchain) { - return create( - ProtocolScheduleFixture.MAINNET, - blockchain, - new DeterministicEthScheduler(TimeoutPolicy.NEVER_TIMEOUT)); - } - - public static EthProtocolManager create( - final ProtocolSchedule protocolSchedule, - final Blockchain blockchain, - final WorldStateArchive worldStateArchive, - final TransactionPool transactionPool, - final EthProtocolConfiguration ethProtocolConfiguration) { - return create( - protocolSchedule, - blockchain, - new DeterministicEthScheduler(TimeoutPolicy.NEVER_TIMEOUT), - worldStateArchive, - transactionPool, - ethProtocolConfiguration); - } - - public static EthProtocolManager create(final EthScheduler ethScheduler) { - final ProtocolSchedule protocolSchedule = ProtocolScheduleFixture.MAINNET; - final GenesisConfigFile config = GenesisConfigFile.mainnet(); - final GenesisState genesisState = GenesisState.fromConfig(config, protocolSchedule); - final Blockchain blockchain = createInMemoryBlockchain(genesisState.getBlock()); - return create(protocolSchedule, blockchain, ethScheduler); - } - - public static EthProtocolManager create( - final ProtocolSchedule protocolSchedule, - final Blockchain blockchain, - final EthScheduler ethScheduler, - final WorldStateArchive worldStateArchive, - final TransactionPool transactionPool, - final EthProtocolConfiguration configuration) { - - final EthPeers peers = - new EthPeers( - () -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()), - TestClock.fixed(), - new NoOpMetricsSystem(), - EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE, - Collections.emptyList(), - Bytes.random(64), - 25, - 25, - false, - SyncMode.FAST, - new ForkIdManager(blockchain, Collections.emptyList(), Collections.emptyList(), false)); - final EthMessages messages = new EthMessages(); - - final ChainHeadTracker chtMock = getChainHeadTrackerMock(); - - peers.setChainHeadTracker(chtMock); - - return create( - blockchain, - ethScheduler, - worldStateArchive, - transactionPool, - configuration, - peers, - messages, - new EthContext(peers, messages, ethScheduler)); - } - public static ChainHeadTracker getChainHeadTrackerMock() { final ChainHeadTracker chtMock = mock(ChainHeadTracker.class); final BlockHeader blockHeaderMock = mock(BlockHeader.class); @@ -249,84 +49,6 @@ public class EthProtocolManagerTestUtil { return chtMock; } - public static EthProtocolManager create( - final ProtocolSchedule protocolSchedule, - final Blockchain blockchain, - final EthScheduler ethScheduler, - final WorldStateArchive worldStateArchive, - final TransactionPool transactionPool, - final EthProtocolConfiguration configuration, - final ForkIdManager forkIdManager) { - - final EthPeers peers = - new EthPeers( - () -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()), - TestClock.fixed(), - new NoOpMetricsSystem(), - EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE, - Collections.emptyList(), - Bytes.random(64), - 25, - 25, - false, - SyncMode.FAST, - new ForkIdManager(blockchain, Collections.emptyList(), Collections.emptyList(), false)); - final EthMessages messages = new EthMessages(); - - return create( - blockchain, - ethScheduler, - worldStateArchive, - transactionPool, - configuration, - peers, - messages, - new EthContext(peers, messages, ethScheduler), - forkIdManager); - } - - public static EthProtocolManager create( - final ProtocolSchedule protocolSchedule, - final Blockchain blockchain, - final EthScheduler ethScheduler) { - final EthPeers ethPeers = - new EthPeers( - () -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()), - TestClock.fixed(), - new NoOpMetricsSystem(), - EthProtocolConfiguration.DEFAULT_MAX_MESSAGE_SIZE, - Collections.emptyList(), - Bytes.random(64), - 25, - 25, - false, - SyncMode.FAST, - new ForkIdManager(blockchain, Collections.emptyList(), Collections.emptyList(), false)); - - final ChainHeadTracker chainHeadTrackerMock = getChainHeadTrackerMock(); - ethPeers.setChainHeadTracker(chainHeadTrackerMock); - - final EthMessages messages = new EthMessages(); - - return create( - blockchain, - ethScheduler, - BlockchainSetupUtil.forTesting(DataStorageFormat.FOREST).getWorldArchive(), - mock(TransactionPool.class), - EthProtocolConfiguration.defaultConfig(), - ethPeers, - messages, - new EthContext(ethPeers, messages, ethScheduler)); - } - - public static EthProtocolManager create() { - return create(TimeoutPolicy.NEVER_TIMEOUT); - } - - public static EthProtocolManager create(final TimeoutPolicy timeoutPolicy) { - return create(new DeterministicEthScheduler(timeoutPolicy)); - } - // Utility to prevent scheduler from automatically running submitted tasks public static void disableEthSchedulerAutoRun(final EthProtocolManager ethProtocolManager) { final EthScheduler scheduler = ethProtocolManager.ethContext().getScheduler(); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/AbstractMessageTaskTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/AbstractMessageTaskTest.java index 7de95304be..9d6f63df28 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/AbstractMessageTaskTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/AbstractMessageTaskTest.java @@ -33,6 +33,7 @@ import org.hyperledger.besu.ethereum.eth.manager.EthMessages; import org.hyperledger.besu.ethereum.eth.manager.EthPeer; import org.hyperledger.besu.ethereum.eth.manager.EthPeers; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; @@ -146,15 +147,16 @@ public abstract class AbstractMessageTaskTest { transactionPool.setEnabled(); ethProtocolManager = - EthProtocolManagerTestUtil.create( - blockchain, - ethScheduler, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig(), - ethPeers, - ethMessages, - ethContext); + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(ethScheduler) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .setEthPeers(ethPeers) + .setEthMessages(ethMessages) + .setEthContext(ethContext) + .build(); } protected abstract T generateDataToBeRequested(); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/task/WaitForPeerTaskTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/task/WaitForPeerTaskTest.java index 906b0ca7aa..07bce17b60 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/task/WaitForPeerTaskTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/task/WaitForPeerTaskTest.java @@ -18,6 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem; @@ -36,7 +37,7 @@ public class WaitForPeerTaskTest { @BeforeEach public void setupTest() { - ethProtocolManager = EthProtocolManagerTestUtil.create(); + ethProtocolManager = EthProtocolManagerTestBuilder.builder().build(); ethContext = ethProtocolManager.ethContext(); } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/task/WaitForPeersTaskTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/task/WaitForPeersTaskTest.java index 283a1b5894..c4bf495139 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/task/WaitForPeersTaskTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/task/WaitForPeersTaskTest.java @@ -18,6 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem; @@ -36,7 +37,7 @@ public class WaitForPeersTaskTest { @BeforeEach public void setupTest() { - ethProtocolManager = EthProtocolManagerTestUtil.create(); + ethProtocolManager = EthProtocolManagerTestBuilder.builder().build(); ethContext = ethProtocolManager.ethContext(); } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/AbstractPeerBlockValidatorTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/AbstractPeerBlockValidatorTest.java index b7258de5b7..3e6ee32c41 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/AbstractPeerBlockValidatorTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/AbstractPeerBlockValidatorTest.java @@ -21,6 +21,7 @@ import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockDataGenerator.BlockOptions; import org.hyperledger.besu.ethereum.eth.manager.EthPeer; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.messages.BlockHeadersMessage; @@ -43,7 +44,11 @@ public abstract class AbstractPeerBlockValidatorTest { @Test public void validatePeer_unresponsivePeer() { final EthProtocolManager ethProtocolManager = - EthProtocolManagerTestUtil.create(DeterministicEthScheduler.TimeoutPolicy.ALWAYS_TIMEOUT); + EthProtocolManagerTestBuilder.builder() + .setEthScheduler( + new DeterministicEthScheduler( + DeterministicEthScheduler.TimeoutPolicy.ALWAYS_TIMEOUT)) + .build(); final long blockNumber = 500; final PeerValidator validator = createValidator(blockNumber, 0); @@ -61,7 +66,7 @@ public abstract class AbstractPeerBlockValidatorTest { @Test public void validatePeer_requestBlockFromPeerBeingTested() { - final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); + final EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build(); final BlockDataGenerator gen = new BlockDataGenerator(1); final long blockNumber = 500; final Block block = gen.block(BlockOptions.create().setBlockNumber(blockNumber)); @@ -97,7 +102,11 @@ public abstract class AbstractPeerBlockValidatorTest { public void canBeValidated() { final BlockDataGenerator gen = new BlockDataGenerator(1); final EthProtocolManager ethProtocolManager = - EthProtocolManagerTestUtil.create(DeterministicEthScheduler.TimeoutPolicy.ALWAYS_TIMEOUT); + EthProtocolManagerTestBuilder.builder() + .setEthScheduler( + new DeterministicEthScheduler( + DeterministicEthScheduler.TimeoutPolicy.ALWAYS_TIMEOUT)) + .build(); final long blockNumber = 500; final long buffer = 10; diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/DaoForkPeerValidatorTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/DaoForkPeerValidatorTest.java index 042ca8f960..c27b656df8 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/DaoForkPeerValidatorTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/DaoForkPeerValidatorTest.java @@ -21,6 +21,7 @@ import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockDataGenerator.BlockOptions; import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderValidator; @@ -42,7 +43,7 @@ public class DaoForkPeerValidatorTest extends AbstractPeerBlockValidatorTest { @Test public void validatePeer_responsivePeerOnRightSideOfFork() { - final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); + final EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build(); final BlockDataGenerator gen = new BlockDataGenerator(1); final long daoBlockNumber = 500; final Block daoBlock = @@ -73,7 +74,7 @@ public class DaoForkPeerValidatorTest extends AbstractPeerBlockValidatorTest { @Test public void validatePeer_responsivePeerOnWrongSideOfFork() { - final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); + final EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build(); final BlockDataGenerator gen = new BlockDataGenerator(1); final long daoBlockNumber = 500; final Block daoBlock = @@ -101,7 +102,7 @@ public class DaoForkPeerValidatorTest extends AbstractPeerBlockValidatorTest { @Test public void validatePeer_responsivePeerDoesNotHaveBlockWhenPastForkHeight() { - final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); + final EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build(); final long daoBlockNumber = 500; final PeerValidator validator = diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/PeerValidatorRunnerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/PeerValidatorRunnerTest.java index 4663ac3ee9..591927bd83 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/PeerValidatorRunnerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/PeerValidatorRunnerTest.java @@ -25,6 +25,7 @@ import static org.mockito.Mockito.when; import org.hyperledger.besu.ethereum.eth.manager.EthPeer; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.messages.DisconnectMessage.DisconnectReason; @@ -39,7 +40,7 @@ public class PeerValidatorRunnerTest { public void checkPeer_schedulesFutureCheckWhenPeerNotReady() { final PeerValidator validator = mock(PeerValidator.class); - final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); + final EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build(); EthProtocolManagerTestUtil.disableEthSchedulerAutoRun(ethProtocolManager); final EthPeer peer = EthProtocolManagerTestUtil.peerBuilder() @@ -78,7 +79,7 @@ public class PeerValidatorRunnerTest { public void checkPeer_doesNotScheduleFutureCheckWhenPeerNotReadyAndDisconnected() { final PeerValidator validator = mock(PeerValidator.class); - final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); + final EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build(); EthProtocolManagerTestUtil.disableEthSchedulerAutoRun(ethProtocolManager); final EthPeer peer = EthProtocolManagerTestUtil.peerBuilder() @@ -105,7 +106,7 @@ public class PeerValidatorRunnerTest { public void checkPeer_handlesInvalidPeer() { final PeerValidator validator = mock(PeerValidator.class); - final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); + final EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build(); EthProtocolManagerTestUtil.disableEthSchedulerAutoRun(ethProtocolManager); final EthPeer peer = EthProtocolManagerTestUtil.peerBuilder() @@ -138,7 +139,7 @@ public class PeerValidatorRunnerTest { public void checkPeer_handlesValidPeer() { final PeerValidator validator = mock(PeerValidator.class); - final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); + final EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build(); EthProtocolManagerTestUtil.disableEthSchedulerAutoRun(ethProtocolManager); final EthPeer peer = EthProtocolManagerTestUtil.peerBuilder() diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/RequiredBlocksPeerValidatorTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/RequiredBlocksPeerValidatorTest.java index 4fdb679880..38486570d5 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/RequiredBlocksPeerValidatorTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/RequiredBlocksPeerValidatorTest.java @@ -22,6 +22,7 @@ import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockDataGenerator.BlockOptions; import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -41,7 +42,10 @@ public class RequiredBlocksPeerValidatorTest extends AbstractPeerBlockValidatorT @Test public void validatePeer_responsivePeerWithRequiredBlock() { - final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); + final EthProtocolManager ethProtocolManager = + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(ProtocolScheduleFixture.MAINNET) + .build(); final BlockDataGenerator gen = new BlockDataGenerator(1); final long requiredBlockNumber = 500; final Block requiredBlock = @@ -73,7 +77,7 @@ public class RequiredBlocksPeerValidatorTest extends AbstractPeerBlockValidatorT @Test public void validatePeer_responsivePeerWithBadRequiredBlock() { - final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); + final EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build(); final BlockDataGenerator gen = new BlockDataGenerator(1); final long requiredBlockNumber = 500; final Block requiredBlock = @@ -105,7 +109,7 @@ public class RequiredBlocksPeerValidatorTest extends AbstractPeerBlockValidatorT @Test public void validatePeer_responsivePeerDoesNotHaveBlockWhenPastForkHeight() { - final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); + final EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build(); final PeerValidator validator = new RequiredBlocksPeerValidator( diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/AbstractBlockPropagationManagerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/AbstractBlockPropagationManagerTest.java index cae4c8ff85..c06d1cda2a 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/AbstractBlockPropagationManagerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/AbstractBlockPropagationManagerTest.java @@ -45,6 +45,7 @@ import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthMessages; import org.hyperledger.besu.ethereum.eth.manager.EthPeers; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; @@ -110,12 +111,13 @@ public abstract class AbstractBlockPropagationManagerTest { tempProtocolContext.getConsensusContext(ConsensusContext.class), new BadBlockManager()); ethProtocolManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - blockchainUtil.getWorldArchive(), - blockchainUtil.getTransactionPool(), - EthProtocolConfiguration.defaultConfig()); + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setWorldStateArchive(blockchainUtil.getWorldArchive()) + .setTransactionPool(blockchainUtil.getTransactionPool()) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build(); syncConfig = SynchronizerConfiguration.builder().blockPropagationRange(-3, 5).build(); syncState = new SyncState(blockchain, ethProtocolManager.ethContext().getEthPeers()); blockBroadcaster = mock(BlockBroadcaster.class); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTrackerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTrackerTest.java index f97fe91c6f..6fa8a6ec9d 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTrackerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTrackerTest.java @@ -27,7 +27,7 @@ import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.difficulty.fixed.FixedDifficultyProtocolSchedule; import org.hyperledger.besu.ethereum.eth.manager.ChainState; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; -import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer.Responder; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -76,7 +76,7 @@ public class ChainHeadTrackerTest { public void setup(final DataStorageFormat storageFormat) { blockchainSetupUtil = BlockchainSetupUtil.forTesting(storageFormat); blockchain = blockchainSetupUtil.getBlockchain(); - ethProtocolManager = EthProtocolManagerTestUtil.create(blockchain); + ethProtocolManager = EthProtocolManagerTestBuilder.builder().setBlockchain(blockchain).build(); respondingPeer = RespondingEthPeer.builder() .ethProtocolManager(ethProtocolManager) diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/DownloadHeadersStepTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/DownloadHeadersStepTest.java index 3dba7d1cf1..dfc2986610 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/DownloadHeadersStepTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/DownloadHeadersStepTest.java @@ -24,6 +24,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.eth.manager.EthPeer; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.sync.range.RangeHeaders; @@ -65,7 +66,7 @@ public class DownloadHeadersStepTest { @BeforeEach public void setUp() { - ethProtocolManager = EthProtocolManagerTestUtil.create(blockchain); + ethProtocolManager = EthProtocolManagerTestBuilder.builder().setBlockchain(blockchain).build(); downloader = new DownloadHeadersStep( protocolSchedule, diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/RangeHeadersFetcherTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/RangeHeadersFetcherTest.java index 39cad8407e..27a4650c54 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/RangeHeadersFetcherTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/RangeHeadersFetcherTest.java @@ -26,6 +26,7 @@ import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer.Responder; @@ -36,6 +37,7 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; +import org.hyperledger.besu.testutil.DeterministicEthScheduler; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -73,13 +75,14 @@ public class RangeHeadersFetcherTest { @BeforeEach public void setUpTest() { ethProtocolManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig()); + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build(); responder = RespondingEthPeer.blockchainResponder( blockchain, protocolContext.getWorldStateArchive(), transactionPool); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContextTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContextTest.java index 4cd4d1c674..66cfc21130 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContextTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContextTest.java @@ -40,6 +40,7 @@ import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; @@ -144,7 +145,11 @@ public class BackwardSyncContextTest { } } when(protocolContext.getBlockchain()).thenReturn(localBlockchain); - EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); + EthProtocolManager ethProtocolManager = + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(localBlockchain) + .build(); peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager); EthContext ethContext = ethProtocolManager.ethContext(); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncStepTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncStepTest.java index 696856c076..76f1e8ea62 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncStepTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncStepTest.java @@ -33,7 +33,7 @@ import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; -import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.exceptions.MaxRetriesReachedException; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; @@ -130,7 +130,8 @@ public class BackwardSyncStepTest { when(context.getProtocolSchedule()).thenReturn(protocolSchedule); when(context.getBatchSize()).thenReturn(5); - EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(ethScheduler); + EthProtocolManager ethProtocolManager = + EthProtocolManagerTestBuilder.builder().setEthScheduler(ethScheduler).build(); peer = RespondingEthPeer.builder() diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/ForwardSyncStepTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/ForwardSyncStepTest.java index 34479bf11f..7104ae3173 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/ForwardSyncStepTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/ForwardSyncStepTest.java @@ -32,6 +32,7 @@ import org.hyperledger.besu.ethereum.core.MiningConfiguration; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; @@ -127,7 +128,7 @@ public class ForwardSyncStepTest { when(context.getProtocolContext().getBlockchain()).thenReturn(localBlockchain); when(context.getProtocolSchedule()).thenReturn(protocolSchedule); when(context.getBatchSize()).thenReturn(2); - EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); + EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build(); peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager); EthContext ethContext = ethProtocolManager.ethContext(); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckPointSyncChainDownloaderTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckPointSyncChainDownloaderTest.java index 56e0461f70..e4039aee49 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckPointSyncChainDownloaderTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckPointSyncChainDownloaderTest.java @@ -28,6 +28,7 @@ import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; @@ -121,10 +122,11 @@ public class CheckPointSyncChainDownloaderTest { protocolSchedule = localBlockchainSetup.getProtocolSchedule(); protocolContext = localBlockchainSetup.getProtocolContext(); ethProtocolManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - localBlockchain, - new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem())); + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(localBlockchain) + .setEthScheduler(new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem())) + .build(); ethContext = ethProtocolManager.ethContext(); final int blockNumber = 10; diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStepTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStepTest.java index 4559b211e6..97cc268d6b 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStepTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStepTest.java @@ -31,6 +31,7 @@ import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; @@ -42,6 +43,7 @@ import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; +import org.hyperledger.besu.testutil.DeterministicEthScheduler; import java.util.HashMap; import java.util.List; @@ -78,13 +80,14 @@ public class DownloadReceiptsStepTest { peerTaskExecutor = mock(PeerTaskExecutor.class); TransactionPool transactionPool = mock(TransactionPool.class); ethProtocolManager = - EthProtocolManagerTestUtil.create( - ProtocolScheduleFixture.MAINNET, - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig()); + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(ProtocolScheduleFixture.MAINNET) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(() -> false)) + .setWorldStateArchive(protocolContext.getWorldStateArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build(); } @Test diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActionsTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActionsTest.java index 7af807c1c7..a1003fe411 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActionsTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActionsTest.java @@ -32,6 +32,7 @@ import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthPeer; import org.hyperledger.besu.ethereum.eth.manager.EthPeers; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; @@ -45,6 +46,7 @@ import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; +import org.hyperledger.besu.testutil.DeterministicEthScheduler; import java.util.ArrayList; import java.util.List; @@ -93,13 +95,15 @@ public class FastSyncActionsTest { blockchainSetupUtil.importAllBlocks(); blockchain = blockchainSetupUtil.getBlockchain(); ethProtocolManager = - EthProtocolManagerTestUtil.create( - ProtocolScheduleFixture.MAINNET, - blockchain, - () -> timeoutCount.getAndDecrement() > 0, - blockchainSetupUtil.getWorldArchive(), - blockchainSetupUtil.getTransactionPool(), - EthProtocolConfiguration.defaultConfig()); + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(ProtocolScheduleFixture.MAINNET) + .setBlockchain(blockchain) + .setEthScheduler( + new DeterministicEthScheduler(() -> timeoutCount.getAndDecrement() > 0)) + .setWorldStateArchive(blockchainSetupUtil.getWorldArchive()) + .setTransactionPool(blockchainSetupUtil.getTransactionPool()) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build(); ethContext = ethProtocolManager.ethContext(); ethPeers = ethContext.getEthPeers(); syncState = new SyncState(blockchain, ethPeers); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloaderTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloaderTest.java index 0e5b5ec2c7..9865d4f23c 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloaderTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloaderTest.java @@ -26,6 +26,7 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; @@ -87,10 +88,11 @@ public class FastSyncChainDownloaderTest { protocolSchedule = localBlockchainSetup.getProtocolSchedule(); protocolContext = localBlockchainSetup.getProtocolContext(); ethProtocolManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - localBlockchain, - new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem())); + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(localBlockchain) + .setEthScheduler(new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem())) + .build(); ethContext = ethProtocolManager.ethContext(); syncState = new SyncState(protocolContext.getBlockchain(), ethContext.getEthPeers()); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockConfirmerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockConfirmerTest.java index 2a8a311084..ab81fc68ed 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockConfirmerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockConfirmerTest.java @@ -26,6 +26,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer.Responder; @@ -35,6 +36,7 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; +import org.hyperledger.besu.testutil.DeterministicEthScheduler; import java.util.Optional; import java.util.concurrent.CompletableFuture; @@ -79,13 +81,14 @@ public class PivotBlockConfirmerTest { protocolSchedule = blockchainSetupUtil.getProtocolSchedule(); protocolContext = blockchainSetupUtil.getProtocolContext(); ethProtocolManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - timeout::get, - blockchainSetupUtil.getWorldArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig()); + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(timeout::get)) + .setWorldStateArchive(blockchainSetupUtil.getWorldArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build(); pivotBlockConfirmer = createPivotBlockConfirmer(3, 2); } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockRetrieverTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockRetrieverTest.java index a377ee7827..54864acbc6 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockRetrieverTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockRetrieverTest.java @@ -28,6 +28,7 @@ import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer.Responder; @@ -37,6 +38,7 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; +import org.hyperledger.besu.testutil.DeterministicEthScheduler; import org.hyperledger.besu.util.ExceptionUtils; import java.util.Optional; @@ -82,13 +84,14 @@ public class PivotBlockRetrieverTest { protocolContext = blockchainSetupUtil.getProtocolContext(); transactionPool = blockchainSetupUtil.getTransactionPool(); ethProtocolManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - blockchain, - timeout::get, - blockchainSetupUtil.getWorldArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig()); + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .setEthScheduler(new DeterministicEthScheduler(timeout::get)) + .setWorldStateArchive(blockchainSetupUtil.getWorldArchive()) + .setTransactionPool(transactionPool) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build(); pivotBlockRetriever = createPivotBlockRetriever(3, 1, 1); } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldStateDownloaderTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldStateDownloaderTest.java index 323f0ae9f1..431c044cbb 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldStateDownloaderTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldStateDownloaderTest.java @@ -36,6 +36,7 @@ import org.hyperledger.besu.ethereum.core.MutableWorldState; import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; @@ -114,7 +115,9 @@ class FastWorldStateDownloaderTest { .build()); final EthProtocolManager ethProtocolManager = - EthProtocolManagerTestUtil.create(new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem())); + EthProtocolManagerTestBuilder.builder() + .setEthScheduler(new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem())) + .build(); @AfterEach public void tearDown() throws Exception { @@ -238,7 +241,10 @@ class FastWorldStateDownloaderTest { void canRecoverFromTimeouts() { final DeterministicEthScheduler.TimeoutPolicy timeoutPolicy = DeterministicEthScheduler.TimeoutPolicy.timeoutXTimes(2); - final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(timeoutPolicy); + final EthProtocolManager ethProtocolManager = + EthProtocolManagerTestBuilder.builder() + .setEthScheduler(new DeterministicEthScheduler(timeoutPolicy)) + .build(); final MockExecutorService serviceExecutor = ((DeterministicEthScheduler) ethProtocolManager.ethContext().getScheduler()) .mockServiceExecutor(); @@ -382,7 +388,7 @@ class FastWorldStateDownloaderTest { @SuppressWarnings("unchecked") private void testCancellation(final boolean shouldCancelFuture) { - final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); + final EthProtocolManager ethProtocolManager = EthProtocolManagerTestBuilder.builder().build(); // Prevent the persistence service from running final MockExecutorService serviceExecutor = ((DeterministicEthScheduler) ethProtocolManager.ethContext().getScheduler()) @@ -661,7 +667,9 @@ class FastWorldStateDownloaderTest { @Timeout(value = 60) void stalledDownloader() { final EthProtocolManager ethProtocolManager = - EthProtocolManagerTestUtil.create(new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem())); + EthProtocolManagerTestBuilder.builder() + .setEthScheduler(new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem())) + .build(); // Setup "remote" state final ForestWorldStateKeyValueStorage remoteStorage = diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderForkTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderForkTest.java index d7b5970098..fb518c305f 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderForkTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderForkTest.java @@ -24,6 +24,7 @@ import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; @@ -66,13 +67,14 @@ public class FullSyncChainDownloaderForkTest { protocolSchedule = localBlockchainSetup.getProtocolSchedule(); protocolContext = localBlockchainSetup.getProtocolContext(); ethProtocolManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - localBlockchain, - new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()), - localBlockchainSetup.getWorldArchive(), - localBlockchainSetup.getTransactionPool(), - EthProtocolConfiguration.defaultConfig()); + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(localBlockchain) + .setEthScheduler(new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem())) + .setWorldStateArchive(localBlockchainSetup.getWorldArchive()) + .setTransactionPool(localBlockchainSetup.getTransactionPool()) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build(); ethContext = ethProtocolManager.ethContext(); syncState = new SyncState(protocolContext.getBlockchain(), ethContext.getEthPeers()); } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderTest.java index ac7f0fb825..2c3c1ecdc8 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderTest.java @@ -31,6 +31,7 @@ import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; @@ -96,13 +97,14 @@ public class FullSyncChainDownloaderTest { protocolSchedule = localBlockchainSetup.getProtocolSchedule(); protocolContext = localBlockchainSetup.getProtocolContext(); ethProtocolManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - localBlockchain, - new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()), - localBlockchainSetup.getWorldArchive(), - localBlockchainSetup.getTransactionPool(), - EthProtocolConfiguration.defaultConfig()); + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(localBlockchain) + .setEthScheduler(new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem())) + .setWorldStateArchive(localBlockchainSetup.getWorldArchive()) + .setTransactionPool(localBlockchainSetup.getTransactionPool()) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build(); ethContext = ethProtocolManager.ethContext(); syncState = new SyncState(protocolContext.getBlockchain(), ethContext.getEthPeers()); } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderTotalTerminalDifficultyTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderTotalTerminalDifficultyTest.java index 311ccf5de3..d79a220924 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderTotalTerminalDifficultyTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderTotalTerminalDifficultyTest.java @@ -24,6 +24,7 @@ import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; @@ -80,13 +81,14 @@ public class FullSyncChainDownloaderTotalTerminalDifficultyTest { protocolSchedule = localBlockchainSetup.getProtocolSchedule(); protocolContext = localBlockchainSetup.getProtocolContext(); ethProtocolManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - localBlockchain, - new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()), - localBlockchainSetup.getWorldArchive(), - localBlockchainSetup.getTransactionPool(), - EthProtocolConfiguration.defaultConfig()); + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(localBlockchain) + .setEthScheduler(new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem())) + .setWorldStateArchive(localBlockchainSetup.getWorldArchive()) + .setTransactionPool(localBlockchainSetup.getTransactionPool()) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build(); ethContext = ethProtocolManager.ethContext(); syncState = new SyncState(protocolContext.getBlockchain(), ethContext.getEthPeers()); } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncDownloaderTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncDownloaderTest.java index 63e41f6d25..f50b7edfcf 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncDownloaderTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncDownloaderTest.java @@ -22,6 +22,7 @@ import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; @@ -71,13 +72,14 @@ public class FullSyncDownloaderTest { protocolSchedule = localBlockchainSetup.getProtocolSchedule(); protocolContext = localBlockchainSetup.getProtocolContext(); ethProtocolManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - localBlockchain, - new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()), - localBlockchainSetup.getWorldArchive(), - localBlockchainSetup.getTransactionPool(), - EthProtocolConfiguration.defaultConfig()); + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(localBlockchain) + .setEthScheduler(new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem())) + .setWorldStateArchive(localBlockchainSetup.getWorldArchive()) + .setTransactionPool(localBlockchainSetup.getTransactionPool()) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build(); ethContext = ethProtocolManager.ethContext(); syncState = new SyncState(protocolContext.getBlockchain(), ethContext.getEthPeers()); } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java index 9132842ccb..66314ddddd 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java @@ -30,6 +30,7 @@ import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; @@ -81,13 +82,14 @@ public class FullSyncTargetManagerTest { new ProtocolContext( localBlockchain, localWorldState, mock(ConsensusContext.class), new BadBlockManager()); ethProtocolManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - localBlockchain, - new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()), - localWorldState, - localBlockchainSetup.getTransactionPool(), - EthProtocolConfiguration.defaultConfig()); + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(localBlockchain) + .setEthScheduler(new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem())) + .setWorldStateArchive(localBlockchainSetup.getWorldArchive()) + .setTransactionPool(localBlockchainSetup.getTransactionPool()) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build(); final EthContext ethContext = ethProtocolManager.ethContext(); localBlockchainSetup.importFirstBlocks(5); otherBlockchainSetup.importFirstBlocks(20); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/state/SyncStateTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/state/SyncStateTest.java index d3dcb85599..88653f8af3 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/state/SyncStateTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/state/SyncStateTest.java @@ -42,6 +42,7 @@ import org.hyperledger.besu.ethereum.eth.manager.ChainState; import org.hyperledger.besu.ethereum.eth.manager.EthPeer; import org.hyperledger.besu.ethereum.eth.manager.EthPeers; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.messages.DisconnectMessage.DisconnectReason; @@ -90,7 +91,7 @@ public class SyncStateTest { @BeforeEach public void setUp() { - ethProtocolManager = EthProtocolManagerTestUtil.create(blockchain); + ethProtocolManager = EthProtocolManagerTestBuilder.builder().setBlockchain(blockchain).build(); ethPeers = spy(ethProtocolManager.ethContext().getEthPeers()); syncTargetPeer = createPeer(TARGET_DIFFICULTY, TARGET_CHAIN_HEIGHT); otherPeer = createPeer(Difficulty.ZERO, 0); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java index 5686b4ae90..ba0d0fb1da 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java @@ -33,6 +33,7 @@ import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.task.EthTask; @@ -135,12 +136,13 @@ public class DetermineCommonAncestorTaskParameterizedTest { final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); final EthProtocolManager ethProtocolManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - localBlockchain, - worldStateArchive, - mock(TransactionPool.class), - EthProtocolConfiguration.defaultConfig()); + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(localBlockchain) + .setWorldStateArchive(worldStateArchive) + .setTransactionPool(mock(TransactionPool.class)) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build(); final RespondingEthPeer.Responder responder = RespondingEthPeer.blockchainResponder(remoteBlockchain); final RespondingEthPeer respondingEthPeer = diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java index f85e4dd31c..c8fb58ed43 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java @@ -41,6 +41,7 @@ import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthPeer; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; import org.hyperledger.besu.ethereum.eth.manager.RespondingEthPeer; import org.hyperledger.besu.ethereum.eth.manager.exceptions.EthTaskException; @@ -81,12 +82,13 @@ public class DetermineCommonAncestorTaskTest { localBlockchain = createInMemoryBlockchain(localGenesisBlock); final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); ethProtocolManager = - EthProtocolManagerTestUtil.create( - protocolSchedule, - localBlockchain, - worldStateArchive, - mock(TransactionPool.class), - EthProtocolConfiguration.defaultConfig()); + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(localBlockchain) + .setWorldStateArchive(worldStateArchive) + .setTransactionPool(mock(TransactionPool.class)) + .setEthereumWireProtocolConfiguration(EthProtocolConfiguration.defaultConfig()) + .build(); ethContext = ethProtocolManager.ethContext(); protocolContext = new ProtocolContext( diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/PersistBlockTaskTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/PersistBlockTaskTest.java index dd5d79b667..a39d3658bf 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/PersistBlockTaskTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/PersistBlockTaskTest.java @@ -25,7 +25,7 @@ import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; -import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.sync.tasks.exceptions.InvalidBlockException; import org.hyperledger.besu.ethereum.mainnet.HeaderValidationMode; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; @@ -70,7 +70,11 @@ public class PersistBlockTaskTest { protocolSchedule = blockchainUtil.getProtocolSchedule(); protocolContext = blockchainUtil.getProtocolContext(); blockchain = blockchainUtil.getBlockchain(); - final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create(); + final EthProtocolManager ethProtocolManager = + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .build(); ethContext = ethProtocolManager.ethContext(); } diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTestBase.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTestBase.java index e3e8046ba8..7046270cd5 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTestBase.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/AbstractTransactionPoolTestBase.java @@ -56,7 +56,7 @@ import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.core.TransactionTestFixture; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; -import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestUtil; +import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManagerTestBuilder; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.eth.transactions.layered.LayeredTransactionPoolBaseFeeTest; import org.hyperledger.besu.ethereum.eth.transactions.sorter.LegacyTransactionPoolBaseFeeTest; @@ -225,7 +225,11 @@ public abstract class AbstractTransactionPoolTestBase { protocolSchedule = spy(executionContext.getProtocolSchedule()); doReturn(protocolSpec).when(protocolSchedule).getByBlockHeader(any()); blockGasLimit = blockchain.getChainHeadBlock().getHeader().getGasLimit(); - ethProtocolManager = EthProtocolManagerTestUtil.create(); + ethProtocolManager = + EthProtocolManagerTestBuilder.builder() + .setProtocolSchedule(protocolSchedule) + .setBlockchain(blockchain) + .build(); ethContext = spy(ethProtocolManager.ethContext()); final EthScheduler ethScheduler = spy(ethContext.getScheduler());