From b67ea3dfe797ebe9dc64ce02fb258f19e8b94d13 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Thu, 28 Nov 2024 15:03:00 +1100 Subject: [PATCH 1/6] 7311: Add EthProtocolManagerTestBuilder Signed-off-by: Matilda Clerke --- .../EthProtocolManagerTestBuilder.java | 227 ++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100644 ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTestBuilder.java 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 00000000000..95d5b6aa188 --- /dev/null +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTestBuilder.java @@ -0,0 +1,227 @@ +/* + * 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 EthPeers ethPeers; + private EthMessages ethMessages; + private EthMessages snapMessages; + private EthScheduler ethScheduler; + private EthContext ethContext; + private List peerValidators; + private Optional mergePeerFilter; + private SynchronizerConfiguration synchronizerConfiguration; + + public EthProtocolManagerTestBuilder setProtocolSchedule(ProtocolSchedule protocolSchedule) { + this.protocolSchedule = protocolSchedule; + return this; + } + + public EthProtocolManagerTestBuilder setGenesisConfigFile(GenesisConfigFile genesisConfigFile) { + this.genesisConfigFile = genesisConfigFile; + return this; + } + + public EthProtocolManagerTestBuilder setGenesisState(GenesisState genesisState) { + this.genesisState = genesisState; + return this; + } + + public EthProtocolManagerTestBuilder setBlockchain(Blockchain blockchain) { + this.blockchain = blockchain; + return this; + } + + public EthProtocolManagerTestBuilder setNetworkId(BigInteger networkId) { + this.networkId = networkId; + return this; + } + + public EthProtocolManagerTestBuilder setWorldStateArchive(WorldStateArchive worldStateArchive) { + this.worldStateArchive = worldStateArchive; + return this; + } + + public EthProtocolManagerTestBuilder setTransactionPool(TransactionPool transactionPool) { + this.transactionPool = transactionPool; + return this; + } + + public EthProtocolManagerTestBuilder setEthereumWireProtocolConfiguration( + EthProtocolConfiguration ethereumWireProtocolConfiguration) { + this.ethereumWireProtocolConfiguration = ethereumWireProtocolConfiguration; + return this; + } + + public EthProtocolManagerTestBuilder setEthPeers(EthPeers ethPeers) { + this.ethPeers = ethPeers; + return this; + } + + public EthProtocolManagerTestBuilder setEthMessages(EthMessages ethMessages) { + this.ethMessages = ethMessages; + return this; + } + + public EthProtocolManagerTestBuilder setSnapMessages(EthMessages snapMessages) { + this.snapMessages = snapMessages; + return this; + } + + public EthProtocolManagerTestBuilder setEthContext(EthContext ethContext) { + this.ethContext = ethContext; + return this; + } + + public EthProtocolManagerTestBuilder setPeerValidators(List peerValidators) { + this.peerValidators = peerValidators; + return this; + } + + public EthProtocolManagerTestBuilder setMergePeerFilter( + Optional mergePeerFilter) { + this.mergePeerFilter = mergePeerFilter; + return this; + } + + public EthProtocolManagerTestBuilder setSynchronizerConfiguration( + SynchronizerConfiguration synchronizerConfiguration) { + this.synchronizerConfiguration = synchronizerConfiguration; + return this; + } + + public EthProtocolManagerTestBuilder setEthScheduler(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) { + EthProtocolConfiguration.defaultConfig(); + } + 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, + new ForkIdManager( + blockchain, Collections.emptyList(), Collections.emptyList(), false)); + } + 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); + } +} From 53439f154d61c8ba899fbf12872c4fae1a5787ae Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Thu, 28 Nov 2024 15:04:23 +1100 Subject: [PATCH 2/6] 7311: Add EthProtocolManagerTestBuilder.builder method Signed-off-by: Matilda Clerke --- .../ethereum/eth/manager/EthProtocolManagerTestBuilder.java | 4 ++++ 1 file changed, 4 insertions(+) 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 index 95d5b6aa188..0430eefce5a 100644 --- 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 @@ -63,6 +63,10 @@ public class EthProtocolManagerTestBuilder { private Optional mergePeerFilter; private SynchronizerConfiguration synchronizerConfiguration; + public static EthProtocolManagerTestBuilder builder() { + return new EthProtocolManagerTestBuilder(); + } + public EthProtocolManagerTestBuilder setProtocolSchedule(ProtocolSchedule protocolSchedule) { this.protocolSchedule = protocolSchedule; return this; From 56c5d44689f2410be193558814de3895d9f55ffd Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Thu, 28 Nov 2024 15:38:19 +1100 Subject: [PATCH 3/6] 7311: Replace EthProtocolManagerTestUtil.create() usages with builder Signed-off-by: Matilda Clerke --- .../ethereum/eth/manager/EthPeersTest.java | 2 +- .../EthProtocolManagerTestBuilder.java | 38 ++++++++++--------- .../eth/manager/task/WaitForPeerTaskTest.java | 3 +- .../manager/task/WaitForPeersTaskTest.java | 3 +- .../AbstractPeerBlockValidatorTest.java | 3 +- .../DaoForkPeerValidatorTest.java | 7 ++-- .../PeerValidatorRunnerTest.java | 9 +++-- .../RequiredBlocksPeerValidatorTest.java | 10 +++-- .../backwardsync/BackwardSyncContextTest.java | 7 +++- .../backwardsync/ForwardSyncStepTest.java | 3 +- .../FastWorldStateDownloaderTest.java | 3 +- .../eth/sync/tasks/PersistBlockTaskTest.java | 8 +++- .../AbstractTransactionPoolTestBase.java | 8 +++- 13 files changed, 66 insertions(+), 38 deletions(-) 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 f6c635aa51f..2cd50269043 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/EthProtocolManagerTestBuilder.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTestBuilder.java index 0430eefce5a..032b8644bcd 100644 --- 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 @@ -67,85 +67,88 @@ public static EthProtocolManagerTestBuilder builder() { return new EthProtocolManagerTestBuilder(); } - public EthProtocolManagerTestBuilder setProtocolSchedule(ProtocolSchedule protocolSchedule) { + public EthProtocolManagerTestBuilder setProtocolSchedule( + final ProtocolSchedule protocolSchedule) { this.protocolSchedule = protocolSchedule; return this; } - public EthProtocolManagerTestBuilder setGenesisConfigFile(GenesisConfigFile genesisConfigFile) { + public EthProtocolManagerTestBuilder setGenesisConfigFile( + final GenesisConfigFile genesisConfigFile) { this.genesisConfigFile = genesisConfigFile; return this; } - public EthProtocolManagerTestBuilder setGenesisState(GenesisState genesisState) { + public EthProtocolManagerTestBuilder setGenesisState(final GenesisState genesisState) { this.genesisState = genesisState; return this; } - public EthProtocolManagerTestBuilder setBlockchain(Blockchain blockchain) { + public EthProtocolManagerTestBuilder setBlockchain(final Blockchain blockchain) { this.blockchain = blockchain; return this; } - public EthProtocolManagerTestBuilder setNetworkId(BigInteger networkId) { + public EthProtocolManagerTestBuilder setNetworkId(final BigInteger networkId) { this.networkId = networkId; return this; } - public EthProtocolManagerTestBuilder setWorldStateArchive(WorldStateArchive worldStateArchive) { + public EthProtocolManagerTestBuilder setWorldStateArchive( + final WorldStateArchive worldStateArchive) { this.worldStateArchive = worldStateArchive; return this; } - public EthProtocolManagerTestBuilder setTransactionPool(TransactionPool transactionPool) { + public EthProtocolManagerTestBuilder setTransactionPool(final TransactionPool transactionPool) { this.transactionPool = transactionPool; return this; } public EthProtocolManagerTestBuilder setEthereumWireProtocolConfiguration( - EthProtocolConfiguration ethereumWireProtocolConfiguration) { + final EthProtocolConfiguration ethereumWireProtocolConfiguration) { this.ethereumWireProtocolConfiguration = ethereumWireProtocolConfiguration; return this; } - public EthProtocolManagerTestBuilder setEthPeers(EthPeers ethPeers) { + public EthProtocolManagerTestBuilder setEthPeers(final EthPeers ethPeers) { this.ethPeers = ethPeers; return this; } - public EthProtocolManagerTestBuilder setEthMessages(EthMessages ethMessages) { + public EthProtocolManagerTestBuilder setEthMessages(final EthMessages ethMessages) { this.ethMessages = ethMessages; return this; } - public EthProtocolManagerTestBuilder setSnapMessages(EthMessages snapMessages) { + public EthProtocolManagerTestBuilder setSnapMessages(final EthMessages snapMessages) { this.snapMessages = snapMessages; return this; } - public EthProtocolManagerTestBuilder setEthContext(EthContext ethContext) { + public EthProtocolManagerTestBuilder setEthContext(final EthContext ethContext) { this.ethContext = ethContext; return this; } - public EthProtocolManagerTestBuilder setPeerValidators(List peerValidators) { + public EthProtocolManagerTestBuilder setPeerValidators(final List peerValidators) { this.peerValidators = peerValidators; return this; } public EthProtocolManagerTestBuilder setMergePeerFilter( - Optional mergePeerFilter) { + final Optional mergePeerFilter) { this.mergePeerFilter = mergePeerFilter; return this; } public EthProtocolManagerTestBuilder setSynchronizerConfiguration( - SynchronizerConfiguration synchronizerConfiguration) { + final SynchronizerConfiguration synchronizerConfiguration) { this.synchronizerConfiguration = synchronizerConfiguration; return this; } - public EthProtocolManagerTestBuilder setEthScheduler(EthScheduler ethScheduler) { + public EthProtocolManagerTestBuilder setEthScheduler(final EthScheduler ethScheduler) { this.ethScheduler = ethScheduler; return this; } @@ -174,7 +177,7 @@ public EthProtocolManager build() { transactionPool = mock(TransactionPool.class); } if (ethereumWireProtocolConfiguration == null) { - EthProtocolConfiguration.defaultConfig(); + ethereumWireProtocolConfiguration = EthProtocolConfiguration.defaultConfig(); } if (ethPeers == null) { ethPeers = @@ -191,6 +194,7 @@ public EthProtocolManager build() { SyncMode.FAST, new ForkIdManager( blockchain, Collections.emptyList(), Collections.emptyList(), false)); + ethPeers.setChainHeadTracker(EthProtocolManagerTestUtil.getChainHeadTrackerMock()); } if (ethMessages == null) { ethMessages = new EthMessages(); 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 906b0ca7aaa..07bce17b608 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 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 283a1b5894c..c4bf495139f 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 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 b7258de5b7e..aa289a9f5ae 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.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; @@ -61,7 +62,7 @@ public void validatePeer_unresponsivePeer() { @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)); 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 042ca8f9605..c27b656df8d 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.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 @@ AbstractPeerBlockValidator createValidator(final long blockNumber, final long bu @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 void validatePeer_responsivePeerOnRightSideOfFork() { @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 void validatePeer_responsivePeerOnWrongSideOfFork() { @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 4663ac3ee92..591927bd83b 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 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 void checkPeer_schedulesFutureCheckWhenPeerNotReady() { 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 void checkPeer_doesNotScheduleFutureCheckWhenPeerNotReadyAndDisconnected( 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 void checkPeer_handlesInvalidPeer() { 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 4fdb679880b..38486570d5f 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.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 @@ AbstractPeerBlockValidator createValidator(final long blockNumber, final long bu @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 void validatePeer_responsivePeerWithRequiredBlock() { @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 void validatePeer_responsivePeerWithBadRequiredBlock() { @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/backwardsync/BackwardSyncContextTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncContextTest.java index 4cd4d1c6745..66cfc211303 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.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 void setup() { } } 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/ForwardSyncStepTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/ForwardSyncStepTest.java index 34479bf11fd..7104ae31730 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.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 void setup() { 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/fastsync/worldstate/FastWorldStateDownloaderTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldStateDownloaderTest.java index 323f0ae9f10..fb4888c7640 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.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; @@ -382,7 +383,7 @@ void cancelDownloaderFuture() { @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()) 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 dd5d79b6670..a39d3658bfe 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.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 void setup(final DataStorageFormat storageFormat) { 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 e3e8046ba87..7046270cd59 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.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 void setUp() { 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()); From 30ba10633607c54df9c3c418f062b12c599c42d3 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Thu, 28 Nov 2024 15:54:21 +1100 Subject: [PATCH 4/6] 7311: Replace EthProtocolManagerTestUtil.create(TimeoutPolicy) Signed-off-by: Matilda Clerke --- .../eth/manager/EthProtocolManagerTestUtil.java | 8 -------- .../AbstractPeerBlockValidatorTest.java | 12 ++++++++++-- .../worldstate/FastWorldStateDownloaderTest.java | 5 ++++- 3 files changed, 14 insertions(+), 11 deletions(-) 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 3415a897a2d..d521284c341 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 @@ -319,14 +319,6 @@ public static EthProtocolManager create( 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/peervalidation/AbstractPeerBlockValidatorTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/peervalidation/AbstractPeerBlockValidatorTest.java index aa289a9f5ae..3e6ee32c418 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 @@ -44,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); @@ -98,7 +102,11 @@ public void validatePeer_requestBlockFromPeerBeingTested() { 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/sync/fastsync/worldstate/FastWorldStateDownloaderTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldStateDownloaderTest.java index fb4888c7640..cbb8f40df9d 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 @@ -239,7 +239,10 @@ void downloadAlreadyAvailableWorldState() { 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(); From c8b6e28d61607ac8d8f1c63a9f85ec1a846f3822 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Thu, 28 Nov 2024 16:11:19 +1100 Subject: [PATCH 5/6] 7311: Replace EthProtocolManagerTestUtil.create(Blockchain) Signed-off-by: Matilda Clerke --- .../besu/ethereum/eth/sync/ChainHeadTrackerTest.java | 3 ++- .../besu/ethereum/eth/sync/DownloadHeadersStepTest.java | 3 ++- .../besu/ethereum/eth/sync/state/SyncStateTest.java | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) 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 f97fe91c6f5..009515600cc 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,6 +27,7 @@ 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.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; @@ -76,7 +77,7 @@ public Stream provideArguments(final ExtensionContext conte 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 3dba7d1cf10..dfc2986610a 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.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 static void setUpClass() { @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/state/SyncStateTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/state/SyncStateTest.java index d3dcb855990..88653f8af37 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.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); From 37bba0f7b3ef1937e54a6ebd3a2dbef367fe5f9d Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Thu, 28 Nov 2024 16:51:53 +1100 Subject: [PATCH 6/6] 7311: Replace EthProtocolManagerTestUtil.create(EthScheduler) Signed-off-by: Matilda Clerke --- .../WorldStateDownloaderBenchmark.java | 15 +++++++++------ .../manager/EthProtocolManagerTestUtil.java | 19 ------------------- .../eth/sync/ChainHeadTrackerTest.java | 1 - .../backwardsync/BackwardSyncStepTest.java | 5 +++-- .../FastWorldStateDownloaderTest.java | 8 ++++++-- 5 files changed, 18 insertions(+), 30 deletions(-) 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 079b6ba47fa..f4764f129dd 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.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 void setUpUnchangedState() { 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/EthProtocolManagerTestUtil.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTestUtil.java index d521284c341..0b328a76e2a 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,19 +15,15 @@ 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; @@ -170,13 +166,6 @@ public static EthProtocolManager create( 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, @@ -192,14 +181,6 @@ public static EthProtocolManager create( 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, 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 009515600cc..6fa8a6ec9d1 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 @@ -28,7 +28,6 @@ import org.hyperledger.besu.ethereum.eth.manager.ChainState; 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; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; 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 696856c0761..76f1e8ea62d 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.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 void setup() { 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/fastsync/worldstate/FastWorldStateDownloaderTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastWorldStateDownloaderTest.java index cbb8f40df9d..431c044cbbf 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 @@ -115,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 { @@ -665,7 +667,9 @@ void doesNotRequestKnownStorageTrieNodesFromNetwork() { @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 =