From 86a1f0bf5139afe24c350ab6f3fca0ff8a791870 Mon Sep 17 00:00:00 2001 From: Matilda Clerke Date: Wed, 9 Oct 2024 10:14:58 +1100 Subject: [PATCH] 7311: Add protocol spec supplier to GetReceiptsFromPeerTask Signed-off-by: Matilda Clerke --- .../controller/BesuControllerBuilder.java | 3 +++ .../TransitionBesuControllerBuilder.java | 4 ++++ .../besu/ethereum/eth/manager/EthPeers.java | 5 ++++- .../task/GetReceiptsFromPeerTask.java | 11 +++++++++-- .../eth/sync/DefaultSynchronizer.java | 5 +++++ .../CheckpointDownloadBlockStep.java | 8 +++++++- .../CheckpointDownloaderFactory.java | 5 +++++ .../checkpointsync/CheckpointSyncActions.java | 6 ++++++ .../CheckpointSyncChainDownloader.java | 5 +++++ ...CheckpointSyncDownloadPipelineFactory.java | 12 +++++++++++- .../sync/fastsync/DownloadReceiptsStep.java | 8 +++++++- .../eth/sync/fastsync/FastSyncActions.java | 5 +++++ .../fastsync/FastSyncChainDownloader.java | 5 +++++ .../FastSyncDownloadPipelineFactory.java | 8 +++++++- .../worldstate/FastDownloaderFactory.java | 4 ++++ .../sync/snapsync/SnapDownloaderFactory.java | 4 ++++ .../task/GetReceiptsFromPeerTaskTest.java | 19 +++++++++++++------ .../CheckPointSyncChainDownloaderTest.java | 3 ++- .../fastsync/DownloadReceiptsStepTest.java | 2 ++ .../fastsync/FastDownloaderFactoryTest.java | 5 +++++ .../sync/fastsync/FastSyncActionsTest.java | 3 ++- .../fastsync/FastSyncChainDownloaderTest.java | 3 ++- 22 files changed, 117 insertions(+), 16 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java index 46d7d10fc7..d1e04d451b 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java @@ -705,6 +705,7 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides final DefaultSynchronizer synchronizer = createSynchronizer( protocolSchedule, + currentProtocolSpecSupplier, worldStateStorageCoordinator, protocolContext, ethContext, @@ -839,6 +840,7 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides */ protected DefaultSynchronizer createSynchronizer( final ProtocolSchedule protocolSchedule, + final Supplier currentProtocolSpecSupplier, final WorldStateStorageCoordinator worldStateStorageCoordinator, final ProtocolContext protocolContext, final EthContext ethContext, @@ -850,6 +852,7 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides return new DefaultSynchronizer( syncConfig, protocolSchedule, + currentProtocolSpecSupplier, protocolContext, worldStateStorageCoordinator, ethProtocolManager.getBlockBroadcaster(), diff --git a/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java index 703592f90a..a363efed44 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java @@ -51,6 +51,7 @@ import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; import org.hyperledger.besu.ethereum.forkid.ForkIdManager; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.storage.StorageProvider; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; @@ -66,6 +67,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.function.Consumer; +import java.util.function.Supplier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -223,6 +225,7 @@ public class TransitionBesuControllerBuilder extends BesuControllerBuilder { @Override protected DefaultSynchronizer createSynchronizer( final ProtocolSchedule protocolSchedule, + final Supplier currentProtocolSpecSupplier, final WorldStateStorageCoordinator worldStateStorageCoordinator, final ProtocolContext protocolContext, final EthContext ethContext, @@ -234,6 +237,7 @@ public class TransitionBesuControllerBuilder extends BesuControllerBuilder { DefaultSynchronizer sync = super.createSynchronizer( protocolSchedule, + currentProtocolSpecSupplier, worldStateStorageCoordinator, protocolContext, ethContext, diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java index d070c35ce1..a721697717 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeers.java @@ -470,7 +470,10 @@ public class EthPeers implements PeerSelector { // Part of the PeerSelector interface, to be split apart later @Override public Optional getPeer(final Predicate filter) { - return streamBestPeers().filter(filter).filter(EthPeer::hasAvailableRequestCapacity).findFirst(); + return streamBestPeers() + .filter(filter) + .filter(EthPeer::hasAvailableRequestCapacity) + .findFirst(); } // Part of the PeerSelector interface, to be split apart later diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTask.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTask.java index 544f73b782..706e8779a7 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTask.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTask.java @@ -25,6 +25,7 @@ import org.hyperledger.besu.ethereum.eth.manager.peertask.PeerTaskRetryBehavior; import org.hyperledger.besu.ethereum.eth.messages.GetReceiptsMessage; import org.hyperledger.besu.ethereum.eth.messages.ReceiptsMessage; import org.hyperledger.besu.ethereum.mainnet.BodyValidator; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.SubProtocol; @@ -34,19 +35,24 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Predicate; +import java.util.function.Supplier; public class GetReceiptsFromPeerTask implements PeerTask>> { private final Collection blockHeaders; private final BodyValidator bodyValidator; + private final Supplier currentProtocolSpecSupplier; private final Map> headersByReceiptsRoot = new HashMap<>(); private final long requiredBlockchainHeight; public GetReceiptsFromPeerTask( - final Collection blockHeaders, final BodyValidator bodyValidator) { + final Collection blockHeaders, + final BodyValidator bodyValidator, + final Supplier currentProtocolSpecSupplier) { this.blockHeaders = blockHeaders; this.bodyValidator = bodyValidator; + this.currentProtocolSpecSupplier = currentProtocolSpecSupplier; blockHeaders.forEach( header -> @@ -112,6 +118,7 @@ public class GetReceiptsFromPeerTask public Predicate getPeerRequirementFilter() { return (ethPeer) -> ethPeer.getProtocolName().equals(getSubProtocol().getName()) - && ethPeer.chainState().getEstimatedHeight() >= requiredBlockchainHeight; + && (currentProtocolSpecSupplier.get().isPoS() + || ethPeer.chainState().getEstimatedHeight() >= requiredBlockchainHeight); } } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java index f012bbd7ae..bbaea66432 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java @@ -35,6 +35,7 @@ import org.hyperledger.besu.ethereum.eth.sync.snapsync.context.SnapSyncStatePers import org.hyperledger.besu.ethereum.eth.sync.state.PendingBlocksManager; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.storage.StorageProvider; import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.BonsaiWorldStateProvider; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; @@ -79,6 +80,7 @@ public class DefaultSynchronizer implements Synchronizer, UnverifiedForkchoiceLi public DefaultSynchronizer( final SynchronizerConfiguration syncConfig, final ProtocolSchedule protocolSchedule, + final Supplier currentProtocolSpecSupplier, final ProtocolContext protocolContext, final WorldStateStorageCoordinator worldStateStorageCoordinator, final BlockBroadcaster blockBroadcaster, @@ -146,6 +148,7 @@ public class DefaultSynchronizer implements Synchronizer, UnverifiedForkchoiceLi syncConfig, dataDirectory, protocolSchedule, + currentProtocolSpecSupplier, protocolContext, metricsSystem, ethContext, @@ -163,6 +166,7 @@ public class DefaultSynchronizer implements Synchronizer, UnverifiedForkchoiceLi syncConfig, dataDirectory, protocolSchedule, + currentProtocolSpecSupplier, protocolContext, metricsSystem, ethContext, @@ -180,6 +184,7 @@ public class DefaultSynchronizer implements Synchronizer, UnverifiedForkchoiceLi syncConfig, dataDirectory, protocolSchedule, + currentProtocolSpecSupplier, protocolContext, metricsSystem, ethContext, diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloadBlockStep.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloadBlockStep.java index a0bb5ee595..70e9958bea 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloadBlockStep.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloadBlockStep.java @@ -30,16 +30,19 @@ import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; import org.hyperledger.besu.ethereum.eth.sync.fastsync.checkpoint.Checkpoint; import org.hyperledger.besu.ethereum.mainnet.BodyValidator; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.plugin.services.MetricsSystem; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; public class CheckpointDownloadBlockStep { private final ProtocolSchedule protocolSchedule; + private final Supplier currentProtocolSpecSupplier; private final EthContext ethContext; private final PeerTaskExecutor peerTaskExecutor; private final Checkpoint checkpoint; @@ -48,12 +51,14 @@ public class CheckpointDownloadBlockStep { public CheckpointDownloadBlockStep( final ProtocolSchedule protocolSchedule, + final Supplier currentProtocolSpecSupplier, final EthContext ethContext, final PeerTaskExecutor peerTaskExecutor, final Checkpoint checkpoint, final SynchronizerConfiguration synchronizerConfiguration, final MetricsSystem metricsSystem) { this.protocolSchedule = protocolSchedule; + this.currentProtocolSpecSupplier = currentProtocolSpecSupplier; this.ethContext = ethContext; this.peerTaskExecutor = peerTaskExecutor; this.checkpoint = checkpoint; @@ -81,7 +86,8 @@ public class CheckpointDownloadBlockStep { if (synchronizerConfiguration.isPeerTaskSystemEnabled()) { CompletableFuture> futureReceipts = new CompletableFuture<>(); GetReceiptsFromPeerTask task = - new GetReceiptsFromPeerTask(List.of(block.getHeader()), new BodyValidator()); + new GetReceiptsFromPeerTask( + List.of(block.getHeader()), new BodyValidator(), currentProtocolSpecSupplier); PeerTaskExecutorResult>> executorResult = peerTaskExecutor.execute(task); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloaderFactory.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloaderFactory.java index 30134d9f6c..e8a6fe2804 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloaderFactory.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointDownloaderFactory.java @@ -34,6 +34,7 @@ import org.hyperledger.besu.ethereum.eth.sync.snapsync.request.SnapDataRequest; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; import org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldStateDownloader; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions; import org.hyperledger.besu.ethereum.trie.CompactEncoding; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; @@ -44,6 +45,7 @@ import org.hyperledger.besu.services.tasks.InMemoryTasksPriorityQueues; import java.nio.file.Path; import java.time.Clock; import java.util.Optional; +import java.util.function.Supplier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,6 +61,7 @@ public class CheckpointDownloaderFactory extends SnapDownloaderFactory { final SynchronizerConfiguration syncConfig, final Path dataDirectory, final ProtocolSchedule protocolSchedule, + final Supplier currentProtocolSpecSupplier, final ProtocolContext protocolContext, final MetricsSystem metricsSystem, final EthContext ethContext, @@ -110,6 +113,7 @@ public class CheckpointDownloaderFactory extends SnapDownloaderFactory { syncConfig, worldStateStorageCoordinator, protocolSchedule, + currentProtocolSpecSupplier, protocolContext, ethContext, peerTaskExecutor, @@ -128,6 +132,7 @@ public class CheckpointDownloaderFactory extends SnapDownloaderFactory { syncConfig, worldStateStorageCoordinator, protocolSchedule, + currentProtocolSpecSupplier, protocolContext, ethContext, peerTaskExecutor, diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncActions.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncActions.java index 61b997e6c5..ebc86836b0 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncActions.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncActions.java @@ -24,15 +24,19 @@ import org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncActions; import org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncState; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.metrics.SyncDurationMetrics; import org.hyperledger.besu.plugin.services.MetricsSystem; +import java.util.function.Supplier; + public class CheckpointSyncActions extends FastSyncActions { public CheckpointSyncActions( final SynchronizerConfiguration syncConfig, final WorldStateStorageCoordinator worldStateStorageCoordinator, final ProtocolSchedule protocolSchedule, + final Supplier currentProtocolSpecSupplier, final ProtocolContext protocolContext, final EthContext ethContext, final PeerTaskExecutor peerTaskExecutor, @@ -43,6 +47,7 @@ public class CheckpointSyncActions extends FastSyncActions { syncConfig, worldStateStorageCoordinator, protocolSchedule, + currentProtocolSpecSupplier, protocolContext, ethContext, peerTaskExecutor, @@ -58,6 +63,7 @@ public class CheckpointSyncActions extends FastSyncActions { syncConfig, worldStateStorageCoordinator, protocolSchedule, + currentProtocolSpecSupplier, protocolContext, ethContext, peerTaskExecutor, diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncChainDownloader.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncChainDownloader.java index 2590e4736a..58fbec93e0 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncChainDownloader.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncChainDownloader.java @@ -25,16 +25,20 @@ import org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncState; import org.hyperledger.besu.ethereum.eth.sync.fastsync.SyncTargetManager; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.metrics.SyncDurationMetrics; import org.hyperledger.besu.plugin.services.MetricsSystem; +import java.util.function.Supplier; + public class CheckpointSyncChainDownloader extends FastSyncChainDownloader { public static ChainDownloader create( final SynchronizerConfiguration config, final WorldStateStorageCoordinator worldStateStorageCoordinator, final ProtocolSchedule protocolSchedule, + final Supplier currentProtocolSpecSupplier, final ProtocolContext protocolContext, final EthContext ethContext, final PeerTaskExecutor peerTaskExecutor, @@ -59,6 +63,7 @@ public class CheckpointSyncChainDownloader extends FastSyncChainDownloader { new CheckpointSyncDownloadPipelineFactory( config, protocolSchedule, + currentProtocolSpecSupplier, protocolContext, ethContext, peerTaskExecutor, diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncDownloadPipelineFactory.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncDownloadPipelineFactory.java index 0be1086986..696d5e8d0f 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncDownloadPipelineFactory.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/checkpointsync/CheckpointSyncDownloadPipelineFactory.java @@ -27,18 +27,21 @@ import org.hyperledger.besu.ethereum.eth.sync.fastsync.checkpoint.Checkpoint; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; import org.hyperledger.besu.ethereum.eth.sync.state.SyncTarget; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.services.pipeline.Pipeline; import org.hyperledger.besu.services.pipeline.PipelineBuilder; import java.util.concurrent.CompletionStage; +import java.util.function.Supplier; public class CheckpointSyncDownloadPipelineFactory extends FastSyncDownloadPipelineFactory { public CheckpointSyncDownloadPipelineFactory( final SynchronizerConfiguration syncConfig, final ProtocolSchedule protocolSchedule, + final Supplier currentProtocolSpecSupplier, final ProtocolContext protocolContext, final EthContext ethContext, final PeerTaskExecutor peerTaskExecutor, @@ -47,6 +50,7 @@ public class CheckpointSyncDownloadPipelineFactory extends FastSyncDownloadPipel super( syncConfig, protocolSchedule, + currentProtocolSpecSupplier, protocolContext, ethContext, peerTaskExecutor, @@ -86,7 +90,13 @@ public class CheckpointSyncDownloadPipelineFactory extends FastSyncDownloadPipel final CheckpointDownloadBlockStep checkPointDownloadBlockStep = new CheckpointDownloadBlockStep( - protocolSchedule, ethContext, peerTaskExecutor, checkpoint, syncConfig, metricsSystem); + protocolSchedule, + currentProtocolSpecSupplier, + ethContext, + peerTaskExecutor, + checkpoint, + syncConfig, + metricsSystem); return PipelineBuilder.createPipelineFrom( "fetchCheckpoints", diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStep.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStep.java index 8ee7ef414a..65e6f84636 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStep.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStep.java @@ -29,6 +29,7 @@ import org.hyperledger.besu.ethereum.eth.manager.peertask.task.GetReceiptsFromPe import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; import org.hyperledger.besu.ethereum.eth.sync.tasks.GetReceiptsForHeadersTask; import org.hyperledger.besu.ethereum.mainnet.BodyValidator; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.plugin.services.MetricsSystem; import java.util.HashMap; @@ -36,20 +37,24 @@ import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.function.Function; +import java.util.function.Supplier; public class DownloadReceiptsStep implements Function, CompletableFuture>> { + private final Supplier currentProtocolSpecSupplier; private final EthContext ethContext; private final PeerTaskExecutor peerTaskExecutor; private final SynchronizerConfiguration synchronizerConfiguration; private final MetricsSystem metricsSystem; public DownloadReceiptsStep( + final Supplier currentProtocolSpecSupplier, final EthContext ethContext, final PeerTaskExecutor peerTaskExecutor, final SynchronizerConfiguration synchronizerConfiguration, final MetricsSystem metricsSystem) { + this.currentProtocolSpecSupplier = currentProtocolSpecSupplier; this.ethContext = ethContext; this.peerTaskExecutor = peerTaskExecutor; this.synchronizerConfiguration = synchronizerConfiguration; @@ -76,7 +81,8 @@ public class DownloadReceiptsStep getReceiptsWithPeerTaskSystem(final List headers) { Map> getReceipts = new HashMap<>(); do { - GetReceiptsFromPeerTask task = new GetReceiptsFromPeerTask(headers, new BodyValidator()); + GetReceiptsFromPeerTask task = + new GetReceiptsFromPeerTask(headers, new BodyValidator(), currentProtocolSpecSupplier); PeerTaskExecutorResult>> getReceiptsResult = peerTaskExecutor.execute(task); if (getReceiptsResult.responseCode() == PeerTaskExecutorResponseCode.SUCCESS diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActions.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActions.java index 58a64bd562..b1b31298fc 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActions.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncActions.java @@ -27,6 +27,7 @@ import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; import org.hyperledger.besu.ethereum.eth.sync.tasks.RetryingGetHeaderFromPeerByHashTask; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.metrics.SyncDurationMetrics; @@ -47,6 +48,7 @@ public class FastSyncActions { protected final SynchronizerConfiguration syncConfig; protected final WorldStateStorageCoordinator worldStateStorageCoordinator; protected final ProtocolSchedule protocolSchedule; + protected final Supplier currentProtocolSpecSupplier; protected final ProtocolContext protocolContext; protected final EthContext ethContext; protected final PeerTaskExecutor peerTaskExecutor; @@ -60,6 +62,7 @@ public class FastSyncActions { final SynchronizerConfiguration syncConfig, final WorldStateStorageCoordinator worldStateStorageCoordinator, final ProtocolSchedule protocolSchedule, + final Supplier currentProtocolSpecSupplier, final ProtocolContext protocolContext, final EthContext ethContext, final PeerTaskExecutor peerTaskExecutor, @@ -69,6 +72,7 @@ public class FastSyncActions { this.syncConfig = syncConfig; this.worldStateStorageCoordinator = worldStateStorageCoordinator; this.protocolSchedule = protocolSchedule; + this.currentProtocolSpecSupplier = currentProtocolSpecSupplier; this.protocolContext = protocolContext; this.ethContext = ethContext; this.peerTaskExecutor = peerTaskExecutor; @@ -166,6 +170,7 @@ public class FastSyncActions { syncConfig, worldStateStorageCoordinator, protocolSchedule, + currentProtocolSpecSupplier, protocolContext, ethContext, peerTaskExecutor, diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloader.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloader.java index 1bf55a3811..206284a494 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloader.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncChainDownloader.java @@ -22,10 +22,13 @@ import org.hyperledger.besu.ethereum.eth.sync.PipelineChainDownloader; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.metrics.SyncDurationMetrics; import org.hyperledger.besu.plugin.services.MetricsSystem; +import java.util.function.Supplier; + public class FastSyncChainDownloader { protected FastSyncChainDownloader() {} @@ -34,6 +37,7 @@ public class FastSyncChainDownloader { final SynchronizerConfiguration config, final WorldStateStorageCoordinator worldStateStorageCoordinator, final ProtocolSchedule protocolSchedule, + final Supplier currentProtocolSpecSupplier, final ProtocolContext protocolContext, final EthContext ethContext, final PeerTaskExecutor peerTaskExecutor, @@ -57,6 +61,7 @@ public class FastSyncChainDownloader { new FastSyncDownloadPipelineFactory( config, protocolSchedule, + currentProtocolSpecSupplier, protocolContext, ethContext, peerTaskExecutor, diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java index d7c5769bdb..b55b372067 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastSyncDownloadPipelineFactory.java @@ -40,6 +40,7 @@ import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; import org.hyperledger.besu.ethereum.eth.sync.state.SyncTarget; import org.hyperledger.besu.ethereum.mainnet.BodyValidationMode; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.metrics.BesuMetricCategory; import org.hyperledger.besu.plugin.services.MetricsSystem; import org.hyperledger.besu.plugin.services.metrics.Counter; @@ -48,6 +49,7 @@ import org.hyperledger.besu.services.pipeline.Pipeline; import org.hyperledger.besu.services.pipeline.PipelineBuilder; import java.util.concurrent.CompletionStage; +import java.util.function.Supplier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,6 +59,7 @@ public class FastSyncDownloadPipelineFactory implements DownloadPipelineFactory protected final SynchronizerConfiguration syncConfig; protected final ProtocolSchedule protocolSchedule; + protected final Supplier currentProtocolSpecSupplier; protected final ProtocolContext protocolContext; protected final EthContext ethContext; protected final PeerTaskExecutor peerTaskExecutor; @@ -69,6 +72,7 @@ public class FastSyncDownloadPipelineFactory implements DownloadPipelineFactory public FastSyncDownloadPipelineFactory( final SynchronizerConfiguration syncConfig, final ProtocolSchedule protocolSchedule, + final Supplier currentProtocolSpecSupplier, final ProtocolContext protocolContext, final EthContext ethContext, final PeerTaskExecutor peerTaskExecutor, @@ -76,6 +80,7 @@ public class FastSyncDownloadPipelineFactory implements DownloadPipelineFactory final MetricsSystem metricsSystem) { this.syncConfig = syncConfig; this.protocolSchedule = protocolSchedule; + this.currentProtocolSpecSupplier = currentProtocolSpecSupplier; this.protocolContext = protocolContext; this.ethContext = ethContext; this.peerTaskExecutor = peerTaskExecutor; @@ -149,7 +154,8 @@ public class FastSyncDownloadPipelineFactory implements DownloadPipelineFactory final DownloadBodiesStep downloadBodiesStep = new DownloadBodiesStep(protocolSchedule, ethContext, metricsSystem); final DownloadReceiptsStep downloadReceiptsStep = - new DownloadReceiptsStep(ethContext, peerTaskExecutor, syncConfig, metricsSystem); + new DownloadReceiptsStep( + currentProtocolSpecSupplier, ethContext, peerTaskExecutor, syncConfig, metricsSystem); final ImportBlocksStep importBlockStep = new ImportBlocksStep( protocolSchedule, diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastDownloaderFactory.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastDownloaderFactory.java index 1d775cc80f..0b6fad7bb6 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastDownloaderFactory.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/worldstate/FastDownloaderFactory.java @@ -28,6 +28,7 @@ import org.hyperledger.besu.ethereum.eth.sync.fastsync.FastSyncStateStorage; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; import org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldStateDownloader; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; import org.hyperledger.besu.metrics.BesuMetricCategory; @@ -41,6 +42,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.time.Clock; import java.util.Optional; +import java.util.function.Supplier; import java.util.stream.Stream; import org.slf4j.Logger; @@ -57,6 +59,7 @@ public class FastDownloaderFactory { final SynchronizerConfiguration syncConfig, final Path dataDirectory, final ProtocolSchedule protocolSchedule, + final Supplier currentProtocolSpecSupplier, final ProtocolContext protocolContext, final MetricsSystem metricsSystem, final EthContext ethContext, @@ -126,6 +129,7 @@ public class FastDownloaderFactory { syncConfig, worldStateStorageCoordinator, protocolSchedule, + currentProtocolSpecSupplier, protocolContext, ethContext, peerTaskExecutor, diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapDownloaderFactory.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapDownloaderFactory.java index 6c5ce0b04e..423bb6b879 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapDownloaderFactory.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/snapsync/SnapDownloaderFactory.java @@ -31,6 +31,7 @@ import org.hyperledger.besu.ethereum.eth.sync.snapsync.request.SnapDataRequest; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; import org.hyperledger.besu.ethereum.eth.sync.worldstate.WorldStateDownloader; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions; import org.hyperledger.besu.ethereum.trie.CompactEncoding; import org.hyperledger.besu.ethereum.worldstate.WorldStateStorageCoordinator; @@ -41,6 +42,7 @@ import org.hyperledger.besu.services.tasks.InMemoryTasksPriorityQueues; import java.nio.file.Path; import java.time.Clock; import java.util.Optional; +import java.util.function.Supplier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,6 +57,7 @@ public class SnapDownloaderFactory extends FastDownloaderFactory { final SynchronizerConfiguration syncConfig, final Path dataDirectory, final ProtocolSchedule protocolSchedule, + final Supplier currentProtocolSpecSupplier, final ProtocolContext protocolContext, final MetricsSystem metricsSystem, final EthContext ethContext, @@ -121,6 +124,7 @@ public class SnapDownloaderFactory extends FastDownloaderFactory { syncConfig, worldStateStorageCoordinator, protocolSchedule, + currentProtocolSpecSupplier, protocolContext, ethContext, peerTaskExecutor, diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTaskTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTaskTest.java index 4529d9d396..0e3e7365f4 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTaskTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/peertask/task/GetReceiptsFromPeerTaskTest.java @@ -25,6 +25,7 @@ import org.hyperledger.besu.ethereum.eth.messages.EthPV63; import org.hyperledger.besu.ethereum.eth.messages.GetReceiptsMessage; import org.hyperledger.besu.ethereum.eth.messages.ReceiptsMessage; import org.hyperledger.besu.ethereum.mainnet.BodyValidator; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; import java.util.ArrayList; @@ -42,7 +43,8 @@ public class GetReceiptsFromPeerTaskTest { @Test public void testGetSubProtocol() { - GetReceiptsFromPeerTask task = new GetReceiptsFromPeerTask(Collections.emptyList(), null); + GetReceiptsFromPeerTask task = + new GetReceiptsFromPeerTask(Collections.emptyList(), null, () -> null); Assertions.assertEquals(EthProtocol.get(), task.getSubProtocol()); } @@ -50,7 +52,7 @@ public class GetReceiptsFromPeerTaskTest { public void testGetRequestMessage() { GetReceiptsFromPeerTask task = new GetReceiptsFromPeerTask( - List.of(mockBlockHeader(1), mockBlockHeader(2), mockBlockHeader(3)), null); + List.of(mockBlockHeader(1), mockBlockHeader(2), mockBlockHeader(3)), null, () -> null); MessageData messageData = task.getRequestMessage(); GetReceiptsMessage getReceiptsMessage = GetReceiptsMessage.readFrom(messageData); @@ -72,7 +74,8 @@ public class GetReceiptsFromPeerTaskTest { @Test public void testParseResponseWithNullResponseMessage() { - GetReceiptsFromPeerTask task = new GetReceiptsFromPeerTask(Collections.emptyList(), null); + GetReceiptsFromPeerTask task = + new GetReceiptsFromPeerTask(Collections.emptyList(), null, () -> null); Assertions.assertThrows(InvalidPeerTaskResponseException.class, () -> task.parseResponse(null)); } @@ -80,7 +83,7 @@ public class GetReceiptsFromPeerTaskTest { public void testParseResponseForInvalidResponse() { GetReceiptsFromPeerTask task = new GetReceiptsFromPeerTask( - List.of(mockBlockHeader(1), mockBlockHeader(2), mockBlockHeader(3)), null); + List.of(mockBlockHeader(1), mockBlockHeader(2), mockBlockHeader(3)), null, () -> null); ReceiptsMessage receiptsMessage = ReceiptsMessage.create( List.of( @@ -103,7 +106,7 @@ public class GetReceiptsFromPeerTaskTest { GetReceiptsFromPeerTask task = new GetReceiptsFromPeerTask( - List.of(blockHeader1, blockHeader2, blockHeader3), bodyValidator); + List.of(blockHeader1, blockHeader2, blockHeader3), bodyValidator, () -> null); TransactionReceipt receiptForBlock1 = new TransactionReceipt(1, 123, Collections.emptyList(), Optional.empty()); @@ -137,8 +140,12 @@ public class GetReceiptsFromPeerTaskTest { BlockHeader blockHeader2 = mockBlockHeader(2); BlockHeader blockHeader3 = mockBlockHeader(3); + ProtocolSpec protocolSpec = Mockito.mock(ProtocolSpec.class); + Mockito.when(protocolSpec.isPoS()).thenReturn(false); + GetReceiptsFromPeerTask task = - new GetReceiptsFromPeerTask(List.of(blockHeader1, blockHeader2, blockHeader3), null); + new GetReceiptsFromPeerTask( + List.of(blockHeader1, blockHeader2, blockHeader3), null, () -> protocolSpec); EthPeer failForIncorrectProtocol = mockPeer("incorrectProtocol", 5); EthPeer failForShortChainHeight = mockPeer("incorrectProtocol", 1); 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 c2a9930667..8458a5664f 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 @@ -157,7 +157,7 @@ public class CheckPointSyncChainDownloaderTest { } }); - when(peerTaskExecutor.executeAsync(any(GetReceiptsFromPeerTask.class))) + when(peerTaskExecutor.execute(any(GetReceiptsFromPeerTask.class))) .thenAnswer( new Answer< CompletableFuture< @@ -207,6 +207,7 @@ public class CheckPointSyncChainDownloaderTest { syncConfig, worldStateStorageCoordinator, protocolSchedule, + () -> null, protocolContext, ethContext, peerTaskExecutor, 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 554e09c3e9..6261d397dd 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 @@ -87,6 +87,7 @@ public class DownloadReceiptsStepTest { public void shouldDownloadReceiptsForBlocks() { DownloadReceiptsStep downloadReceiptsStep = new DownloadReceiptsStep( + () -> null, ethProtocolManager.ethContext(), peerTaskExecutor, SynchronizerConfiguration.builder().isPeerTaskSystemEnabled(false).build(), @@ -112,6 +113,7 @@ public class DownloadReceiptsStepTest { throws ExecutionException, InterruptedException { DownloadReceiptsStep downloadReceiptsStep = new DownloadReceiptsStep( + () -> null, ethProtocolManager.ethContext(), peerTaskExecutor, SynchronizerConfiguration.builder().isPeerTaskSystemEnabled(true).build(), diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastDownloaderFactoryTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastDownloaderFactoryTest.java index bc493ebd03..924780fe57 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastDownloaderFactoryTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/FastDownloaderFactoryTest.java @@ -113,6 +113,7 @@ public class FastDownloaderFactoryTest { syncConfig, dataDirectory, protocolSchedule, + () -> null, protocolContext, metricsSystem, ethContext, @@ -139,6 +140,7 @@ public class FastDownloaderFactoryTest { syncConfig, dataDirectory, protocolSchedule, + () -> null, protocolContext, metricsSystem, ethContext, @@ -168,6 +170,7 @@ public class FastDownloaderFactoryTest { syncConfig, dataDirectory, protocolSchedule, + () -> null, protocolContext, metricsSystem, ethContext, @@ -204,6 +207,7 @@ public class FastDownloaderFactoryTest { syncConfig, dataDirectory, protocolSchedule, + () -> null, protocolContext, metricsSystem, ethContext, @@ -242,6 +246,7 @@ public class FastDownloaderFactoryTest { syncConfig, dataDirectory, protocolSchedule, + () -> null, protocolContext, metricsSystem, ethContext, 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 7e1ec3c83a..0ffecd6842 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 @@ -585,9 +585,10 @@ public class FastSyncActionsTest { syncConfig, worldStateStorageCoordinator, protocolSchedule, + () -> null, protocolContext, ethContext, - new PeerTaskExecutor(null, null, null, new NoOpMetricsSystem()), + new PeerTaskExecutor(null, null, new NoOpMetricsSystem()), new SyncState(blockchain, ethContext.getEthPeers(), true, Optional.empty()), pivotBlockSelector, new NoOpMetricsSystem()); 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 da82034eaa..f0c433ebc3 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 @@ -109,9 +109,10 @@ public class FastSyncChainDownloaderTest { syncConfig, worldStateStorageCoordinator, protocolSchedule, + () -> null, protocolContext, ethContext, - new PeerTaskExecutor(null, null, null, new NoOpMetricsSystem()), + new PeerTaskExecutor(null, null, new NoOpMetricsSystem()), syncState, new NoOpMetricsSystem(), new FastSyncState(otherBlockchain.getBlockHeader(pivotBlockNumber).get()),