7311: Adjust to the removal of PeerTaskFeatureToggle and use SynchronizerConfiguration to get the toggle instead

Signed-off-by: Matilda Clerke <matilda.clerke@consensys.net>
pull/7638/head
Matilda Clerke 2 months ago
parent 76724ed3b1
commit fc9b3f2517
  1. 48
      besu/src/test/java/org/hyperledger/besu/RunnerTest.java
  2. 7
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloadBlockStep.java
  3. 2
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncDownloadPipelineFactory.java
  4. 7
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStep.java
  5. 2
      ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java
  6. 13
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckPointSyncChainDownloaderTest.java
  7. 20
      ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStepTest.java
  8. 36
      testutil/src/main/java/org/hyperledger/ethereum/eth/manager/peertask/PeerTaskFeatureToggleTestHelper.java

@ -75,7 +75,6 @@ import org.hyperledger.besu.services.BesuPluginContextImpl;
import org.hyperledger.besu.services.PermissioningServiceImpl; import org.hyperledger.besu.services.PermissioningServiceImpl;
import org.hyperledger.besu.services.RpcEndpointServiceImpl; import org.hyperledger.besu.services.RpcEndpointServiceImpl;
import org.hyperledger.besu.testutil.TestClock; import org.hyperledger.besu.testutil.TestClock;
import org.hyperledger.ethereum.eth.manager.peertask.PeerTaskFeatureToggleTestHelper;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
@ -133,17 +132,6 @@ public final class RunnerTest {
@Test @Test
public void getFixedNodes() throws IllegalAccessException { public void getFixedNodes() throws IllegalAccessException {
PeerTaskFeatureToggleTestHelper.setPeerTaskFeatureToggle(false);
doGetFixedNodes();
}
@Test
public void getFixedNodesUsingPeerTaskSystem() throws IllegalAccessException {
PeerTaskFeatureToggleTestHelper.setPeerTaskFeatureToggle(true);
doGetFixedNodes();
}
private void doGetFixedNodes() {
final EnodeURL staticNode = final EnodeURL staticNode =
EnodeURLImpl.fromString( EnodeURLImpl.fromString(
"enode://8f4b88336cc40ef2516d8b27df812e007fb2384a61e93635f1899051311344f3dcdbb49a4fe49a79f66d2f589a9f282e8cc4f1d7381e8ef7e4fcc6b0db578c77@127.0.0.1:30301"); "enode://8f4b88336cc40ef2516d8b27df812e007fb2384a61e93635f1899051311344f3dcdbb49a4fe49a79f66d2f589a9f282e8cc4f1d7381e8ef7e4fcc6b0db578c77@127.0.0.1:30301");
@ -162,43 +150,40 @@ public final class RunnerTest {
@Test @Test
public void fullSyncFromGenesis() throws Exception { public void fullSyncFromGenesis() throws Exception {
PeerTaskFeatureToggleTestHelper.setPeerTaskFeatureToggle(false); // set merge flag to false, otherwise this test can fail if a merge test runs first
doFullSyncFromGenesis(); MergeConfigOptions.setMergeEnabled(false);
syncFromGenesis(SyncMode.FULL, getFastSyncGenesis(), false);
} }
@Test @Test
public void fullSyncFromGenesisUsingPeerTaskSystem() throws Exception { public void fullSyncFromGenesisUsingPeerTaskSystem() throws Exception {
PeerTaskFeatureToggleTestHelper.setPeerTaskFeatureToggle(true);
doFullSyncFromGenesis();
}
private void doFullSyncFromGenesis() throws Exception {
// set merge flag to false, otherwise this test can fail if a merge test runs first // set merge flag to false, otherwise this test can fail if a merge test runs first
MergeConfigOptions.setMergeEnabled(false); MergeConfigOptions.setMergeEnabled(false);
syncFromGenesis(SyncMode.FULL, getFastSyncGenesis()); syncFromGenesis(SyncMode.FULL, getFastSyncGenesis(), true);
} }
@Test @Test
public void fastSyncFromGenesis() throws Exception { public void fastSyncFromGenesis() throws Exception {
PeerTaskFeatureToggleTestHelper.setPeerTaskFeatureToggle(false); // set merge flag to false, otherwise this test can fail if a merge test runs first
doFastSyncFromGenesis(); MergeConfigOptions.setMergeEnabled(false);
syncFromGenesis(SyncMode.FAST, getFastSyncGenesis(), false);
} }
@Test @Test
public void fastSyncFromGenesisUsingPeerTaskSystem() throws Exception { public void fastSyncFromGenesisUsingPeerTaskSystem() throws Exception {
PeerTaskFeatureToggleTestHelper.setPeerTaskFeatureToggle(true);
doFastSyncFromGenesis();
}
private void doFastSyncFromGenesis() throws Exception {
// set merge flag to false, otherwise this test can fail if a merge test runs first // set merge flag to false, otherwise this test can fail if a merge test runs first
MergeConfigOptions.setMergeEnabled(false); MergeConfigOptions.setMergeEnabled(false);
syncFromGenesis(SyncMode.FAST, getFastSyncGenesis()); syncFromGenesis(SyncMode.FAST, getFastSyncGenesis(), true);
} }
private void syncFromGenesis(final SyncMode mode, final GenesisConfigFile genesisConfig) private void syncFromGenesis(
final SyncMode mode,
final GenesisConfigFile genesisConfig,
final boolean isPeerTaskSystemEnabled)
throws Exception { throws Exception {
final Path dataDirAhead = Files.createTempDirectory(temp, "db-ahead"); final Path dataDirAhead = Files.createTempDirectory(temp, "db-ahead");
final Path dbAhead = dataDirAhead.resolve("database"); final Path dbAhead = dataDirAhead.resolve("database");
@ -206,7 +191,10 @@ public final class RunnerTest {
final NodeKey aheadDbNodeKey = NodeKeyUtils.createFrom(KeyPairUtil.loadKeyPair(dataDirAhead)); final NodeKey aheadDbNodeKey = NodeKeyUtils.createFrom(KeyPairUtil.loadKeyPair(dataDirAhead));
final NodeKey behindDbNodeKey = NodeKeyUtils.generate(); final NodeKey behindDbNodeKey = NodeKeyUtils.generate();
final SynchronizerConfiguration syncConfigAhead = final SynchronizerConfiguration syncConfigAhead =
SynchronizerConfiguration.builder().syncMode(SyncMode.FULL).build(); SynchronizerConfiguration.builder()
.syncMode(SyncMode.FULL)
.isPeerTaskSystemEnabled(isPeerTaskSystemEnabled)
.build();
final ObservableMetricsSystem noOpMetricsSystem = new NoOpMetricsSystem(); final ObservableMetricsSystem noOpMetricsSystem = new NoOpMetricsSystem();
final var miningParameters = MiningParameters.newDefault(); final var miningParameters = MiningParameters.newDefault();
final var dataStorageConfiguration = DataStorageConfiguration.DEFAULT_FOREST_CONFIG; final var dataStorageConfiguration = DataStorageConfiguration.DEFAULT_FOREST_CONFIG;

@ -23,10 +23,10 @@ import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor;
import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResponseCode; import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResponseCode;
import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResult; import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResult;
import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskFeatureToggle;
import org.hyperledger.besu.ethereum.eth.manager.peertask.task.GetReceiptsFromPeerTask; import org.hyperledger.besu.ethereum.eth.manager.peertask.task.GetReceiptsFromPeerTask;
import org.hyperledger.besu.ethereum.eth.manager.task.AbstractPeerTask.PeerTaskResult; import org.hyperledger.besu.ethereum.eth.manager.task.AbstractPeerTask.PeerTaskResult;
import org.hyperledger.besu.ethereum.eth.manager.task.GetBlockFromPeerTask; import org.hyperledger.besu.ethereum.eth.manager.task.GetBlockFromPeerTask;
import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration;
import org.hyperledger.besu.ethereum.eth.sync.fastsync.checkpoint.Checkpoint; import org.hyperledger.besu.ethereum.eth.sync.fastsync.checkpoint.Checkpoint;
import org.hyperledger.besu.ethereum.mainnet.BodyValidator; import org.hyperledger.besu.ethereum.mainnet.BodyValidator;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
@ -43,6 +43,7 @@ public class CheckpointDownloadBlockStep {
private final EthContext ethContext; private final EthContext ethContext;
private final PeerTaskExecutor peerTaskExecutor; private final PeerTaskExecutor peerTaskExecutor;
private final Checkpoint checkpoint; private final Checkpoint checkpoint;
private final SynchronizerConfiguration synchronizerConfiguration;
private final MetricsSystem metricsSystem; private final MetricsSystem metricsSystem;
public CheckpointDownloadBlockStep( public CheckpointDownloadBlockStep(
@ -50,11 +51,13 @@ public class CheckpointDownloadBlockStep {
final EthContext ethContext, final EthContext ethContext,
final PeerTaskExecutor peerTaskExecutor, final PeerTaskExecutor peerTaskExecutor,
final Checkpoint checkpoint, final Checkpoint checkpoint,
final SynchronizerConfiguration synchronizerConfiguration,
final MetricsSystem metricsSystem) { final MetricsSystem metricsSystem) {
this.protocolSchedule = protocolSchedule; this.protocolSchedule = protocolSchedule;
this.ethContext = ethContext; this.ethContext = ethContext;
this.peerTaskExecutor = peerTaskExecutor; this.peerTaskExecutor = peerTaskExecutor;
this.checkpoint = checkpoint; this.checkpoint = checkpoint;
this.synchronizerConfiguration = synchronizerConfiguration;
this.metricsSystem = metricsSystem; this.metricsSystem = metricsSystem;
} }
@ -75,7 +78,7 @@ public class CheckpointDownloadBlockStep {
private CompletableFuture<Optional<BlockWithReceipts>> downloadReceipts( private CompletableFuture<Optional<BlockWithReceipts>> downloadReceipts(
final PeerTaskResult<Block> peerTaskResult) { final PeerTaskResult<Block> peerTaskResult) {
final Block block = peerTaskResult.getResult(); final Block block = peerTaskResult.getResult();
if (PeerTaskFeatureToggle.usePeerTaskSystem()) { if (synchronizerConfiguration.isPeerTaskSystemEnabled()) {
CompletableFuture<Optional<BlockWithReceipts>> futureReceipts = new CompletableFuture<>(); CompletableFuture<Optional<BlockWithReceipts>> futureReceipts = new CompletableFuture<>();
GetReceiptsFromPeerTask task = GetReceiptsFromPeerTask task =
new GetReceiptsFromPeerTask(List.of(block.getHeader()), new BodyValidator()); new GetReceiptsFromPeerTask(List.of(block.getHeader()), new BodyValidator());

@ -86,7 +86,7 @@ public class CheckpointSyncDownloadPipelineFactory extends FastSyncDownloadPipel
final CheckpointDownloadBlockStep checkPointDownloadBlockStep = final CheckpointDownloadBlockStep checkPointDownloadBlockStep =
new CheckpointDownloadBlockStep( new CheckpointDownloadBlockStep(
protocolSchedule, ethContext, peerTaskExecutor, checkpoint, metricsSystem); protocolSchedule, ethContext, peerTaskExecutor, checkpoint, syncConfig, metricsSystem);
return PipelineBuilder.createPipelineFrom( return PipelineBuilder.createPipelineFrom(
"fetchCheckpoints", "fetchCheckpoints",

@ -25,8 +25,8 @@ import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor; import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor;
import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResponseCode; import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResponseCode;
import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResult; import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResult;
import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskFeatureToggle;
import org.hyperledger.besu.ethereum.eth.manager.peertask.task.GetReceiptsFromPeerTask; import org.hyperledger.besu.ethereum.eth.manager.peertask.task.GetReceiptsFromPeerTask;
import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration;
import org.hyperledger.besu.ethereum.eth.sync.tasks.GetReceiptsForHeadersTask; import org.hyperledger.besu.ethereum.eth.sync.tasks.GetReceiptsForHeadersTask;
import org.hyperledger.besu.ethereum.mainnet.BodyValidator; import org.hyperledger.besu.ethereum.mainnet.BodyValidator;
import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.MetricsSystem;
@ -42,14 +42,17 @@ public class DownloadReceiptsStep
implements Function<List<Block>, CompletableFuture<List<BlockWithReceipts>>> { implements Function<List<Block>, CompletableFuture<List<BlockWithReceipts>>> {
private final EthContext ethContext; private final EthContext ethContext;
private final PeerTaskExecutor peerTaskExecutor; private final PeerTaskExecutor peerTaskExecutor;
private final SynchronizerConfiguration synchronizerConfiguration;
private final MetricsSystem metricsSystem; private final MetricsSystem metricsSystem;
public DownloadReceiptsStep( public DownloadReceiptsStep(
final EthContext ethContext, final EthContext ethContext,
final PeerTaskExecutor peerTaskExecutor, final PeerTaskExecutor peerTaskExecutor,
final SynchronizerConfiguration synchronizerConfiguration,
final MetricsSystem metricsSystem) { final MetricsSystem metricsSystem) {
this.ethContext = ethContext; this.ethContext = ethContext;
this.peerTaskExecutor = peerTaskExecutor; this.peerTaskExecutor = peerTaskExecutor;
this.synchronizerConfiguration = synchronizerConfiguration;
this.metricsSystem = metricsSystem; this.metricsSystem = metricsSystem;
} }
@ -57,7 +60,7 @@ public class DownloadReceiptsStep
public CompletableFuture<List<BlockWithReceipts>> apply(final List<Block> blocks) { public CompletableFuture<List<BlockWithReceipts>> apply(final List<Block> blocks) {
final List<BlockHeader> headers = blocks.stream().map(Block::getHeader).collect(toList()); final List<BlockHeader> headers = blocks.stream().map(Block::getHeader).collect(toList());
final CompletableFuture<Map<BlockHeader, List<TransactionReceipt>>> getReceipts; final CompletableFuture<Map<BlockHeader, List<TransactionReceipt>>> getReceipts;
if (PeerTaskFeatureToggle.usePeerTaskSystem()) { if (synchronizerConfiguration.isPeerTaskSystemEnabled()) {
GetReceiptsFromPeerTask getReceiptsFromPeerTask = GetReceiptsFromPeerTask getReceiptsFromPeerTask =
new GetReceiptsFromPeerTask(headers, new BodyValidator()); new GetReceiptsFromPeerTask(headers, new BodyValidator());
PeerTaskExecutorResult<Map<BlockHeader, List<TransactionReceipt>>> getReceiptsResult = PeerTaskExecutorResult<Map<BlockHeader, List<TransactionReceipt>>> getReceiptsResult =

@ -144,7 +144,7 @@ public class FastSyncDownloadPipelineFactory implements DownloadPipelineFactory
final DownloadBodiesStep downloadBodiesStep = final DownloadBodiesStep downloadBodiesStep =
new DownloadBodiesStep(protocolSchedule, ethContext, metricsSystem); new DownloadBodiesStep(protocolSchedule, ethContext, metricsSystem);
final DownloadReceiptsStep downloadReceiptsStep = final DownloadReceiptsStep downloadReceiptsStep =
new DownloadReceiptsStep(ethContext, peerTaskExecutor, metricsSystem); new DownloadReceiptsStep(ethContext, peerTaskExecutor, syncConfig, metricsSystem);
final ImportBlocksStep importBlockStep = final ImportBlocksStep importBlockStep =
new ImportBlocksStep( new ImportBlocksStep(
protocolSchedule, protocolSchedule,

@ -49,7 +49,6 @@ import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator;
import org.hyperledger.besu.metrics.SyncDurationMetrics; import org.hyperledger.besu.metrics.SyncDurationMetrics;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;
import org.hyperledger.ethereum.eth.manager.peertask.PeerTaskFeatureToggleTestHelper;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Collection; import java.util.Collection;
@ -221,7 +220,6 @@ public class CheckPointSyncChainDownloaderTest {
@ArgumentsSource(CheckPointSyncChainDownloaderTestArguments.class) @ArgumentsSource(CheckPointSyncChainDownloaderTestArguments.class)
public void shouldSyncToPivotBlockInMultipleSegments(final DataStorageFormat storageFormat) public void shouldSyncToPivotBlockInMultipleSegments(final DataStorageFormat storageFormat)
throws IllegalAccessException { throws IllegalAccessException {
PeerTaskFeatureToggleTestHelper.setPeerTaskFeatureToggle(false);
setup(storageFormat); setup(storageFormat);
final RespondingEthPeer peer = final RespondingEthPeer peer =
@ -233,6 +231,7 @@ public class CheckPointSyncChainDownloaderTest {
SynchronizerConfiguration.builder() SynchronizerConfiguration.builder()
.downloaderChainSegmentSize(5) .downloaderChainSegmentSize(5)
.downloaderHeadersRequestSize(3) .downloaderHeadersRequestSize(3)
.isPeerTaskSystemEnabled(false)
.build(); .build();
final long pivotBlockNumber = 25; final long pivotBlockNumber = 25;
ethContext ethContext
@ -258,7 +257,6 @@ public class CheckPointSyncChainDownloaderTest {
@ArgumentsSource(CheckPointSyncChainDownloaderTestArguments.class) @ArgumentsSource(CheckPointSyncChainDownloaderTestArguments.class)
public void shouldSyncToPivotBlockInSingleSegment(final DataStorageFormat storageFormat) public void shouldSyncToPivotBlockInSingleSegment(final DataStorageFormat storageFormat)
throws IllegalAccessException { throws IllegalAccessException {
PeerTaskFeatureToggleTestHelper.setPeerTaskFeatureToggle(false);
setup(storageFormat); setup(storageFormat);
final RespondingEthPeer peer = final RespondingEthPeer peer =
@ -267,7 +265,8 @@ public class CheckPointSyncChainDownloaderTest {
RespondingEthPeer.blockchainResponder(otherBlockchain); RespondingEthPeer.blockchainResponder(otherBlockchain);
final long pivotBlockNumber = 10; final long pivotBlockNumber = 10;
final SynchronizerConfiguration syncConfig = SynchronizerConfiguration.builder().build(); final SynchronizerConfiguration syncConfig =
SynchronizerConfiguration.builder().isPeerTaskSystemEnabled(false).build();
ethContext ethContext
.getEthPeers() .getEthPeers()
.streamAvailablePeers() .streamAvailablePeers()
@ -292,7 +291,6 @@ public class CheckPointSyncChainDownloaderTest {
public void shouldSyncToPivotBlockInMultipleSegmentsWithPeerTaskSystem( public void shouldSyncToPivotBlockInMultipleSegmentsWithPeerTaskSystem(
final DataStorageFormat storageFormat) final DataStorageFormat storageFormat)
throws IllegalAccessException, ExecutionException, InterruptedException, TimeoutException { throws IllegalAccessException, ExecutionException, InterruptedException, TimeoutException {
PeerTaskFeatureToggleTestHelper.setPeerTaskFeatureToggle(true);
setup(storageFormat); setup(storageFormat);
final RespondingEthPeer peer = final RespondingEthPeer peer =
@ -304,6 +302,7 @@ public class CheckPointSyncChainDownloaderTest {
SynchronizerConfiguration.builder() SynchronizerConfiguration.builder()
.downloaderChainSegmentSize(5) .downloaderChainSegmentSize(5)
.downloaderHeadersRequestSize(3) .downloaderHeadersRequestSize(3)
.isPeerTaskSystemEnabled(true)
.build(); .build();
final long pivotBlockNumber = 25; final long pivotBlockNumber = 25;
ethContext ethContext
@ -329,7 +328,6 @@ public class CheckPointSyncChainDownloaderTest {
@ArgumentsSource(CheckPointSyncChainDownloaderTestArguments.class) @ArgumentsSource(CheckPointSyncChainDownloaderTestArguments.class)
public void shouldSyncToPivotBlockInSingleSegmentWithPeerTaskSystem( public void shouldSyncToPivotBlockInSingleSegmentWithPeerTaskSystem(
final DataStorageFormat storageFormat) throws IllegalAccessException { final DataStorageFormat storageFormat) throws IllegalAccessException {
PeerTaskFeatureToggleTestHelper.setPeerTaskFeatureToggle(true);
setup(storageFormat); setup(storageFormat);
final RespondingEthPeer peer = final RespondingEthPeer peer =
@ -338,7 +336,8 @@ public class CheckPointSyncChainDownloaderTest {
RespondingEthPeer.blockchainResponder(otherBlockchain); RespondingEthPeer.blockchainResponder(otherBlockchain);
final long pivotBlockNumber = 10; final long pivotBlockNumber = 10;
final SynchronizerConfiguration syncConfig = SynchronizerConfiguration.builder().build(); final SynchronizerConfiguration syncConfig =
SynchronizerConfiguration.builder().isPeerTaskSystemEnabled(true).build();
ethContext ethContext
.getEthPeers() .getEthPeers()
.streamAvailablePeers() .streamAvailablePeers()

@ -34,10 +34,10 @@ import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutor;
import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResponseCode; import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResponseCode;
import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResult; import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskExecutorResult;
import org.hyperledger.besu.ethereum.eth.manager.peertask.task.GetReceiptsFromPeerTask; import org.hyperledger.besu.ethereum.eth.manager.peertask.task.GetReceiptsFromPeerTask;
import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.services.storage.DataStorageFormat; import org.hyperledger.besu.plugin.services.storage.DataStorageFormat;
import org.hyperledger.ethereum.eth.manager.peertask.PeerTaskFeatureToggleTestHelper;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -57,7 +57,6 @@ public class DownloadReceiptsStepTest {
private PeerTaskExecutor peerTaskExecutor; private PeerTaskExecutor peerTaskExecutor;
private EthProtocolManager ethProtocolManager; private EthProtocolManager ethProtocolManager;
private DownloadReceiptsStep downloadReceiptsStep;
@BeforeAll @BeforeAll
public static void setUpClass() { public static void setUpClass() {
@ -79,14 +78,16 @@ public class DownloadReceiptsStepTest {
protocolContext.getWorldStateArchive(), protocolContext.getWorldStateArchive(),
transactionPool, transactionPool,
EthProtocolConfiguration.defaultConfig()); EthProtocolConfiguration.defaultConfig());
downloadReceiptsStep =
new DownloadReceiptsStep(
ethProtocolManager.ethContext(), peerTaskExecutor, new NoOpMetricsSystem());
} }
@Test @Test
public void shouldDownloadReceiptsForBlocks() throws IllegalAccessException { public void shouldDownloadReceiptsForBlocks() throws IllegalAccessException {
PeerTaskFeatureToggleTestHelper.setPeerTaskFeatureToggle(false); DownloadReceiptsStep downloadReceiptsStep =
new DownloadReceiptsStep(
ethProtocolManager.ethContext(),
peerTaskExecutor,
SynchronizerConfiguration.builder().isPeerTaskSystemEnabled(false).build(),
new NoOpMetricsSystem());
final RespondingEthPeer peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, 1000); final RespondingEthPeer peer = EthProtocolManagerTestUtil.createPeer(ethProtocolManager, 1000);
final List<Block> blocks = asList(block(1), block(2), block(3), block(4)); final List<Block> blocks = asList(block(1), block(2), block(3), block(4));
@ -106,7 +107,12 @@ public class DownloadReceiptsStepTest {
@Test @Test
public void shouldDownloadReceiptsForBlocksUsingPeerTaskSystem() public void shouldDownloadReceiptsForBlocksUsingPeerTaskSystem()
throws IllegalAccessException, ExecutionException, InterruptedException { throws IllegalAccessException, ExecutionException, InterruptedException {
PeerTaskFeatureToggleTestHelper.setPeerTaskFeatureToggle(true); DownloadReceiptsStep downloadReceiptsStep =
new DownloadReceiptsStep(
ethProtocolManager.ethContext(),
peerTaskExecutor,
SynchronizerConfiguration.builder().isPeerTaskSystemEnabled(true).build(),
new NoOpMetricsSystem());
final List<Block> blocks = asList(mockBlock(), mockBlock(), mockBlock(), mockBlock()); final List<Block> blocks = asList(mockBlock(), mockBlock(), mockBlock(), mockBlock());
Map<BlockHeader, List<TransactionReceipt>> receiptsMap = new HashMap<>(); Map<BlockHeader, List<TransactionReceipt>> receiptsMap = new HashMap<>();

@ -1,36 +0,0 @@
/*
* Copyright contributors to Hyperledger 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.ethereum.eth.manager.peertask;
import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskFeatureToggle;
import java.lang.reflect.Field;
import org.junit.platform.commons.util.ReflectionUtils;
public class PeerTaskFeatureToggleTestHelper {
public static void setPeerTaskFeatureToggle(final boolean usePeerTaskSystem)
throws IllegalAccessException {
Field usePeerTaskSystemField =
ReflectionUtils.findFields(
PeerTaskFeatureToggle.class,
(f) -> f.getName().equals("USE_PEER_TASK_SYSTEM"),
ReflectionUtils.HierarchyTraversalMode.TOP_DOWN)
.getFirst();
usePeerTaskSystemField.setAccessible(true);
usePeerTaskSystemField.set(null, usePeerTaskSystem);
}
}
Loading…
Cancel
Save