From 08e2f87306a19b225c07d1fe32701cd91d0c4295 Mon Sep 17 00:00:00 2001 From: Stefan Pingel <16143240+pinges@users.noreply.github.com> Date: Wed, 15 Feb 2023 11:36:58 +1000 Subject: [PATCH] reintroduce checking of block height for certain tasks when we are not PoS (Revert PR#3911) (#5083) * reintroduce checking of block height for certain tasks when we are not PoS (Revert PR#3911) Signed-off-by: Stefan --- .../controller/BesuControllerBuilder.java | 4 ++ .../Istanbul99ProtocolManagerTest.java | 1 + .../methods/EthGetTransactionReceiptTest.java | 6 ++- .../mainnet/MainnetProtocolSpecs.java | 3 +- .../besu/ethereum/mainnet/ProtocolSpec.java | 15 ++++++- .../ethereum/mainnet/ProtocolSpecBuilder.java | 9 ++++- .../besu/ethereum/eth/manager/EthPeers.java | 25 +++++++++++- .../manager/task/AbstractPeerRequestTask.java | 4 -- .../manager/task/GetBlockFromPeerTask.java | 2 +- .../manager/task/GetBodiesFromPeerTask.java | 4 +- .../task/GetHeadersFromPeerByHashTask.java | 39 ++++++++++++++++--- .../task/GetHeadersFromPeerByNumberTask.java | 3 +- ...gGetHeadersEndingAtFromPeerByHashTask.java | 19 ++++++++- .../ethereum/eth/sync/ChainHeadTracker.java | 1 + .../eth/sync/DownloadHeadersStep.java | 1 + .../sync/backwardsync/BackwardSyncStep.java | 1 + .../eth/sync/fastsync/FastSyncActions.java | 6 ++- .../fastsync/PivotSelectorFromSafeBlock.java | 2 +- .../eth/sync/range/RangeHeadersFetcher.java | 1 + .../tasks/DownloadHeaderSequenceTask.java | 7 +++- .../RetryingGetHeaderFromPeerByHashTask.java | 11 +++++- .../eth/manager/EthProtocolManagerTest.java | 26 +++++++++++++ .../manager/EthProtocolManagerTestUtil.java | 22 +++++++++-- .../ethtaskutils/AbstractMessageTaskTest.java | 1 + .../GetHeadersFromPeerByHashTaskTest.java | 29 ++++++++++++-- .../AbstractBlockPropagationManagerTest.java | 3 ++ .../eth/sync/RangeHeadersFetcherTest.java | 1 + .../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 | 3 +- .../ethereum/retesteth/RetestethContext.java | 4 ++ 44 files changed, 244 insertions(+), 34 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/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/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/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/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..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 @@ -103,7 +103,7 @@ private CompletableFuture>> downloadHeader() { hash.map( value -> GetHeadersFromPeerByHashTask.forSingleHash( - protocolSchedule, ethContext, value, metricsSystem)) + protocolSchedule, ethContext, value, blockNumber, metricsSystem)) .orElseGet( () -> GetHeadersFromPeerByNumberTask.forSingleNumber( 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..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,12 +83,14 @@ public static GetBodiesFromPeerTask forHeaders( protected PendingPeerRequest sendRequest() { final List blockHashes = headers.stream().map(BlockHeader::getHash).collect(Collectors.toList()); + final long minimumRequiredBlockNumber = 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..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 @@ -32,17 +32,20 @@ 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 = minimumRequiredBlockNumber; checkNotNull(referenceHash); this.referenceHash = referenceHash; } @@ -51,40 +54,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 +125,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..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 @@ -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..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 @@ -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,13 @@ 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 = minimumRequiredBlockNumber; this.count = count; checkNotNull(referenceHash); this.referenceHash = referenceHash; @@ -60,11 +63,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 +82,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 d00f979b773..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 @@ -76,6 +76,7 @@ protected CompletableFuture> requestHeaders(final Hash hash) { context.getProtocolSchedule(), context.getEthContext(), hash, + 0, 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 8e6cac0b485..474257c3cd2 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/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/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/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/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 cee9cdf1293..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 @@ -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,