From b677f6c9928fb06a7887c892af0a1c1f07164f49 Mon Sep 17 00:00:00 2001 From: Stefan Date: Fri, 10 Feb 2023 16:51:54 +1000 Subject: [PATCH 1/3] reintroduce checking of block height for certain tasks when we are not PoS (Revert PR#3911) Signed-off-by: Stefan --- .../MergeBesuControllerBuilder.java | 1 + .../TransitionBesuControllerBuilder.java | 13 +++--- .../consensus/merge/PostMergeContext.java | 5 ++- .../merge/TransitionProtocolSchedule.java | 2 +- .../mainnet/MutableProtocolSchedule.java | 2 +- .../ethereum/mainnet/ProtocolSchedule.java | 21 +++++++--- .../manager/task/AbstractPeerRequestTask.java | 4 -- .../manager/task/GetBlockFromPeerTask.java | 5 ++- .../manager/task/GetBodiesFromPeerTask.java | 5 ++- .../task/GetHeadersFromPeerByHashTask.java | 40 ++++++++++++++++--- .../task/GetHeadersFromPeerByNumberTask.java | 5 ++- ...gGetHeadersEndingAtFromPeerByHashTask.java | 20 +++++++++- .../ethereum/eth/sync/ChainHeadTracker.java | 1 + .../eth/sync/DownloadHeadersStep.java | 1 + .../sync/backwardsync/BackwardSyncStep.java | 7 ++++ .../eth/sync/fastsync/FastSyncActions.java | 6 ++- .../fastsync/PivotSelectorFromSafeBlock.java | 2 +- .../eth/sync/range/RangeHeadersFetcher.java | 1 + .../tasks/DownloadHeaderSequenceTask.java | 7 +++- .../RetryingGetHeaderFromPeerByHashTask.java | 11 ++++- .../GetHeadersFromPeerByHashTaskTest.java | 29 ++++++++++++-- .../backwardsync/BackwardSyncStepTest.java | 39 ++++++++++++++++++ .../NoRewardProtocolScheduleWrapper.java | 2 +- 23 files changed, 192 insertions(+), 37 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java index cf68059763c..25fb7acaabc 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java @@ -220,6 +220,7 @@ protected MergeContext createConsensusContext( .getTotalDifficultyByHash(blockAddedEvent.getBlock().getHeader().getHash()) .ifPresent(mergeContext::setIsPostMerge)); + protocolSchedule.setIsPostMerge(mergeContext::isPostMerge); return mergeContext; } 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 6eba8e94302..f2e339c2ac1 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java @@ -202,11 +202,14 @@ protected ConsensusContext createConsensusContext( final Blockchain blockchain, final WorldStateArchive worldStateArchive, final ProtocolSchedule protocolSchedule) { - return new TransitionContext( - preMergeBesuControllerBuilder.createConsensusContext( - blockchain, worldStateArchive, protocolSchedule), - mergeBesuControllerBuilder.createConsensusContext( - blockchain, worldStateArchive, protocolSchedule)); + final TransitionContext transitionContext = + new TransitionContext( + preMergeBesuControllerBuilder.createConsensusContext( + blockchain, worldStateArchive, protocolSchedule), + mergeBesuControllerBuilder.createConsensusContext( + blockchain, worldStateArchive, protocolSchedule)); + protocolSchedule.setIsPostMerge(transitionContext::isPostMerge); + return transitionContext; } @Override diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/PostMergeContext.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/PostMergeContext.java index 12ac368c310..03e2ed20d37 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/PostMergeContext.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/PostMergeContext.java @@ -144,7 +144,10 @@ public void setIsPostMerge(final Difficulty totalDifficulty) { @Override public boolean isPostMerge() { - return isPostMerge.get().orElse(Boolean.FALSE); + return isPostMerge + .get() + .orElse(Boolean.FALSE); // TODO: is this correct? PostMergeContext -> should this always be + // true???? } @Override diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java index d1d70060e4d..580ba004c27 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; /** The Transition protocol schedule. */ -public class TransitionProtocolSchedule implements ProtocolSchedule { +public class TransitionProtocolSchedule extends ProtocolSchedule { private final TransitionUtils transitionUtils; private static final Logger LOG = LoggerFactory.getLogger(TransitionProtocolSchedule.class); private final TimestampSchedule timestampSchedule; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MutableProtocolSchedule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MutableProtocolSchedule.java index 8145af43ac2..88ac019f019 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MutableProtocolSchedule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MutableProtocolSchedule.java @@ -28,7 +28,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -public class MutableProtocolSchedule implements ProtocolSchedule { +public class MutableProtocolSchedule extends ProtocolSchedule { private final NavigableSet protocolSpecs = new TreeSet<>( diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSchedule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSchedule.java index 7cef6b7696f..53a95e8982b 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSchedule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSchedule.java @@ -16,17 +16,28 @@ import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; +import java.util.function.Supplier; import java.util.stream.Stream; -public interface ProtocolSchedule - extends HeaderBasedProtocolSchedule, PrivacySupportingProtocolSchedule { +public abstract class ProtocolSchedule + implements HeaderBasedProtocolSchedule, PrivacySupportingProtocolSchedule { - ProtocolSpec getByBlockNumber(long number); + private Supplier isPostMerge = () -> false; - Stream streamMilestoneBlocks(); + public abstract ProtocolSpec getByBlockNumber(long number); + + public abstract Stream streamMilestoneBlocks(); + + public void setIsPostMerge(final Supplier isPostMerge) { + this.isPostMerge = isPostMerge; + } + + public boolean isPostMerge() { + return isPostMerge.get(); + } @Override - default ProtocolSpec getByBlockHeader(final ProcessableBlockHeader blockHeader) { + public ProtocolSpec getByBlockHeader(final ProcessableBlockHeader blockHeader) { return getByBlockNumber(blockHeader.getNumber()); } } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/AbstractPeerRequestTask.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/AbstractPeerRequestTask.java index 6dd87ae3b7a..b66a8a3b8de 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/AbstractPeerRequestTask.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/AbstractPeerRequestTask.java @@ -85,10 +85,6 @@ protected final void executeTask() { }); } - public PendingPeerRequest sendRequestToPeer(final PeerRequest request) { - return sendRequestToPeer(request, 0L); - } - public PendingPeerRequest sendRequestToPeer( final PeerRequest request, final long minimumBlockNumber) { return ethContext.getEthPeers().executePeerRequest(request, minimumBlockNumber, assignedPeer); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetBlockFromPeerTask.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetBlockFromPeerTask.java index 6dc20710667..80ea12c277b 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetBlockFromPeerTask.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetBlockFromPeerTask.java @@ -96,6 +96,7 @@ protected void executeTask() { } private CompletableFuture>> downloadHeader() { + long blockNumberToUse = protocolSchedule.isPostMerge() ? 0 : this.blockNumber; return executeSubTask( () -> { final AbstractGetHeadersFromPeerTask task; @@ -103,11 +104,11 @@ private CompletableFuture>> downloadHeader() { hash.map( value -> GetHeadersFromPeerByHashTask.forSingleHash( - protocolSchedule, ethContext, value, metricsSystem)) + protocolSchedule, ethContext, value, blockNumberToUse, metricsSystem)) .orElseGet( () -> GetHeadersFromPeerByNumberTask.forSingleNumber( - protocolSchedule, ethContext, blockNumber, metricsSystem)); + protocolSchedule, ethContext, blockNumberToUse, metricsSystem)); assignedPeer.ifPresent(task::assignPeer); return task.run(); }); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetBodiesFromPeerTask.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetBodiesFromPeerTask.java index 82e7902b579..d1522360f67 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetBodiesFromPeerTask.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetBodiesFromPeerTask.java @@ -83,12 +83,15 @@ public static GetBodiesFromPeerTask forHeaders( protected PendingPeerRequest sendRequest() { final List blockHashes = headers.stream().map(BlockHeader::getHash).collect(Collectors.toList()); + final long minimumRequiredBlockNumber = + protocolSchedule.isPostMerge() ? 0 : headers.get(headers.size() - 1).getNumber(); return sendRequestToPeer( peer -> { LOG.debug("Requesting {} bodies from peer {}.", blockHashes.size(), peer); return peer.getBodies(blockHashes); - }); + }, + minimumRequiredBlockNumber); } @Override diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetHeadersFromPeerByHashTask.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetHeadersFromPeerByHashTask.java index 1f8d76865d2..dfade97e7e0 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetHeadersFromPeerByHashTask.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetHeadersFromPeerByHashTask.java @@ -32,17 +32,21 @@ public class GetHeadersFromPeerByHashTask extends AbstractGetHeadersFromPeerTask private static final Logger LOG = LoggerFactory.getLogger(GetHeadersFromPeerByHashTask.class); private final Hash referenceHash; + private final long minimumRequiredBlockNumber; @VisibleForTesting GetHeadersFromPeerByHashTask( final ProtocolSchedule protocolSchedule, final EthContext ethContext, final Hash referenceHash, + final long minimumRequiredBlockNumber, final int count, final int skip, final boolean reverse, final MetricsSystem metricsSystem) { super(protocolSchedule, ethContext, count, skip, reverse, metricsSystem); + this.minimumRequiredBlockNumber = + protocolSchedule.isPostMerge() ? 0 : minimumRequiredBlockNumber; checkNotNull(referenceHash); this.referenceHash = referenceHash; } @@ -51,40 +55,65 @@ public static AbstractGetHeadersFromPeerTask startingAtHash( final ProtocolSchedule protocolSchedule, final EthContext ethContext, final Hash firstHash, + final long firstBlockNumber, final int segmentLength, final MetricsSystem metricsSystem) { return new GetHeadersFromPeerByHashTask( - protocolSchedule, ethContext, firstHash, segmentLength, 0, false, metricsSystem); + protocolSchedule, + ethContext, + firstHash, + firstBlockNumber, + segmentLength, + 0, + false, + metricsSystem); } public static AbstractGetHeadersFromPeerTask startingAtHash( final ProtocolSchedule protocolSchedule, final EthContext ethContext, final Hash firstHash, + final long firstBlockNumber, final int segmentLength, final int skip, final MetricsSystem metricsSystem) { return new GetHeadersFromPeerByHashTask( - protocolSchedule, ethContext, firstHash, segmentLength, skip, false, metricsSystem); + protocolSchedule, + ethContext, + firstHash, + firstBlockNumber, + segmentLength, + skip, + false, + metricsSystem); } public static AbstractGetHeadersFromPeerTask endingAtHash( final ProtocolSchedule protocolSchedule, final EthContext ethContext, final Hash lastHash, + final long lastBlockNumber, final int segmentLength, final MetricsSystem metricsSystem) { return new GetHeadersFromPeerByHashTask( - protocolSchedule, ethContext, lastHash, segmentLength, 0, true, metricsSystem); + protocolSchedule, + ethContext, + lastHash, + lastBlockNumber, + segmentLength, + 0, + true, + metricsSystem); } public static AbstractGetHeadersFromPeerTask forSingleHash( final ProtocolSchedule protocolSchedule, final EthContext ethContext, final Hash hash, + final long minimumRequiredBlockNumber, final MetricsSystem metricsSystem) { return new GetHeadersFromPeerByHashTask( - protocolSchedule, ethContext, hash, 1, 0, false, metricsSystem); + protocolSchedule, ethContext, hash, minimumRequiredBlockNumber, 1, 0, false, metricsSystem); } @Override @@ -97,7 +126,8 @@ protected PendingPeerRequest sendRequest() { referenceHash.slice(0, 6), peer); return peer.getHeadersByHash(referenceHash, count, skip, reverse); - }); + }, + minimumRequiredBlockNumber); } @Override diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetHeadersFromPeerByNumberTask.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetHeadersFromPeerByNumberTask.java index 1a1cd8db23b..1c0108596f6 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetHeadersFromPeerByNumberTask.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetHeadersFromPeerByNumberTask.java @@ -40,7 +40,7 @@ public class GetHeadersFromPeerByNumberTask extends AbstractGetHeadersFromPeerTa final boolean reverse, final MetricsSystem metricsSystem) { super(protocolSchedule, ethContext, count, skip, reverse, metricsSystem); - this.blockNumber = blockNumber; + this.blockNumber = protocolSchedule.isPostMerge() ? 0 : blockNumber; } public static AbstractGetHeadersFromPeerTask startingAtNumber( @@ -80,7 +80,8 @@ protected PendingPeerRequest sendRequest() { LOG.debug( "Requesting {} headers (blockNumber {}) from peer {}.", count, blockNumber, peer); return peer.getHeadersByNumber(blockNumber, count, skip, reverse); - }); + }, + blockNumber); } @Override diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/RetryingGetHeadersEndingAtFromPeerByHashTask.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/RetryingGetHeadersEndingAtFromPeerByHashTask.java index 2d1119c4aca..0e536a79fbe 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/RetryingGetHeadersEndingAtFromPeerByHashTask.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/RetryingGetHeadersEndingAtFromPeerByHashTask.java @@ -39,6 +39,7 @@ public class RetryingGetHeadersEndingAtFromPeerByHashTask private final Hash referenceHash; private final ProtocolSchedule protocolSchedule; + private final long minimumRequiredBlockNumber; private final int count; @VisibleForTesting @@ -46,11 +47,14 @@ public class RetryingGetHeadersEndingAtFromPeerByHashTask final ProtocolSchedule protocolSchedule, final EthContext ethContext, final Hash referenceHash, + final long minimumRequiredBlockNumber, final int count, final MetricsSystem metricsSystem, final int maxRetries) { super(ethContext, metricsSystem, List::isEmpty, maxRetries); this.protocolSchedule = protocolSchedule; + this.minimumRequiredBlockNumber = + protocolSchedule.isPostMerge() ? 0 : minimumRequiredBlockNumber; this.count = count; checkNotNull(referenceHash); this.referenceHash = referenceHash; @@ -60,11 +64,18 @@ public static RetryingGetHeadersEndingAtFromPeerByHashTask endingAtHash( final ProtocolSchedule protocolSchedule, final EthContext ethContext, final Hash referenceHash, + final long minimumRequiredBlockNumber, final int count, final MetricsSystem metricsSystem, final int maxRetries) { return new RetryingGetHeadersEndingAtFromPeerByHashTask( - protocolSchedule, ethContext, referenceHash, count, metricsSystem, maxRetries); + protocolSchedule, + ethContext, + referenceHash, + minimumRequiredBlockNumber, + count, + metricsSystem, + maxRetries); } @Override @@ -72,7 +83,12 @@ protected CompletableFuture> executeTaskOnCurrentPeer( final EthPeer currentPeer) { final AbstractGetHeadersFromPeerTask task = GetHeadersFromPeerByHashTask.endingAtHash( - protocolSchedule, getEthContext(), referenceHash, count, getMetricsSystem()); + protocolSchedule, + getEthContext(), + referenceHash, + minimumRequiredBlockNumber, + count, + getMetricsSystem()); task.assignPeer(currentPeer); return executeSubTask(task::run) .thenApply( diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTracker.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTracker.java index 547a0abc555..d3d893482a8 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTracker.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/ChainHeadTracker.java @@ -73,6 +73,7 @@ public void onPeerConnected(final EthPeer peer) { protocolSchedule, ethContext, Hash.wrap(peer.chainState().getBestBlock().getHash()), + 0, metricsSystem) .assignPeer(peer) .run() diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DownloadHeadersStep.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DownloadHeadersStep.java index 8ec836bde0d..6e404305823 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DownloadHeadersStep.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DownloadHeadersStep.java @@ -96,6 +96,7 @@ private CompletableFuture> downloadHeaders(final SyncTargetRan protocolSchedule, ethContext, range.getStart().getHash(), + range.getStart().getNumber(), headerRequestSize, metricsSystem) .assignPeer(range.getSyncTarget()) diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncStep.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncStep.java index dd05a02dd0f..04f8aa910b6 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncStep.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncStep.java @@ -67,6 +67,12 @@ protected CompletableFuture> requestHeaders(final Hash hash) { final int batchSize = context.getBatchSize(); LOG.debug("Requesting headers for hash {}, with batch size {}", hash, batchSize); + final Optional maybeFinalizedHeader = + context + .getProtocolContext() + .getBlockchain() + .getFinalized() + .flatMap(context.getProtocolContext().getBlockchain()::getBlockHeader); final RetryingGetHeadersEndingAtFromPeerByHashTask retryingGetHeadersEndingAtFromPeerByHashTask = @@ -74,6 +80,7 @@ protected CompletableFuture> requestHeaders(final Hash hash) { context.getProtocolSchedule(), context.getEthContext(), hash, + maybeFinalizedHeader.map(BlockHeader::getNumber).orElse(0L), batchSize, context.getMetricsSystem(), context.getEthContext().getEthPeers().peerCount()); 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 f3bc4860f5f..6a799e0fa00 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 @@ -171,7 +171,11 @@ public ChainDownloader createChainDownloader(final FastSyncState currentState) { private CompletableFuture downloadPivotBlockHeader(final Hash hash) { LOG.debug("Downloading pivot block header by hash {}", hash); return RetryingGetHeaderFromPeerByHashTask.byHash( - protocolSchedule, ethContext, hash, metricsSystem) + protocolSchedule, + ethContext, + hash, + pivotBlockSelector.getMinRequiredBlockNumber(), + metricsSystem) .getHeader() .whenComplete( (blockHeader, throwable) -> { diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotSelectorFromSafeBlock.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotSelectorFromSafeBlock.java index e107437a9d2..5389ca22288 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotSelectorFromSafeBlock.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotSelectorFromSafeBlock.java @@ -137,7 +137,7 @@ public long getBestChainHeight() { private CompletableFuture downloadBlockHeader(final Hash hash) { return RetryingGetHeaderFromPeerByHashTask.byHash( - protocolSchedule, ethContext, hash, metricsSystem) + protocolSchedule, ethContext, hash, 0, metricsSystem) .getHeader() .whenComplete( (blockHeader, throwable) -> { diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/range/RangeHeadersFetcher.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/range/RangeHeadersFetcher.java index a2723a10d46..68e7d193b99 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/range/RangeHeadersFetcher.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/range/RangeHeadersFetcher.java @@ -106,6 +106,7 @@ private CompletableFuture> requestHeaders( protocolSchedule, ethContext, referenceHeader.getHash(), + referenceHeader.getNumber(), // + 1 because lastHeader will be returned as well. headerCount + 1, skip, diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DownloadHeaderSequenceTask.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DownloadHeaderSequenceTask.java index 9b12fa69e61..23e26ff8922 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DownloadHeaderSequenceTask.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DownloadHeaderSequenceTask.java @@ -166,7 +166,12 @@ private CompletableFuture>> downloadHeaders( // Ask for count + 1 because we'll retrieve the previous header as well final AbstractGetHeadersFromPeerTask headersTask = GetHeadersFromPeerByHashTask.endingAtHash( - protocolSchedule, ethContext, referenceHash, count + 1, metricsSystem); + protocolSchedule, + ethContext, + referenceHash, + referenceHeaderForNextRequest.getNumber(), + count + 1, + metricsSystem); assignedPeer.ifPresent(headersTask::assignPeer); return headersTask.run(); }); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/tasks/RetryingGetHeaderFromPeerByHashTask.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/tasks/RetryingGetHeaderFromPeerByHashTask.java index 18f9d0951d3..c36599e6354 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/tasks/RetryingGetHeaderFromPeerByHashTask.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/tasks/RetryingGetHeaderFromPeerByHashTask.java @@ -40,16 +40,19 @@ public class RetryingGetHeaderFromPeerByHashTask LoggerFactory.getLogger(RetryingGetHeaderFromPeerByHashTask.class); private final Hash referenceHash; private final ProtocolSchedule protocolSchedule; + private final long minimumRequiredBlockNumber; @VisibleForTesting RetryingGetHeaderFromPeerByHashTask( final ProtocolSchedule protocolSchedule, final EthContext ethContext, final Hash referenceHash, + final long minimumRequiredBlockNumber, final MetricsSystem metricsSystem, final int maxRetries) { super(ethContext, metricsSystem, List::isEmpty, maxRetries); this.protocolSchedule = protocolSchedule; + this.minimumRequiredBlockNumber = minimumRequiredBlockNumber; checkNotNull(referenceHash); this.referenceHash = referenceHash; } @@ -58,11 +61,13 @@ public static RetryingGetHeaderFromPeerByHashTask byHash( final ProtocolSchedule protocolSchedule, final EthContext ethContext, final Hash referenceHash, + final long minimumRequiredBlockNumber, final MetricsSystem metricsSystem) { return new RetryingGetHeaderFromPeerByHashTask( protocolSchedule, ethContext, referenceHash, + minimumRequiredBlockNumber, metricsSystem, ethContext.getEthPeers().peerCount()); } @@ -71,7 +76,11 @@ public static RetryingGetHeaderFromPeerByHashTask byHash( protected CompletableFuture> executeTaskOnCurrentPeer(final EthPeer peer) { final AbstractGetHeadersFromPeerTask task = GetHeadersFromPeerByHashTask.forSingleHash( - protocolSchedule, getEthContext(), referenceHash, getMetricsSystem()); + protocolSchedule, + getEthContext(), + referenceHash, + minimumRequiredBlockNumber, + getMetricsSystem()); task.assignPeer(peer); return executeSubTask(task::run) .thenApply( diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/task/GetHeadersFromPeerByHashTaskTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/task/GetHeadersFromPeerByHashTaskTest.java index 5bea199ccad..6d6881c01ff 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/task/GetHeadersFromPeerByHashTaskTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/task/GetHeadersFromPeerByHashTaskTest.java @@ -69,7 +69,12 @@ protected EthTask>> createTask final List requestedData) { final BlockHeader firstHeader = requestedData.get(0); return GetHeadersFromPeerByHashTask.startingAtHash( - protocolSchedule, ethContext, firstHeader.getHash(), requestedData.size(), metricsSystem); + protocolSchedule, + ethContext, + firstHeader.getHash(), + firstHeader.getNumber(), + requestedData.size(), + metricsSystem); } @Test @@ -113,6 +118,7 @@ private void getHeadersFromHash(final int skip, final boolean reverse) { protocolSchedule, ethContext, blockchain.getBlockHashByNumber(startNumber).get(), + startNumber, count, skip, reverse, @@ -135,6 +141,8 @@ private void getHeadersFromHash(final int skip, final boolean reverse) { @Test public void checkThatSequentialHeadersFormingAChainWorks() { + final int startNumber = 1; + final BlockHeader block1 = new BlockHeaderTestFixture().number(1).parentHash(generateTestBlockHash(0)).buildHeader(); final BlockHeader block2 = @@ -145,7 +153,14 @@ public void checkThatSequentialHeadersFormingAChainWorks() { final AbstractGetHeadersFromPeerTask task = new GetHeadersFromPeerByHashTask( - protocolSchedule, ethContext, block1.getHash(), 2, 0, false, metricsSystem); + protocolSchedule, + ethContext, + block1.getHash(), + startNumber, + 2, + 0, + false, + metricsSystem); final Optional> optionalBlockHeaders = task.processResponse(false, BlockHeadersMessage.create(headers), peer); assertThat(optionalBlockHeaders).isNotNull(); @@ -158,6 +173,7 @@ public void checkThatSequentialHeadersFormingAChainWorks() { @Test public void checkThatSequentialHeadersNotFormingAChainFails() { + final int startNumber = 1; final BlockHeader block1 = new BlockHeaderTestFixture().number(1).parentHash(generateTestBlockHash(0)).buildHeader(); final BlockHeader block2 = @@ -168,7 +184,14 @@ public void checkThatSequentialHeadersNotFormingAChainFails() { final AbstractGetHeadersFromPeerTask task = new GetHeadersFromPeerByHashTask( - protocolSchedule, ethContext, block1.getHash(), 2, 0, false, metricsSystem); + protocolSchedule, + ethContext, + block1.getHash(), + startNumber, + 2, + 0, + false, + metricsSystem); final Optional> optionalBlockHeaders = task.processResponse(false, BlockHeadersMessage.create(headers), peer); assertThat(optionalBlockHeaders).isNotNull(); 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 17eb2e45a92..6e9b4d56c54 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 @@ -16,6 +16,7 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; +import static org.assertj.core.api.Fail.failBecauseExceptionWasNotThrown; import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; @@ -41,6 +42,9 @@ import java.util.List; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import javax.annotation.Nonnull; import org.junit.Before; @@ -192,6 +196,41 @@ public void shouldRequestHeaderBeforeCurrentHeight() throws Exception { assertThat(blockHeader).isEqualTo(lookingForBlock.getHeader()); } + @Test + public void shouldNotRequestHeaderBeforeLastFinalizedBlock() throws Exception { + final MutableBlockchain localBlockchain = context.getProtocolContext().getBlockchain(); + extendBlockchain(REMOTE_HEIGHT + 2, localBlockchain); + localBlockchain.setFinalized( + localBlockchain.getBlockHashByNumber(REMOTE_HEIGHT + 1).orElseThrow()); + + BackwardSyncStep step = new BackwardSyncStep(context, createBackwardChain(REMOTE_HEIGHT - 1)); + final Block lookingForBlock = getBlockByNumber(REMOTE_HEIGHT - 2); + + final RespondingEthPeer.Responder responder = + RespondingEthPeer.blockchainResponder(remoteBlockchain); + + final CompletableFuture> future = + step.requestHeaders(lookingForBlock.getHeader().getHash()); + + ScheduledExecutorService schedExecutor = Executors.newScheduledThreadPool(2); + schedExecutor.submit( + () -> peer.respondWhileOtherThreadsWork(responder, () -> !future.isDone())); + + schedExecutor.scheduleWithFixedDelay( + ethScheduler::expirePendingTimeouts, 0, 100, TimeUnit.MILLISECONDS); + + future + .handle( + (r, t) -> { + if (t == null || !(t.getCause() instanceof MaxRetriesReachedException)) { + failBecauseExceptionWasNotThrown(MaxRetriesReachedException.class); + } + return r; + }) + .thenRun(schedExecutor::shutdownNow) + .join(); + } + @Test public void shouldThrowWhenResponseIsEmptyWhenRequestingHeader() { BackwardSyncStep step = new BackwardSyncStep(context, createBackwardChain(REMOTE_HEIGHT - 1)); diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/NoRewardProtocolScheduleWrapper.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/NoRewardProtocolScheduleWrapper.java index cee9cdf1293..3991006ac49 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/NoRewardProtocolScheduleWrapper.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/NoRewardProtocolScheduleWrapper.java @@ -30,7 +30,7 @@ import java.util.Optional; import java.util.stream.Stream; -public class NoRewardProtocolScheduleWrapper implements ProtocolSchedule { +public class NoRewardProtocolScheduleWrapper extends ProtocolSchedule { private final ProtocolSchedule delegate; From f1d9de6a4b66dc6c9851dc011758bc5d192a7e1a Mon Sep 17 00:00:00 2001 From: Stefan Date: Tue, 14 Feb 2023 11:15:00 +1000 Subject: [PATCH 2/3] make some changes after review by Fabio Signed-off-by: Stefan --- .../controller/BesuControllerBuilder.java | 4 ++ .../MergeBesuControllerBuilder.java | 1 - .../TransitionBesuControllerBuilder.java | 13 +++---- .../Istanbul99ProtocolManagerTest.java | 1 + .../consensus/merge/PostMergeContext.java | 5 +-- .../merge/TransitionProtocolSchedule.java | 2 +- .../methods/EthGetTransactionReceiptTest.java | 6 ++- .../mainnet/MainnetProtocolSpecs.java | 3 +- .../mainnet/MutableProtocolSchedule.java | 2 +- .../ethereum/mainnet/ProtocolSchedule.java | 21 +++------- .../besu/ethereum/mainnet/ProtocolSpec.java | 15 ++++++- .../ethereum/mainnet/ProtocolSpecBuilder.java | 9 ++++- .../besu/ethereum/eth/manager/EthPeers.java | 25 +++++++++++- .../manager/task/GetBlockFromPeerTask.java | 5 +-- .../manager/task/GetBodiesFromPeerTask.java | 3 +- .../task/GetHeadersFromPeerByHashTask.java | 3 +- .../task/GetHeadersFromPeerByNumberTask.java | 2 +- ...gGetHeadersEndingAtFromPeerByHashTask.java | 3 +- .../eth/manager/EthProtocolManagerTest.java | 26 +++++++++++++ .../manager/EthProtocolManagerTestUtil.java | 22 +++++++++-- .../ethtaskutils/AbstractMessageTaskTest.java | 1 + .../AbstractBlockPropagationManagerTest.java | 3 ++ .../eth/sync/RangeHeadersFetcherTest.java | 1 + .../backwardsync/BackwardSyncStepTest.java | 39 ------------------- .../CheckPointSyncChainDownloaderTest.java | 4 +- .../fastsync/DownloadReceiptsStepTest.java | 2 + .../sync/fastsync/FastSyncActionsTest.java | 2 + .../fastsync/FastSyncChainDownloaderTest.java | 4 +- .../fastsync/PivotBlockConfirmerTest.java | 1 + .../fastsync/PivotBlockRetrieverTest.java | 1 + .../FullSyncChainDownloaderForkTest.java | 1 + .../fullsync/FullSyncChainDownloaderTest.java | 1 + ...DownloaderTotalTerminalDifficultyTest.java | 1 + .../sync/fullsync/FullSyncDownloaderTest.java | 1 + .../fullsync/FullSyncTargetManagerTest.java | 1 + ...neCommonAncestorTaskParameterizedTest.java | 1 + .../DetermineCommonAncestorTaskTest.java | 1 + .../ethereum/eth/transactions/TestNode.java | 1 + .../TransactionPoolFactoryTest.java | 3 ++ .../NoRewardProtocolScheduleWrapper.java | 5 ++- .../ethereum/retesteth/RetestethContext.java | 4 ++ 41 files changed, 155 insertions(+), 94 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 6ac5ed7037e..db700e21260 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java @@ -75,6 +75,7 @@ import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolFactory; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.p2p.config.SubProtocolConfiguration; import org.hyperledger.besu.ethereum.storage.StorageProvider; import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier; @@ -548,9 +549,12 @@ public BesuController build() { } } final int maxMessageSize = ethereumWireProtocolConfiguration.getMaxMessageSize(); + final Supplier currentProtocolSpecSupplier = + () -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()); final EthPeers ethPeers = new EthPeers( getSupportedProtocol(), + currentProtocolSpecSupplier, clock, metricsSystem, maxPeers, diff --git a/besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java index 58db899378c..ad382d795fc 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java @@ -226,7 +226,6 @@ protected MergeContext createConsensusContext( .getTotalDifficultyByHash(blockAddedEvent.getBlock().getHeader().getHash()) .ifPresent(mergeContext::setIsPostMerge)); - protocolSchedule.setIsPostMerge(mergeContext::isPostMerge); return mergeContext; } 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 f2e339c2ac1..6eba8e94302 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java @@ -202,14 +202,11 @@ protected ConsensusContext createConsensusContext( final Blockchain blockchain, final WorldStateArchive worldStateArchive, final ProtocolSchedule protocolSchedule) { - final TransitionContext transitionContext = - new TransitionContext( - preMergeBesuControllerBuilder.createConsensusContext( - blockchain, worldStateArchive, protocolSchedule), - mergeBesuControllerBuilder.createConsensusContext( - blockchain, worldStateArchive, protocolSchedule)); - protocolSchedule.setIsPostMerge(transitionContext::isPostMerge); - return transitionContext; + return new TransitionContext( + preMergeBesuControllerBuilder.createConsensusContext( + blockchain, worldStateArchive, protocolSchedule), + mergeBesuControllerBuilder.createConsensusContext( + blockchain, worldStateArchive, protocolSchedule)); } @Override diff --git a/consensus/ibftlegacy/src/test/java/org/hyperledger/besu/consensus/ibftlegacy/protocol/Istanbul99ProtocolManagerTest.java b/consensus/ibftlegacy/src/test/java/org/hyperledger/besu/consensus/ibftlegacy/protocol/Istanbul99ProtocolManagerTest.java index c8d9e16bcf4..aba56818181 100644 --- a/consensus/ibftlegacy/src/test/java/org/hyperledger/besu/consensus/ibftlegacy/protocol/Istanbul99ProtocolManagerTest.java +++ b/consensus/ibftlegacy/src/test/java/org/hyperledger/besu/consensus/ibftlegacy/protocol/Istanbul99ProtocolManagerTest.java @@ -111,6 +111,7 @@ public void respondToEth65GetHeadersUsingIstanbul99() EthPeers peers = new EthPeers( Istanbul99Protocol.NAME, + () -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()), TestClock.fixed(), new NoOpMetricsSystem(), 25, diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/PostMergeContext.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/PostMergeContext.java index 44198c48af6..6ab2de612e9 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/PostMergeContext.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/PostMergeContext.java @@ -145,10 +145,7 @@ public void setIsPostMerge(final Difficulty totalDifficulty) { @Override public boolean isPostMerge() { - return isPostMerge - .get() - .orElse(Boolean.FALSE); // TODO: is this correct? PostMergeContext -> should this always be - // true???? + return isPostMerge.get().orElse(Boolean.FALSE); } @Override diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java index d4aa831ce6d..2859fc590e6 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/TransitionProtocolSchedule.java @@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory; /** The Transition protocol schedule. */ -public class TransitionProtocolSchedule extends ProtocolSchedule { +public class TransitionProtocolSchedule implements ProtocolSchedule { private final TransitionUtils transitionUtils; private static final Logger LOG = LoggerFactory.getLogger(TransitionProtocolSchedule.class); private final TimestampSchedule timestampSchedule; diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java index 55bde158abf..615bf3edefe 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java @@ -113,7 +113,8 @@ public class EthGetTransactionReceiptTest { null, Optional.of(PoWHasher.ETHASH_LIGHT), null, - Optional.empty()); + Optional.empty(), + true); private final ProtocolSpec statusTransactionTypeSpec = new ProtocolSpec( "status", @@ -140,7 +141,8 @@ public class EthGetTransactionReceiptTest { null, Optional.of(PoWHasher.ETHASH_LIGHT), null, - Optional.empty()); + Optional.empty(), + true); @SuppressWarnings("unchecked") private final ProtocolSchedule protocolSchedule = mock(ProtocolSchedule.class); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java index 874b73afb17..068713d5e2b 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java @@ -638,7 +638,8 @@ static ProtocolSpecBuilder parisDefinition( .difficultyCalculator(MainnetDifficultyCalculators.PROOF_OF_STAKE_DIFFICULTY) .blockHeaderValidatorBuilder(MainnetBlockHeaderValidator::mergeBlockHeaderValidator) .blockReward(Wei.ZERO) - .name("ParisFork"); + .name("ParisFork") + .isPoS(true); } static ProtocolSpecBuilder shanghaiDefinition( diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MutableProtocolSchedule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MutableProtocolSchedule.java index 88ac019f019..8145af43ac2 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MutableProtocolSchedule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MutableProtocolSchedule.java @@ -28,7 +28,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -public class MutableProtocolSchedule extends ProtocolSchedule { +public class MutableProtocolSchedule implements ProtocolSchedule { private final NavigableSet protocolSpecs = new TreeSet<>( diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSchedule.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSchedule.java index 53a95e8982b..7cef6b7696f 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSchedule.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSchedule.java @@ -16,28 +16,17 @@ import org.hyperledger.besu.ethereum.core.ProcessableBlockHeader; -import java.util.function.Supplier; import java.util.stream.Stream; -public abstract class ProtocolSchedule - implements HeaderBasedProtocolSchedule, PrivacySupportingProtocolSchedule { +public interface ProtocolSchedule + extends HeaderBasedProtocolSchedule, PrivacySupportingProtocolSchedule { - private Supplier isPostMerge = () -> false; + ProtocolSpec getByBlockNumber(long number); - public abstract ProtocolSpec getByBlockNumber(long number); - - public abstract Stream streamMilestoneBlocks(); - - public void setIsPostMerge(final Supplier isPostMerge) { - this.isPostMerge = isPostMerge; - } - - public boolean isPostMerge() { - return isPostMerge.get(); - } + Stream streamMilestoneBlocks(); @Override - public ProtocolSpec getByBlockHeader(final ProcessableBlockHeader blockHeader) { + default ProtocolSpec getByBlockHeader(final ProcessableBlockHeader blockHeader) { return getByBlockNumber(blockHeader.getNumber()); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpec.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpec.java index 3022181b49d..6777f5e7f66 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpec.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpec.java @@ -80,6 +80,7 @@ public class ProtocolSpec { private final Optional withdrawalsProcessor; + private final boolean isPoS; /** * Creates a new protocol specification instance. * @@ -108,6 +109,7 @@ public class ProtocolSpec { * @param powHasher the proof-of-work hasher * @param withdrawalsValidator the withdrawals validator to use * @param withdrawalsProcessor the Withdrawals processor to use + * @param isPoS indicates whether the current spec is PoS */ public ProtocolSpec( final String name, @@ -134,7 +136,8 @@ public ProtocolSpec( final BadBlockManager badBlockManager, final Optional powHasher, final WithdrawalsValidator withdrawalsValidator, - final Optional withdrawalsProcessor) { + final Optional withdrawalsProcessor, + final boolean isPoS) { this.name = name; this.evm = evm; this.transactionValidator = transactionValidator; @@ -160,6 +163,7 @@ public ProtocolSpec( this.powHasher = powHasher; this.withdrawalsValidator = withdrawalsValidator; this.withdrawalsProcessor = withdrawalsProcessor; + this.isPoS = isPoS; } /** @@ -367,4 +371,13 @@ public WithdrawalsValidator getWithdrawalsValidator() { public Optional getWithdrawalsProcessor() { return withdrawalsProcessor; } + + /** + * Returns true if the network is running Proof of Stake + * + * @return true if the network is running Proof of Stake + */ + public boolean isPoS() { + return isPoS; + } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java index 043155dc932..0882196aadb 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java @@ -79,6 +79,7 @@ public class ProtocolSpecBuilder { private FeeMarket feeMarket = FeeMarket.legacy(); private BadBlockManager badBlockManager; private PoWHasher powHasher = PoWHasher.ETHASH_LIGHT; + private boolean isPoS = false; public ProtocolSpecBuilder gasCalculator(final Supplier gasCalculatorBuilder) { this.gasCalculatorBuilder = gasCalculatorBuilder; @@ -257,6 +258,11 @@ public ProtocolSpecBuilder withdrawalsProcessor(final WithdrawalsProcessor withd return this; } + public ProtocolSpecBuilder isPoS(final boolean isPoS) { + this.isPoS = isPoS; + return this; + } + public ProtocolSpec build(final HeaderBasedProtocolSchedule protocolSchedule) { checkNotNull(gasCalculatorBuilder, "Missing gasCalculator"); checkNotNull(gasLimitCalculator, "Missing gasLimitCalculator"); @@ -363,7 +369,8 @@ public ProtocolSpec build(final HeaderBasedProtocolSchedule protocolSchedule) { badBlockManager, Optional.ofNullable(powHasher), withdrawalsValidator, - Optional.ofNullable(withdrawalsProcessor)); + Optional.ofNullable(withdrawalsProcessor), + isPoS); } private PrivateTransactionProcessor createPrivateTransactionProcessor( 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 5ae869830ec..44016a2985e 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 @@ -18,6 +18,7 @@ import org.hyperledger.besu.ethereum.eth.manager.EthPeer.DisconnectCallback; import org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.messages.DisconnectMessage; import org.hyperledger.besu.metrics.BesuMetricCategory; @@ -36,6 +37,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.Predicate; +import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -67,26 +69,37 @@ public class EthPeers { private final Subscribers connectCallbacks = Subscribers.create(); private final Subscribers disconnectCallbacks = Subscribers.create(); private final Collection pendingRequests = new CopyOnWriteArrayList<>(); + private final Supplier currentProtocolSpecSupplier; private Comparator bestPeerComparator; public EthPeers( final String protocolName, + final Supplier currentProtocolSpecSupplier, final Clock clock, final MetricsSystem metricsSystem, final int maxPeers, final int maxMessageSize) { - this(protocolName, clock, metricsSystem, maxPeers, maxMessageSize, Collections.emptyList()); + this( + protocolName, + currentProtocolSpecSupplier, + clock, + metricsSystem, + maxPeers, + maxMessageSize, + Collections.emptyList()); } public EthPeers( final String protocolName, + final Supplier currentProtocolSpecSupplier, final Clock clock, final MetricsSystem metricsSystem, final int maxPeers, final int maxMessageSize, final List permissioningProviders) { this.protocolName = protocolName; + this.currentProtocolSpecSupplier = currentProtocolSpecSupplier; this.clock = clock; this.permissioningProviders = permissioningProviders; this.maxPeers = maxPeers; @@ -148,8 +161,16 @@ public EthPeer peer(final PeerConnection peerConnection) { public PendingPeerRequest executePeerRequest( final PeerRequest request, final long minimumBlockNumber, final Optional peer) { + final long actualMinBlockNumber; + if (minimumBlockNumber > 0 && currentProtocolSpecSupplier.get().isPoS()) { + // if on PoS do not enforce a min block number, since the estimated chain height of the remote + // peer is not updated anymore. + actualMinBlockNumber = 0; + } else { + actualMinBlockNumber = minimumBlockNumber; + } final PendingPeerRequest pendingPeerRequest = - new PendingPeerRequest(this, request, minimumBlockNumber, peer); + new PendingPeerRequest(this, request, actualMinBlockNumber, peer); synchronized (this) { if (!pendingPeerRequest.attemptExecution()) { pendingRequests.add(pendingPeerRequest); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetBlockFromPeerTask.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetBlockFromPeerTask.java index 80ea12c277b..c352fbc3009 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetBlockFromPeerTask.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetBlockFromPeerTask.java @@ -96,7 +96,6 @@ protected void executeTask() { } private CompletableFuture>> downloadHeader() { - long blockNumberToUse = protocolSchedule.isPostMerge() ? 0 : this.blockNumber; return executeSubTask( () -> { final AbstractGetHeadersFromPeerTask task; @@ -104,11 +103,11 @@ private CompletableFuture>> downloadHeader() { hash.map( value -> GetHeadersFromPeerByHashTask.forSingleHash( - protocolSchedule, ethContext, value, blockNumberToUse, metricsSystem)) + protocolSchedule, ethContext, value, blockNumber, metricsSystem)) .orElseGet( () -> GetHeadersFromPeerByNumberTask.forSingleNumber( - protocolSchedule, ethContext, blockNumberToUse, metricsSystem)); + protocolSchedule, ethContext, blockNumber, metricsSystem)); assignedPeer.ifPresent(task::assignPeer); return task.run(); }); diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetBodiesFromPeerTask.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetBodiesFromPeerTask.java index d1522360f67..58a8786d0ac 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetBodiesFromPeerTask.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetBodiesFromPeerTask.java @@ -83,8 +83,7 @@ public static GetBodiesFromPeerTask forHeaders( protected PendingPeerRequest sendRequest() { final List blockHashes = headers.stream().map(BlockHeader::getHash).collect(Collectors.toList()); - final long minimumRequiredBlockNumber = - protocolSchedule.isPostMerge() ? 0 : headers.get(headers.size() - 1).getNumber(); + final long minimumRequiredBlockNumber = headers.get(headers.size() - 1).getNumber(); return sendRequestToPeer( peer -> { diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetHeadersFromPeerByHashTask.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetHeadersFromPeerByHashTask.java index dfade97e7e0..521d7fd398c 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetHeadersFromPeerByHashTask.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetHeadersFromPeerByHashTask.java @@ -45,8 +45,7 @@ public class GetHeadersFromPeerByHashTask extends AbstractGetHeadersFromPeerTask final boolean reverse, final MetricsSystem metricsSystem) { super(protocolSchedule, ethContext, count, skip, reverse, metricsSystem); - this.minimumRequiredBlockNumber = - protocolSchedule.isPostMerge() ? 0 : minimumRequiredBlockNumber; + this.minimumRequiredBlockNumber = minimumRequiredBlockNumber; checkNotNull(referenceHash); this.referenceHash = referenceHash; } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetHeadersFromPeerByNumberTask.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetHeadersFromPeerByNumberTask.java index 1c0108596f6..3ad01aa34a9 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetHeadersFromPeerByNumberTask.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/GetHeadersFromPeerByNumberTask.java @@ -40,7 +40,7 @@ public class GetHeadersFromPeerByNumberTask extends AbstractGetHeadersFromPeerTa final boolean reverse, final MetricsSystem metricsSystem) { super(protocolSchedule, ethContext, count, skip, reverse, metricsSystem); - this.blockNumber = protocolSchedule.isPostMerge() ? 0 : blockNumber; + this.blockNumber = blockNumber; } public static AbstractGetHeadersFromPeerTask startingAtNumber( diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/RetryingGetHeadersEndingAtFromPeerByHashTask.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/RetryingGetHeadersEndingAtFromPeerByHashTask.java index 0e536a79fbe..e467bfba119 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/RetryingGetHeadersEndingAtFromPeerByHashTask.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/task/RetryingGetHeadersEndingAtFromPeerByHashTask.java @@ -53,8 +53,7 @@ public class RetryingGetHeadersEndingAtFromPeerByHashTask final int maxRetries) { super(ethContext, metricsSystem, List::isEmpty, maxRetries); this.protocolSchedule = protocolSchedule; - this.minimumRequiredBlockNumber = - protocolSchedule.isPostMerge() ? 0 : minimumRequiredBlockNumber; + this.minimumRequiredBlockNumber = minimumRequiredBlockNumber; this.count = count; checkNotNull(referenceHash); this.referenceHash = referenceHash; diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java index 1c781339bbd..803871d69d2 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManagerTest.java @@ -131,6 +131,7 @@ public static void setup() { public void handleMalformedRequestIdMessage() { try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), @@ -149,6 +150,7 @@ public void handleMalformedRequestIdMessage() { public void disconnectOnUnsolicitedMessage() { try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), @@ -166,6 +168,7 @@ public void disconnectOnUnsolicitedMessage() { public void disconnectOnFailureToSendStatusMessage() { try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), @@ -184,6 +187,7 @@ public void disconnectOnFailureToSendStatusMessage() { public void disconnectOnWrongChainId() { try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), @@ -214,6 +218,7 @@ public void disconnectNewPoWPeers() { final MergePeerFilter mergePeerFilter = new MergePeerFilter(); try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, protocolContext.getWorldStateArchive(), transactionPool, @@ -262,6 +267,7 @@ public void disconnectNewPoWPeers() { public void doNotDisconnectOnLargeMessageWithinLimits() { try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), @@ -281,6 +287,7 @@ public void doNotDisconnectOnLargeMessageWithinLimits() { public void disconnectOnWrongGenesisHash() { try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), @@ -310,6 +317,7 @@ public void disconnectOnWrongGenesisHash() { public void doNotDisconnectOnValidMessage() { try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), @@ -331,6 +339,7 @@ public void respondToGetHeaders() throws ExecutionException, InterruptedExceptio final CompletableFuture done = new CompletableFuture<>(); try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), @@ -370,6 +379,7 @@ public void respondToGetHeadersWithinLimits() throws ExecutionException, Interru EthProtocolConfiguration.builder().maxGetBlockHeaders(limit).build(); try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), @@ -406,6 +416,7 @@ public void respondToGetHeadersReversed() throws ExecutionException, Interrupted final CompletableFuture done = new CompletableFuture<>(); try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), @@ -442,6 +453,7 @@ public void respondToGetHeadersWithSkip() throws ExecutionException, Interrupted final CompletableFuture done = new CompletableFuture<>(); try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), @@ -481,6 +493,7 @@ public void respondToGetHeadersReversedWithSkip() final CompletableFuture done = new CompletableFuture<>(); try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), @@ -541,6 +554,7 @@ public void respondToGetHeadersPartial() throws ExecutionException, InterruptedE final CompletableFuture done = new CompletableFuture<>(); try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), @@ -578,6 +592,7 @@ public void respondToGetHeadersEmpty() throws ExecutionException, InterruptedExc final CompletableFuture done = new CompletableFuture<>(); try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), @@ -612,6 +627,7 @@ public void respondToGetBodies() throws ExecutionException, InterruptedException final CompletableFuture done = new CompletableFuture<>(); try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), @@ -664,6 +680,7 @@ public void respondToGetBodiesWithinLimits() throws ExecutionException, Interrup EthProtocolConfiguration.builder().maxGetBlockBodies(limit).build(); try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), @@ -712,6 +729,7 @@ public void respondToGetBodiesPartial() throws ExecutionException, InterruptedEx final CompletableFuture done = new CompletableFuture<>(); try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), @@ -754,6 +772,7 @@ public void respondToGetReceipts() throws ExecutionException, InterruptedExcepti final CompletableFuture done = new CompletableFuture<>(); try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), @@ -804,6 +823,7 @@ public void respondToGetReceiptsWithinLimits() throws ExecutionException, Interr EthProtocolConfiguration.builder().maxGetReceipts(limit).build(); try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), @@ -851,6 +871,7 @@ public void respondToGetReceiptsPartial() throws ExecutionException, Interrupted final CompletableFuture done = new CompletableFuture<>(); try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), @@ -895,6 +916,7 @@ public void respondToGetNodeData() throws Exception { try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), @@ -942,6 +964,7 @@ public void respondToGetNodeData() throws Exception { public void newBlockMinedSendsNewBlockMessageToAllPeers() { try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), @@ -1012,6 +1035,7 @@ public void shouldSuccessfullyRespondToGetHeadersRequestLessThanZero() final CompletableFuture done = new CompletableFuture<>(); try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), @@ -1077,6 +1101,7 @@ public void transactionMessagesGoToTheCorrectExecutor() { try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, ethScheduler, protocolContext.getWorldStateArchive(), @@ -1110,6 +1135,7 @@ public void forkIdForChainHeadMayBeNull() { final EthScheduler ethScheduler = mock(EthScheduler.class); try (final EthProtocolManager ethManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, ethScheduler, protocolContext.getWorldStateArchive(), 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 447910b4bb9..b3b4b850645 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 @@ -48,12 +48,14 @@ public class EthProtocolManagerTestUtil { public static EthProtocolManager create( + final ProtocolSchedule protocolSchedule, final Blockchain blockchain, final TimeoutPolicy timeoutPolicy, final WorldStateArchive worldStateArchive, final TransactionPool transactionPool, final EthProtocolConfiguration ethereumWireProtocolConfiguration) { return create( + protocolSchedule, blockchain, new DeterministicEthScheduler(timeoutPolicy), worldStateArchive, @@ -62,6 +64,7 @@ public static EthProtocolManager create( } public static EthProtocolManager create( + final ProtocolSchedule protocolSchedule, final Blockchain blockchain, final WorldStateArchive worldStateArchive, final TransactionPool transactionPool, @@ -71,6 +74,7 @@ public static EthProtocolManager create( EthPeers peers = new EthPeers( EthProtocol.NAME, + () -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()), TestClock.fixed(), new NoOpMetricsSystem(), 25, @@ -145,15 +149,20 @@ public static EthProtocolManager create( } public static EthProtocolManager create(final Blockchain blockchain) { - return create(blockchain, new DeterministicEthScheduler(TimeoutPolicy.NEVER_TIMEOUT)); + return create( + ProtocolScheduleFixture.MAINNET, + blockchain, + new DeterministicEthScheduler(TimeoutPolicy.NEVER_TIMEOUT)); } public static EthProtocolManager create( + final ProtocolSchedule protocolSchedule, final Blockchain blockchain, final WorldStateArchive worldStateArchive, final TransactionPool transactionPool, final EthProtocolConfiguration ethProtocolConfiguration) { return create( + protocolSchedule, blockchain, new DeterministicEthScheduler(TimeoutPolicy.NEVER_TIMEOUT), worldStateArchive, @@ -166,10 +175,11 @@ public static EthProtocolManager create(final EthScheduler ethScheduler) { final GenesisConfigFile config = GenesisConfigFile.mainnet(); final GenesisState genesisState = GenesisState.fromConfig(config, protocolSchedule); final Blockchain blockchain = createInMemoryBlockchain(genesisState.getBlock()); - return create(blockchain, ethScheduler); + return create(protocolSchedule, blockchain, ethScheduler); } public static EthProtocolManager create( + final ProtocolSchedule protocolSchedule, final Blockchain blockchain, final EthScheduler ethScheduler, final WorldStateArchive worldStateArchive, @@ -178,6 +188,7 @@ public static EthProtocolManager create( EthPeers peers = new EthPeers( EthProtocol.NAME, + () -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()), TestClock.fixed(), new NoOpMetricsSystem(), 25, @@ -196,6 +207,7 @@ public static EthProtocolManager create( } public static EthProtocolManager create( + final ProtocolSchedule protocolSchedule, final Blockchain blockchain, final EthScheduler ethScheduler, final WorldStateArchive worldStateArchive, @@ -205,6 +217,7 @@ public static EthProtocolManager create( EthPeers peers = new EthPeers( EthProtocol.NAME, + () -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()), TestClock.fixed(), new NoOpMetricsSystem(), 25, @@ -224,10 +237,13 @@ public static EthProtocolManager create( } public static EthProtocolManager create( - final Blockchain blockchain, final EthScheduler ethScheduler) { + final ProtocolSchedule protocolSchedule, + final Blockchain blockchain, + final EthScheduler ethScheduler) { EthPeers peers = new EthPeers( EthProtocol.NAME, + () -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()), TestClock.fixed(), new NoOpMetricsSystem(), 25, diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/AbstractMessageTaskTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/AbstractMessageTaskTest.java index 9ab9b1eef29..d7bcfd6f97e 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/AbstractMessageTaskTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/manager/ethtaskutils/AbstractMessageTaskTest.java @@ -90,6 +90,7 @@ public void setupTest() { spy( new EthPeers( EthProtocol.NAME, + () -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()), TestClock.fixed(), metricsSystem, MAX_PEERS, diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/AbstractBlockPropagationManagerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/AbstractBlockPropagationManagerTest.java index e332e4aeb97..57256334f20 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/AbstractBlockPropagationManagerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/AbstractBlockPropagationManagerTest.java @@ -106,6 +106,7 @@ protected void setup(final DataStorageFormat dataStorageFormat) { tempProtocolContext.getConsensusContext(ConsensusContext.class)); ethProtocolManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, blockchainUtil.getWorldArchive(), blockchainUtil.getTransactionPool(), @@ -617,6 +618,7 @@ public void shouldNotImportBlocksThatAreAlreadyBeingImported() { new EthContext( new EthPeers( "eth", + () -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()), TestClock.fixed(), metricsSystem, 25, @@ -749,6 +751,7 @@ public Object answer(final InvocationOnMock invocation) throws Throwable { new EthContext( new EthPeers( "eth", + () -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()), TestClock.fixed(), metricsSystem, 25, diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/RangeHeadersFetcherTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/RangeHeadersFetcherTest.java index 0a0570b8a54..503d59c910a 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/RangeHeadersFetcherTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/RangeHeadersFetcherTest.java @@ -74,6 +74,7 @@ public static void setUpClass() { public void setUpTest() { ethProtocolManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, () -> false, protocolContext.getWorldStateArchive(), 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 2e7c8fadc2b..d9df79a402c 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 @@ -16,7 +16,6 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; -import static org.assertj.core.api.Fail.failBecauseExceptionWasNotThrown; import static org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider.createInMemoryBlockchain; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; @@ -43,9 +42,6 @@ import java.util.List; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; import javax.annotation.Nonnull; import org.junit.Before; @@ -201,41 +197,6 @@ public void shouldRequestHeaderBeforeCurrentHeight() throws Exception { assertThat(blockHeader).isEqualTo(lookingForBlock.getHeader()); } - @Test - public void shouldNotRequestHeaderBeforeLastFinalizedBlock() throws Exception { - final MutableBlockchain localBlockchain = context.getProtocolContext().getBlockchain(); - extendBlockchain(REMOTE_HEIGHT + 2, localBlockchain); - localBlockchain.setFinalized( - localBlockchain.getBlockHashByNumber(REMOTE_HEIGHT + 1).orElseThrow()); - - BackwardSyncStep step = new BackwardSyncStep(context, createBackwardChain(REMOTE_HEIGHT - 1)); - final Block lookingForBlock = getBlockByNumber(REMOTE_HEIGHT - 2); - - final RespondingEthPeer.Responder responder = - RespondingEthPeer.blockchainResponder(remoteBlockchain); - - final CompletableFuture> future = - step.requestHeaders(lookingForBlock.getHeader().getHash()); - - ScheduledExecutorService schedExecutor = Executors.newScheduledThreadPool(2); - schedExecutor.submit( - () -> peer.respondWhileOtherThreadsWork(responder, () -> !future.isDone())); - - schedExecutor.scheduleWithFixedDelay( - ethScheduler::expirePendingTimeouts, 0, 100, TimeUnit.MILLISECONDS); - - future - .handle( - (r, t) -> { - if (t == null || !(t.getCause() instanceof MaxRetriesReachedException)) { - failBecauseExceptionWasNotThrown(MaxRetriesReachedException.class); - } - return r; - }) - .thenRun(schedExecutor::shutdownNow) - .join(); - } - @Test public void shouldThrowWhenResponseIsEmptyWhenRequestingHeader() { BackwardSyncStep step = new BackwardSyncStep(context, createBackwardChain(REMOTE_HEIGHT - 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 6b61831cced..ddb15422559 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 @@ -90,7 +90,9 @@ public void setup() { protocolContext = localBlockchainSetup.getProtocolContext(); ethProtocolManager = EthProtocolManagerTestUtil.create( - localBlockchain, new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem())); + protocolSchedule, + localBlockchain, + new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem())); ethContext = ethProtocolManager.ethContext(); final int blockNumber = 10; diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStepTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/DownloadReceiptsStepTest.java index b5657ab4f97..ec9313ed907 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 @@ -24,6 +24,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockWithReceipts; import org.hyperledger.besu.ethereum.core.BlockchainSetupUtil; +import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; @@ -61,6 +62,7 @@ public void setUp() { TransactionPool transactionPool = mock(TransactionPool.class); ethProtocolManager = EthProtocolManagerTestUtil.create( + ProtocolScheduleFixture.MAINNET, blockchain, () -> false, protocolContext.getWorldStateArchive(), 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 b5bc8168dae..7fdab1e0d3c 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 @@ -26,6 +26,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; 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.EthProtocolConfiguration; import org.hyperledger.besu.ethereum.eth.manager.EthContext; import org.hyperledger.besu.ethereum.eth.manager.EthPeer; @@ -94,6 +95,7 @@ public void setUp() { blockchain = blockchainSetupUtil.getBlockchain(); ethProtocolManager = EthProtocolManagerTestUtil.create( + ProtocolScheduleFixture.MAINNET, blockchain, () -> timeoutCount.getAndDecrement() > 0, blockchainSetupUtil.getWorldArchive(), 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 efe523322c7..9f3031ab65d 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 @@ -89,7 +89,9 @@ public void setup() { protocolContext = localBlockchainSetup.getProtocolContext(); ethProtocolManager = EthProtocolManagerTestUtil.create( - localBlockchain, new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem())); + protocolSchedule, + localBlockchain, + new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem())); ethContext = ethProtocolManager.ethContext(); syncState = new SyncState(protocolContext.getBlockchain(), ethContext.getEthPeers()); diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockConfirmerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockConfirmerTest.java index 11b4e1d249b..741334643cb 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockConfirmerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockConfirmerTest.java @@ -85,6 +85,7 @@ public void setUp() { protocolContext = blockchainSetupUtil.getProtocolContext(); ethProtocolManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, timeout::get, blockchainSetupUtil.getWorldArchive(), diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockRetrieverTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockRetrieverTest.java index e25293634ce..80bc2b9d2a4 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockRetrieverTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fastsync/PivotBlockRetrieverTest.java @@ -88,6 +88,7 @@ public void setUp() { transactionPool = blockchainSetupUtil.getTransactionPool(); ethProtocolManager = EthProtocolManagerTestUtil.create( + protocolSchedule, blockchain, timeout::get, blockchainSetupUtil.getWorldArchive(), diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderForkTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderForkTest.java index 3c877bd2309..cda6e900932 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderForkTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderForkTest.java @@ -64,6 +64,7 @@ public void setupTest() { protocolContext = localBlockchainSetup.getProtocolContext(); ethProtocolManager = EthProtocolManagerTestUtil.create( + protocolSchedule, localBlockchain, new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()), localBlockchainSetup.getWorldArchive(), diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderTest.java index 24d9fa2e305..f9c4cb1e9fa 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderTest.java @@ -101,6 +101,7 @@ public void setupTest() { protocolContext = localBlockchainSetup.getProtocolContext(); ethProtocolManager = EthProtocolManagerTestUtil.create( + protocolSchedule, localBlockchain, new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()), localBlockchainSetup.getWorldArchive(), diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderTotalTerminalDifficultyTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderTotalTerminalDifficultyTest.java index b80e94450d5..1ec29f6994f 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderTotalTerminalDifficultyTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncChainDownloaderTotalTerminalDifficultyTest.java @@ -84,6 +84,7 @@ public void setupTest() { protocolContext = localBlockchainSetup.getProtocolContext(); ethProtocolManager = EthProtocolManagerTestUtil.create( + protocolSchedule, localBlockchain, new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()), localBlockchainSetup.getWorldArchive(), diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncDownloaderTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncDownloaderTest.java index 1214c5da1e6..65e81aafe32 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncDownloaderTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncDownloaderTest.java @@ -76,6 +76,7 @@ public void setupTest() { protocolContext = localBlockchainSetup.getProtocolContext(); ethProtocolManager = EthProtocolManagerTestUtil.create( + protocolSchedule, localBlockchain, new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()), localBlockchainSetup.getWorldArchive(), diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java index 4a766c5d288..495cbfd203d 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/fullsync/FullSyncTargetManagerTest.java @@ -83,6 +83,7 @@ public void setup() { new ProtocolContext(localBlockchain, localWorldState, null); ethProtocolManager = EthProtocolManagerTestUtil.create( + protocolSchedule, localBlockchain, new EthScheduler(1, 1, 1, 1, new NoOpMetricsSystem()), localWorldState, diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java index e5f31408a26..b3abf90364a 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskParameterizedTest.java @@ -144,6 +144,7 @@ public void searchesAgainstNetwork() { final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); final EthProtocolManager ethProtocolManager = EthProtocolManagerTestUtil.create( + protocolSchedule, localBlockchain, worldStateArchive, mock(TransactionPool.class), diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java index f8523b3c557..2976facbe6c 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/sync/tasks/DetermineCommonAncestorTaskTest.java @@ -80,6 +80,7 @@ public void setup() { final WorldStateArchive worldStateArchive = createInMemoryWorldStateArchive(); ethProtocolManager = EthProtocolManagerTestUtil.create( + protocolSchedule, localBlockchain, worldStateArchive, mock(TransactionPool.class), diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java index 22a6840f413..63493da4bfa 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TestNode.java @@ -132,6 +132,7 @@ public TestNode( final EthPeers ethPeers = new EthPeers( EthProtocol.NAME, + () -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()), TestClock.fixed(), metricsSystem, 25, diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactoryTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactoryTest.java index cd17fd07adf..b8295945878 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactoryTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/transactions/TransactionPoolFactoryTest.java @@ -40,6 +40,7 @@ import org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTransactionsSorter; 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.worldstate.WorldStateArchive; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.testutil.TestClock; @@ -60,6 +61,7 @@ public class TransactionPoolFactoryTest { @Mock ProtocolSchedule schedule; @Mock ProtocolContext context; + @Mock ProtocolSpec protocolSpec; @Mock MutableBlockchain blockchain; @Mock EthContext ethContext; @Mock EthMessages ethMessages; @@ -85,6 +87,7 @@ public void setup() { ethPeers = new EthPeers( "ETH", + () -> protocolSpec, TestClock.fixed(), new NoOpMetricsSystem(), 25, diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/NoRewardProtocolScheduleWrapper.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/NoRewardProtocolScheduleWrapper.java index 3991006ac49..e072101d2f6 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/NoRewardProtocolScheduleWrapper.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/NoRewardProtocolScheduleWrapper.java @@ -30,7 +30,7 @@ import java.util.Optional; import java.util.stream.Stream; -public class NoRewardProtocolScheduleWrapper extends ProtocolSchedule { +public class NoRewardProtocolScheduleWrapper implements ProtocolSchedule { private final ProtocolSchedule delegate; @@ -82,7 +82,8 @@ public ProtocolSpec getByBlockNumber(final long number) { original.getBadBlocksManager(), Optional.empty(), original.getWithdrawalsValidator(), - original.getWithdrawalsProcessor()); + original.getWithdrawalsProcessor(), + original.isPoS()); } @Override diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java index 6ae8d70b81d..c0608943ab6 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethContext.java @@ -67,6 +67,7 @@ import java.util.Optional; import java.util.concurrent.locks.ReentrantLock; +import java.util.function.Supplier; import com.fasterxml.jackson.databind.node.ObjectNode; import org.apache.tuweni.bytes.Bytes; @@ -191,9 +192,12 @@ private boolean buildContext( // mining support + final Supplier currentProtocolSpecSupplier = + () -> protocolSchedule.getByBlockHeader(blockchain.getChainHeadHeader()); final EthPeers ethPeers = new EthPeers( "reteseth", + currentProtocolSpecSupplier, retestethClock, metricsSystem, 0, From e12ac3212e42782c32771440a7ea82ed41f22f2d Mon Sep 17 00:00:00 2001 From: Stefan Date: Wed, 15 Feb 2023 11:19:30 +1000 Subject: [PATCH 3/3] remove some code that is not needed Signed-off-by: Stefan --- .../ethereum/eth/sync/backwardsync/BackwardSyncStep.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncStep.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncStep.java index 46837e130bf..dd68b5b0f4b 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncStep.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/backwardsync/BackwardSyncStep.java @@ -69,12 +69,6 @@ protected CompletableFuture> requestHeaders(final Hash hash) { final int batchSize = context.getBatchSize(); LOG.debug("Requesting headers for hash {}, with batch size {}", hash, batchSize); - final Optional maybeFinalizedHeader = - context - .getProtocolContext() - .getBlockchain() - .getFinalized() - .flatMap(context.getProtocolContext().getBlockchain()::getBlockHeader); final RetryingGetHeadersEndingAtFromPeerByHashTask retryingGetHeadersEndingAtFromPeerByHashTask = @@ -82,7 +76,7 @@ protected CompletableFuture> requestHeaders(final Hash hash) { context.getProtocolSchedule(), context.getEthContext(), hash, - maybeFinalizedHeader.map(BlockHeader::getNumber).orElse(0L), + 0, batchSize, context.getMetricsSystem(), context.getEthContext().getEthPeers().peerCount());