From 37bba0f7b3ef1937e54a6ebd3a2dbef367fe5f9d Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Thu, 28 Nov 2024 16:51:53 +1100 Subject: [PATCH] 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 =