From 963da3d7ac99b85b7e928177ad0bc0cefc9eba58 Mon Sep 17 00:00:00 2001 From: Justin Florentine Date: Thu, 16 Jun 2022 14:04:18 -0400 Subject: [PATCH] Release 22.4.3 (#3978) * reverts disconnect of pow network * updates gav coords to 22.4.3 Signed-off-by: Justin Florentine --- .../controller/BesuControllerBuilder.java | 54 ++------ .../TransitionBesuControllerBuilder.java | 80 +---------- .../merge/FinalizedBlockHashSupplier.java | 1 + .../besu/consensus/merge/MergeContext.java | 11 ++ .../consensus/merge/PostMergeContext.java | 8 +- .../consensus/merge/PostMergeContextTest.java | 6 +- .../merge/NewForkchoiceMessageListener.java | 28 ---- .../merge/NewMergeStateCallback.java | 26 ---- .../eth/manager/EthProtocolManager.java | 94 +------------ .../eth/sync/DefaultSynchronizer.java | 24 +--- .../eth/manager/EthProtocolManagerTest.java | 129 +++--------------- gradle.properties | 2 +- 12 files changed, 58 insertions(+), 405 deletions(-) delete mode 100644 ethereum/eth/src/main/java/org/hyperledger/besu/consensus/merge/NewForkchoiceMessageListener.java delete mode 100644 ethereum/eth/src/main/java/org/hyperledger/besu/consensus/merge/NewMergeStateCallback.java 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 972adf07ebb..62a217f7214 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/BesuControllerBuilder.java @@ -98,7 +98,6 @@ import java.util.OptionalLong; import java.util.function.Supplier; -import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -360,15 +359,11 @@ public BesuController build() { Optional.of( ImmutableCheckpoint.builder() .blockHash( - Hash.fromHexString( - configOptions.getCheckpointOptions().getHash().get())) // NOSONAR + Hash.fromHexString(configOptions.getCheckpointOptions().getHash().get())) .blockNumber(configOptions.getCheckpointOptions().getNumber().getAsLong()) .totalDifficulty( Difficulty.fromHexString( - configOptions - .getCheckpointOptions() - .getTotalDifficulty() - .get())) // NOSONAR + configOptions.getCheckpointOptions().getTotalDifficulty().get())) .build()); } @@ -408,14 +403,19 @@ public BesuController build() { final PivotBlockSelector pivotBlockSelector = createPivotSelector(protocolContext); final Synchronizer synchronizer = - createSynchronizer( + new DefaultSynchronizer( + syncConfig, protocolSchedule, - worldStateStorage, protocolContext, + worldStateStorage, + ethProtocolManager.getBlockBroadcaster(), maybePruner, ethContext, syncState, - ethProtocolManager, + dataDirectory, + clock, + metricsSystem, + getFullSyncTerminationCondition(protocolContext.getBlockchain()), pivotBlockSelector); final MiningCoordinator miningCoordinator = @@ -432,6 +432,7 @@ public BesuController build() { final SubProtocolConfiguration subProtocolConfiguration = createSubProtocolConfiguration(ethProtocolManager, maybeSnapProtocolManager); + ; final JsonRpcMethods additionalJsonRpcMethodFactory = createAdditionalJsonRpcMethodFactory(protocolContext); @@ -460,32 +461,6 @@ public BesuController build() { additionalPluginServices); } - @NotNull - protected DefaultSynchronizer createSynchronizer( - final ProtocolSchedule protocolSchedule, - final WorldStateStorage worldStateStorage, - final ProtocolContext protocolContext, - final Optional maybePruner, - final EthContext ethContext, - final SyncState syncState, - final EthProtocolManager ethProtocolManager, - final PivotBlockSelector pivotBlockSelector) { - return new DefaultSynchronizer( - syncConfig, - protocolSchedule, - protocolContext, - worldStateStorage, - ethProtocolManager.getBlockBroadcaster(), - maybePruner, - ethContext, - syncState, - dataDirectory, - clock, - metricsSystem, - getFullSyncTerminationCondition(protocolContext.getBlockchain()), - pivotBlockSelector); - } - private PivotBlockSelector createPivotSelector(final ProtocolContext protocolContext) { final PivotSelectorFromPeers pivotSelectorFromPeers = new PivotSelectorFromPeers(syncConfig); @@ -532,7 +507,7 @@ protected SyncTerminationCondition getFullSyncTerminationCondition(final Blockch protected void prepForBuild() {} protected JsonRpcMethods createAdditionalJsonRpcMethodFactory( - final ProtocolContext protocolContext) { // NOSONAR + final ProtocolContext protocolContext) { return apis -> Collections.emptyMap(); } @@ -542,8 +517,9 @@ protected SubProtocolConfiguration createSubProtocolConfiguration( final SubProtocolConfiguration subProtocolConfiguration = new SubProtocolConfiguration().withSubProtocol(EthProtocol.get(), ethProtocolManager); maybeSnapProtocolManager.ifPresent( - snapProtocolManager -> - subProtocolConfiguration.withSubProtocol(SnapProtocol.get(), snapProtocolManager)); + snapProtocolManager -> { + subProtocolConfiguration.withSubProtocol(SnapProtocol.get(), snapProtocolManager); + }); return subProtocolConfiguration; } 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 7f5d3c6c06c..3e257cbc30c 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/TransitionBesuControllerBuilder.java @@ -15,7 +15,6 @@ package org.hyperledger.besu.controller; import org.hyperledger.besu.config.GenesisConfigFile; -import org.hyperledger.besu.consensus.merge.MergeContext; import org.hyperledger.besu.consensus.merge.PostMergeContext; import org.hyperledger.besu.consensus.merge.TransitionBackwardSyncContext; import org.hyperledger.besu.consensus.merge.TransitionContext; @@ -32,14 +31,7 @@ import org.hyperledger.besu.ethereum.core.MiningParameters; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.EthProtocolConfiguration; -import org.hyperledger.besu.ethereum.eth.manager.EthContext; -import org.hyperledger.besu.ethereum.eth.manager.EthMessages; -import org.hyperledger.besu.ethereum.eth.manager.EthPeers; import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager; -import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; -import org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator; -import org.hyperledger.besu.ethereum.eth.sync.DefaultSynchronizer; -import org.hyperledger.besu.ethereum.eth.sync.PivotBlockSelector; import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration; import org.hyperledger.besu.ethereum.eth.sync.backwardsync.BackwardSyncContext; import org.hyperledger.besu.ethereum.eth.sync.state.SyncState; @@ -48,10 +40,8 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.storage.StorageProvider; import org.hyperledger.besu.ethereum.worldstate.DataStorageConfiguration; -import org.hyperledger.besu.ethereum.worldstate.Pruner; import org.hyperledger.besu.ethereum.worldstate.PrunerConfiguration; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; -import org.hyperledger.besu.ethereum.worldstate.WorldStateStorage; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.metrics.ObservableMetricsSystem; import org.hyperledger.besu.plugin.services.permissioning.NodeMessagePermissioningProvider; @@ -155,79 +145,13 @@ protected PluginServiceFactory createAdditionalPluginServices( return new NoopPluginServiceFactory(); } - @Override - protected DefaultSynchronizer createSynchronizer( - final ProtocolSchedule protocolSchedule, - final WorldStateStorage worldStateStorage, - final ProtocolContext protocolContext, - final Optional maybePruner, - final EthContext ethContext, - final SyncState syncState, - final EthProtocolManager ethProtocolManager, - final PivotBlockSelector pivotBlockSelector) { - - DefaultSynchronizer sync = - super.createSynchronizer( - protocolSchedule, - worldStateStorage, - protocolContext, - maybePruner, - ethContext, - syncState, - ethProtocolManager, - pivotBlockSelector); - - ConsensusContext cc = protocolContext.getConsensusContext(ConsensusContext.class); - if (cc instanceof MergeContext) { - protocolContext.getConsensusContext(MergeContext.class).addNewForkchoiceMessageListener(sync); - } - return sync; - } - - @Override - protected EthProtocolManager createEthProtocolManager( - final ProtocolContext protocolContext, - final boolean fastSyncEnabled, - final TransactionPool transactionPool, - final EthProtocolConfiguration ethereumWireProtocolConfiguration, - final EthPeers ethPeers, - final EthContext ethContext, - final EthMessages ethMessages, - final EthScheduler scheduler, - final List peerValidators) { - - EthProtocolManager ethProtocolManager = - super.createEthProtocolManager( - protocolContext, - fastSyncEnabled, - transactionPool, - ethereumWireProtocolConfiguration, - ethPeers, - ethContext, - ethMessages, - scheduler, - peerValidators); - - ConsensusContext cc = protocolContext.getConsensusContext(ConsensusContext.class); - if (cc instanceof MergeContext) { - protocolContext - .getConsensusContext(MergeContext.class) - .observeNewIsPostMergeState(ethProtocolManager); - protocolContext - .getConsensusContext(MergeContext.class) - .addNewForkchoiceMessageListener(ethProtocolManager); - } - - return ethProtocolManager; - } - private void initTransitionWatcher( final ProtocolContext protocolContext, final TransitionCoordinator composedCoordinator) { PostMergeContext postMergeContext = protocolContext.getConsensusContext(PostMergeContext.class); postMergeContext.observeNewIsPostMergeState( - (isPoS, difficultyStoppedAt) -> { - if (isPoS) { + newIsPostMergeState -> { + if (newIsPostMergeState) { // if we transitioned to post-merge, stop and disable any mining composedCoordinator.getPreMergeObject().disable(); composedCoordinator.getPreMergeObject().stop(); diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/FinalizedBlockHashSupplier.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/FinalizedBlockHashSupplier.java index 03b26ede452..46d9172cabc 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/FinalizedBlockHashSupplier.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/FinalizedBlockHashSupplier.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.consensus.merge; +import org.hyperledger.besu.consensus.merge.MergeContext.NewForkchoiceMessageListener; import org.hyperledger.besu.datatypes.Hash; import java.util.Optional; diff --git a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/MergeContext.java b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/MergeContext.java index e71158b4de2..ba6af5b0dd8 100644 --- a/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/MergeContext.java +++ b/consensus/merge/src/main/java/org/hyperledger/besu/consensus/merge/MergeContext.java @@ -67,4 +67,15 @@ void fireNewUnverifiedForkchoiceMessageEvent( final Hash headBlockHash, final Optional maybeFinalizedBlockHash, final Hash safeBlockHash); + + interface NewMergeStateCallback { + void onNewIsPostMergeState(final boolean newIsPostMergeState); + } + + interface NewForkchoiceMessageListener { + void onNewForkchoiceMessage( + final Hash headBlockHash, + final Optional maybeFinalizedBlockHash, + final Hash safeBlockHash); + } } 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 9036177d587..3babd1bf85e 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 @@ -83,13 +83,13 @@ public PostMergeContext setTerminalTotalDifficulty(final Difficulty newTerminalT } @Override - public void setIsPostMerge(final Difficulty difficultyStoppedAt) { + public void setIsPostMerge(final Difficulty totalDifficulty) { if (isPostMerge.get().orElse(Boolean.FALSE) && lastFinalized.get() != null) { // if we have finalized, we never switch back to a pre-merge once we have transitioned // post-TTD. return; } - final boolean newState = terminalTotalDifficulty.get().lessOrEqualThan(difficultyStoppedAt); + final boolean newState = terminalTotalDifficulty.get().lessOrEqualThan(totalDifficulty); final Optional oldState = isPostMerge.getAndSet(Optional.of(newState)); // if we are past TTD, set it: @@ -99,9 +99,7 @@ public void setIsPostMerge(final Difficulty difficultyStoppedAt) { if (oldState.isEmpty() || oldState.get() != newState) { newMergeStateCallbackSubscribers.forEach( - newMergeStateCallback -> - newMergeStateCallback.onCrossingMergeBoundary( - newState, Optional.of(difficultyStoppedAt))); + newMergeStateCallback -> newMergeStateCallback.onNewIsPostMergeState(newState)); } } diff --git a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/PostMergeContextTest.java b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/PostMergeContextTest.java index afaab9debff..4c548efc728 100644 --- a/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/PostMergeContextTest.java +++ b/consensus/merge/src/test/java/org/hyperledger/besu/consensus/merge/PostMergeContextTest.java @@ -22,6 +22,7 @@ import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; +import org.hyperledger.besu.consensus.merge.MergeContext.NewMergeStateCallback; import org.hyperledger.besu.consensus.merge.blockcreation.PayloadIdentifier; import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeader; @@ -172,9 +173,8 @@ private static class MergeStateChangeCollector implements NewMergeStateCallback final List stateChanges = new ArrayList<>(); @Override - public void onCrossingMergeBoundary( - final boolean isPoS, final Optional difficultyStoppedAt) { - stateChanges.add(isPoS); + public void onNewIsPostMergeState(final boolean newIsPostMergeState) { + stateChanges.add(newIsPostMergeState); } public void reset() { diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/consensus/merge/NewForkchoiceMessageListener.java b/ethereum/eth/src/main/java/org/hyperledger/besu/consensus/merge/NewForkchoiceMessageListener.java deleted file mode 100644 index 3ec0e611e50..00000000000 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/consensus/merge/NewForkchoiceMessageListener.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright Hyperledger Besu Contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * - */ - -package org.hyperledger.besu.consensus.merge; - -import org.hyperledger.besu.datatypes.Hash; - -import java.util.Optional; - -public interface NewForkchoiceMessageListener { - void onNewForkchoiceMessage( - final Hash headBlockHash, - final Optional maybeFinalizedBlockHash, - final Hash safeBlockHash); -} diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/consensus/merge/NewMergeStateCallback.java b/ethereum/eth/src/main/java/org/hyperledger/besu/consensus/merge/NewMergeStateCallback.java deleted file mode 100644 index 4e1717e7a97..00000000000 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/consensus/merge/NewMergeStateCallback.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright Hyperledger Besu Contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * - */ - -package org.hyperledger.besu.consensus.merge; - -import org.hyperledger.besu.ethereum.core.Difficulty; - -import java.util.Optional; - -public interface NewMergeStateCallback { - - void onCrossingMergeBoundary(final boolean isPoS, final Optional difficultyStoppedAt); -} diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java index 29d7937fd11..5cd38791543 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthProtocolManager.java @@ -16,8 +16,6 @@ import static com.google.common.base.Preconditions.checkArgument; -import org.hyperledger.besu.consensus.merge.NewForkchoiceMessageListener; -import org.hyperledger.besu.consensus.merge.NewMergeStateCallback; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.chain.Blockchain; import org.hyperledger.besu.ethereum.chain.MinedBlockObserver; @@ -49,8 +47,6 @@ import java.util.Optional; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.locks.StampedLock; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; @@ -58,16 +54,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class EthProtocolManager - implements ProtocolManager, - MinedBlockObserver, - NewMergeStateCallback, - NewForkchoiceMessageListener { +public class EthProtocolManager implements ProtocolManager, MinedBlockObserver { private static final Logger LOG = LoggerFactory.getLogger(EthProtocolManager.class); private final EthScheduler scheduler; private final CountDownLatch shutdown; private final AtomicBoolean stopped = new AtomicBoolean(false); + private final Hash genesisHash; private final ForkIdManager forkIdManager; private final BigInteger networkId; @@ -78,10 +71,6 @@ public class EthProtocolManager private final Blockchain blockchain; private final BlockBroadcaster blockBroadcaster; private final List peerValidators; - private Optional powTerminalDifficulty = Optional.empty(); - private final StampedLock powTerminalDifficultyLock = new StampedLock(); - private Hash lastFinalized = Hash.ZERO; - private final AtomicLong numFinalizedSeen = new AtomicLong(0); public EthProtocolManager( final Blockchain blockchain, @@ -102,7 +91,7 @@ public EthProtocolManager( this.blockchain = blockchain; this.shutdown = new CountDownLatch(1); - this.genesisHash = blockchain.getBlockHashByNumber(0L).orElse(Hash.ZERO); + genesisHash = blockchain.getBlockHashByNumber(0L).get(); this.forkIdManager = forkIdManager; @@ -248,7 +237,7 @@ public void processMessage(final Capability cap, final Message message) { final EthPeer ethPeer = ethPeers.peer(message.getConnection()); if (ethPeer == null) { LOG.debug( - "Ignoring message received from unknown peer connection: {}", message.getConnection()); + "Ignoring message received from unknown peer connection: " + message.getConnection()); return; } @@ -282,11 +271,6 @@ public void processMessage(final Capability cap, final Message message) { return; } - if (isFinalized() && (code == EthPV62.NEW_BLOCK || code == EthPV62.NEW_BLOCK_HASHES)) { - LOG.debug("disconnecting peer for sending new blocks after transition to PoS"); - ethPeer.disconnect(DisconnectReason.SUBPROTOCOL_TRIGGERED); - } - // This will handle responses ethPeers.dispatchMessage(ethPeer, ethMessage, getSupportedProtocol()); @@ -313,7 +297,7 @@ public void processMessage(final Capability cap, final Message message) { responseData -> { try { ethPeer.send(responseData, getSupportedProtocol()); - } catch (final PeerNotConnected missingPeerException) { + } catch (final PeerNotConnected __) { // Peer disconnected before we could respond - nothing to do } }); @@ -385,19 +369,6 @@ private void handleStatusMessage(final EthPeer peer, final MessageData data) { networkId, status.genesisHash()); peer.disconnect(DisconnectReason.SUBPROTOCOL_TRIGGERED); - } else if (isFinalized()) { - long lockStamp = this.powTerminalDifficultyLock.readLock(); - try { - if (this.powTerminalDifficulty.isPresent() - && status.totalDifficulty().greaterThan(this.powTerminalDifficulty.get())) { - LOG.debug( - "Disconnecting peer with difficulty {}, likely still on PoW chain", - status.totalDifficulty()); - peer.disconnect(DisconnectReason.SUBPROTOCOL_TRIGGERED); - } - } finally { - this.powTerminalDifficultyLock.unlockRead(lockStamp); - } } else { LOG.debug("Received status message from {}: {}", peer, status); peer.registerStatusReceived( @@ -411,10 +382,6 @@ private void handleStatusMessage(final EthPeer peer, final MessageData data) { } } - private boolean isFinalized() { - return this.numFinalizedSeen.get() > 1; - } - @Override public void blockMined(final Block block) { // This assumes the block has already been included in the chain @@ -434,55 +401,4 @@ public List getForkIdAsBytesList() { ? Collections.emptyList() : chainHeadForkId.getForkIdAsBytesList(); } - - @Override - public void onCrossingMergeBoundary( - final boolean isPoS, final Optional difficultyStoppedAt) { - if (isPoS) { - long lockStamp = this.powTerminalDifficultyLock.writeLock(); - try { - this.powTerminalDifficulty = difficultyStoppedAt; - } finally { - this.powTerminalDifficultyLock.unlockWrite(lockStamp); - } - } - } - - private void disconnectKnownPowPeers() { - long lockStamp = powTerminalDifficultyLock.readLock(); - try { - if (powTerminalDifficulty.isPresent()) { - LOG.info( - "disconnecting peers with total difficulty over {}", - powTerminalDifficulty.get().toBigInteger()); - ethPeers - .streamAllPeers() - .filter( - ethPeer -> - ethPeer - .chainState() - .getBestBlock() - .totalDifficulty - .greaterThan(powTerminalDifficulty.get())) - .forEach(ethPeer -> ethPeer.disconnect(DisconnectReason.SUBPROTOCOL_TRIGGERED)); - } - } finally { - powTerminalDifficultyLock.unlockRead(lockStamp); - } - } - - @Override - public void onNewForkchoiceMessage( - final Hash headBlockHash, - final Optional maybeFinalizedBlockHash, - final Hash safeBlockHash) { - if (maybeFinalizedBlockHash.isPresent() - && !maybeFinalizedBlockHash.get().equals(this.lastFinalized)) { - this.lastFinalized = maybeFinalizedBlockHash.get(); - this.numFinalizedSeen.getAndIncrement(); - if (isFinalized()) { - disconnectKnownPowPeers(); - } - } - } } diff --git a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java index 188e959992f..dd1e19e2c70 100644 --- a/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java +++ b/ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/sync/DefaultSynchronizer.java @@ -16,8 +16,6 @@ import static com.google.common.base.Preconditions.checkNotNull; -import org.hyperledger.besu.consensus.merge.NewForkchoiceMessageListener; -import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.Synchronizer; import org.hyperledger.besu.ethereum.eth.manager.EthContext; @@ -43,12 +41,11 @@ import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicLong; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class DefaultSynchronizer implements Synchronizer, NewForkchoiceMessageListener { +public class DefaultSynchronizer implements Synchronizer { private static final Logger LOG = LoggerFactory.getLogger(DefaultSynchronizer.class); @@ -61,8 +58,6 @@ public class DefaultSynchronizer implements Synchronizer, NewForkchoiceMessageLi private final ProtocolContext protocolContext; private final PivotBlockSelector pivotBlockSelector; private final SyncTerminationCondition terminationCondition; - private Hash lastFinalized = Hash.ZERO; - private final AtomicLong numFinalizedSeen = new AtomicLong(0); public DefaultSynchronizer( final SynchronizerConfiguration syncConfig, @@ -293,21 +288,4 @@ private Void finalizeSync(final Void unused) { running.set(false); return null; } - - @Override - public void onNewForkchoiceMessage( - final Hash headBlockHash, - final Optional maybeFinalizedBlockHash, - final Hash safeBlockHash) { - if (maybeFinalizedBlockHash.isPresent() - && !maybeFinalizedBlockHash.get().equals(this.lastFinalized)) { - this.lastFinalized = maybeFinalizedBlockHash.get(); - this.numFinalizedSeen.getAndIncrement(); - if (this.numFinalizedSeen.get() > 1 - && blockPropagationManager.isPresent() - && blockPropagationManager.get().isRunning()) { - blockPropagationManager.get().stop(); - } - } - } } 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 b8665df67a2..8d67d051d7a 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 @@ -66,7 +66,6 @@ import org.hyperledger.besu.ethereum.p2p.rlpx.wire.DefaultMessage; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.MessageData; import org.hyperledger.besu.ethereum.p2p.rlpx.wire.RawMessage; -import org.hyperledger.besu.ethereum.p2p.rlpx.wire.messages.DisconnectMessage.DisconnectReason; import org.hyperledger.besu.ethereum.worldstate.DataStorageFormat; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; @@ -79,7 +78,6 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; -import java.util.Optional; import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; @@ -203,101 +201,6 @@ public void disconnectOnWrongChainId() { } } - @Test - public void disconnectPoWPeersAfterTransition() { - try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig())) { - - final MockPeerConnection workPeer = setupPeer(ethManager, (cap, msg, conn) -> {}); - final MockPeerConnection stakePeer = setupPeer(ethManager, (cap, msg, conn) -> {}); - - final StatusMessage workPeerStatus = - StatusMessage.create( - EthProtocol.EthVersion.V63, - BigInteger.ONE, - blockchain.getChainHead().getTotalDifficulty().add(20), - blockchain.getChainHeadHash(), - blockchain.getBlockHeader(BlockHeader.GENESIS_BLOCK_NUMBER).get().getHash()); - - final StatusMessage stakePeerStatus = - StatusMessage.create( - EthProtocol.EthVersion.V63, - BigInteger.ONE, - blockchain.getChainHead().getTotalDifficulty(), - blockchain.getChainHeadHash(), - blockchain.getBlockHeader(BlockHeader.GENESIS_BLOCK_NUMBER).get().getHash()); - - ethManager.processMessage(EthProtocol.ETH63, new DefaultMessage(workPeer, workPeerStatus)); - ethManager.processMessage(EthProtocol.ETH63, new DefaultMessage(stakePeer, stakePeerStatus)); - - ethManager.onCrossingMergeBoundary( - true, Optional.of(blockchain.getChainHead().getTotalDifficulty())); - ethManager.onNewForkchoiceMessage( - Hash.EMPTY, Optional.of(Hash.hash(Bytes.of(1))), Hash.EMPTY); - ethManager.onNewForkchoiceMessage( - Hash.EMPTY, Optional.of(Hash.hash(Bytes.of(2))), Hash.EMPTY); - assertThat(workPeer.isDisconnected()).isTrue(); - assertThat(workPeer.getDisconnectReason()).isPresent(); - assertThat(workPeer.getDisconnectReason()) - .get() - .isEqualTo(DisconnectReason.SUBPROTOCOL_TRIGGERED); - assertThat(stakePeer.isDisconnected()).isFalse(); - } - } - - @Test - public void disconnectNewPoWPeers() { - try (final EthProtocolManager ethManager = - EthProtocolManagerTestUtil.create( - blockchain, - () -> false, - protocolContext.getWorldStateArchive(), - transactionPool, - EthProtocolConfiguration.defaultConfig())) { - - final MockPeerConnection workPeer = setupPeer(ethManager, (cap, msg, conn) -> {}); - final MockPeerConnection stakePeer = setupPeer(ethManager, (cap, msg, conn) -> {}); - - final StatusMessage workPeerStatus = - StatusMessage.create( - EthProtocol.EthVersion.V63, - BigInteger.ONE, - blockchain.getChainHead().getTotalDifficulty().add(20), - blockchain.getChainHeadHash(), - blockchain.getBlockHeader(BlockHeader.GENESIS_BLOCK_NUMBER).get().getHash()); - - final StatusMessage stakePeerStatus = - StatusMessage.create( - EthProtocol.EthVersion.V63, - BigInteger.ONE, - blockchain.getChainHead().getTotalDifficulty(), - blockchain.getChainHeadHash(), - blockchain.getBlockHeader(BlockHeader.GENESIS_BLOCK_NUMBER).get().getHash()); - - ethManager.processMessage(EthProtocol.ETH63, new DefaultMessage(stakePeer, stakePeerStatus)); - - ethManager.onCrossingMergeBoundary( - true, Optional.of(blockchain.getChainHead().getTotalDifficulty())); - ethManager.onNewForkchoiceMessage( - Hash.EMPTY, Optional.of(Hash.hash(Bytes.of(1))), Hash.EMPTY); - ethManager.onNewForkchoiceMessage( - Hash.EMPTY, Optional.of(Hash.hash(Bytes.of(2))), Hash.EMPTY); - - ethManager.processMessage(EthProtocol.ETH63, new DefaultMessage(workPeer, workPeerStatus)); - assertThat(workPeer.isDisconnected()).isTrue(); - assertThat(workPeer.getDisconnectReason()).isPresent(); - assertThat(workPeer.getDisconnectReason()) - .get() - .isEqualTo(DisconnectReason.SUBPROTOCOL_TRIGGERED); - assertThat(stakePeer.isDisconnected()).isFalse(); - } - } - @Test public void disconnectOnVeryLargeMessage() { try (final EthProtocolManager ethManager = @@ -390,7 +293,7 @@ public void respondToGetHeaders() throws ExecutionException, InterruptedExceptio final BlockHeadersMessage headersMsg = BlockHeadersMessage.readFrom(message); final List headers = Lists.newArrayList(headersMsg.getHeaders(protocolSchedule)); - assertThat(headers).hasSize(blockCount); + assertThat(headers.size()).isEqualTo(blockCount); for (int i = 0; i < blockCount; i++) { assertThat(headers.get(i).getNumber()).isEqualTo(startBlock + i); } @@ -427,7 +330,7 @@ public void respondToGetHeadersWithinLimits() throws ExecutionException, Interru final BlockHeadersMessage headersMsg = BlockHeadersMessage.readFrom(message); final List headers = Lists.newArrayList(headersMsg.getHeaders(protocolSchedule)); - assertThat(headers).hasSize(limit); + assertThat(headers.size()).isEqualTo(limit); for (int i = 0; i < limit; i++) { assertThat(headers.get(i).getNumber()).isEqualTo(startBlock + i); } @@ -463,7 +366,7 @@ public void respondToGetHeadersReversed() throws ExecutionException, Interrupted final BlockHeadersMessage headersMsg = BlockHeadersMessage.readFrom(message); final List headers = Lists.newArrayList(headersMsg.getHeaders(protocolSchedule)); - assertThat(headers).hasSize(blockCount); + assertThat(headers.size()).isEqualTo(blockCount); for (int i = 0; i < blockCount; i++) { assertThat(headers.get(i).getNumber()).isEqualTo(endBlock - i); } @@ -501,7 +404,7 @@ public void respondToGetHeadersWithSkip() throws ExecutionException, Interrupted final BlockHeadersMessage headersMsg = BlockHeadersMessage.readFrom(message); final List headers = Lists.newArrayList(headersMsg.getHeaders(protocolSchedule)); - assertThat(headers).hasSize(blockCount); + assertThat(headers.size()).isEqualTo(blockCount); for (int i = 0; i < blockCount; i++) { assertThat(headers.get(i).getNumber()).isEqualTo(startBlock + i * (skip + 1)); } @@ -540,7 +443,7 @@ public void respondToGetHeadersReversedWithSkip() final BlockHeadersMessage headersMsg = BlockHeadersMessage.readFrom(message); final List headers = Lists.newArrayList(headersMsg.getHeaders(protocolSchedule)); - assertThat(headers).hasSize(blockCount); + assertThat(headers.size()).isEqualTo(blockCount); for (int i = 0; i < blockCount; i++) { assertThat(headers.get(i).getNumber()).isEqualTo(endBlock - i * (skip + 1)); } @@ -599,7 +502,7 @@ public void respondToGetHeadersPartial() throws ExecutionException, InterruptedE final BlockHeadersMessage headersMsg = BlockHeadersMessage.readFrom(message); final List headers = Lists.newArrayList(headersMsg.getHeaders(protocolSchedule)); - assertThat(headers).hasSize(2); + assertThat(headers.size()).isEqualTo(2); for (int i = 0; i < 2; i++) { assertThat(headers.get(i).getNumber()).isEqualTo(startBlock + i); } @@ -636,7 +539,7 @@ public void respondToGetHeadersEmpty() throws ExecutionException, InterruptedExc final BlockHeadersMessage headersMsg = BlockHeadersMessage.readFrom(message); final List headers = Lists.newArrayList(headersMsg.getHeaders(protocolSchedule)); - assertThat(headers).isEmpty(); + assertThat(headers.size()).isEqualTo(0); done.complete(null); }; final PeerConnection peer = setupPeer(ethManager, onSend); @@ -680,7 +583,7 @@ public void respondToGetBodies() throws ExecutionException, InterruptedException final BlockBodiesMessage blocksMessage = BlockBodiesMessage.readFrom(message); final List bodies = Lists.newArrayList(blocksMessage.bodies(protocolSchedule)); - assertThat(bodies).hasSize(blockCount); + assertThat(bodies.size()).isEqualTo(blockCount); for (int i = 0; i < blockCount; i++) { assertThat(expectedBlocks[i].getBody()).isEqualTo(bodies.get(i)); } @@ -729,7 +632,7 @@ public void respondToGetBodiesWithinLimits() throws ExecutionException, Interrup final BlockBodiesMessage blocksMessage = BlockBodiesMessage.readFrom(message); final List bodies = Lists.newArrayList(blocksMessage.bodies(protocolSchedule)); - assertThat(bodies).hasSize(limit); + assertThat(bodies.size()).isEqualTo(limit); for (int i = 0; i < limit; i++) { assertThat(expectedBlocks[i].getBody()).isEqualTo(bodies.get(i)); } @@ -773,7 +676,7 @@ public void respondToGetBodiesPartial() throws ExecutionException, InterruptedEx final BlockBodiesMessage blocksMessage = BlockBodiesMessage.readFrom(message); final List bodies = Lists.newArrayList(blocksMessage.bodies(protocolSchedule)); - assertThat(bodies).hasSize(1); + assertThat(bodies.size()).isEqualTo(1); assertThat(expectedBlock.getBody()).isEqualTo(bodies.get(0)); done.complete(null); }; @@ -818,7 +721,7 @@ public void respondToGetReceipts() throws ExecutionException, InterruptedExcepti final ReceiptsMessage receiptsMessage = ReceiptsMessage.readFrom(message); final List> receipts = Lists.newArrayList(receiptsMessage.receipts()); - assertThat(receipts).hasSize(blockCount); + assertThat(receipts.size()).isEqualTo(blockCount); for (int i = 0; i < blockCount; i++) { assertThat(expectedReceipts.get(i)).isEqualTo(receipts.get(i)); } @@ -866,7 +769,7 @@ public void respondToGetReceiptsWithinLimits() throws ExecutionException, Interr final ReceiptsMessage receiptsMessage = ReceiptsMessage.readFrom(message); final List> receipts = Lists.newArrayList(receiptsMessage.receipts()); - assertThat(receipts).hasSize(limit); + assertThat(receipts.size()).isEqualTo(limit); for (int i = 0; i < limit; i++) { assertThat(expectedReceipts.get(i)).isEqualTo(receipts.get(i)); } @@ -910,7 +813,7 @@ public void respondToGetReceiptsPartial() throws ExecutionException, Interrupted final ReceiptsMessage receiptsMessage = ReceiptsMessage.readFrom(message); final List> receipts = Lists.newArrayList(receiptsMessage.receipts()); - assertThat(receipts).hasSize(1); + assertThat(receipts.size()).isEqualTo(1); assertThat(expectedReceipts).isEqualTo(receipts.get(0)); done.complete(null); }; @@ -958,7 +861,7 @@ public void respondToGetNodeData() throws Exception { assertThat(message.getCode()).isEqualTo(EthPV63.NODE_DATA); final NodeDataMessage receiptsMessage = NodeDataMessage.readFrom(message); final List nodeData = receiptsMessage.nodeData(); - assertThat(nodeData).hasSize(blockCount); + assertThat(nodeData.size()).isEqualTo(blockCount); for (int i = 0; i < blockCount; i++) { assertThat(expectedResults.get(i)).isEqualTo(nodeData.get(i)); } @@ -1025,7 +928,7 @@ public void newBlockMinedSendsNewBlockMessageToAllPeers() { assertThat(msg.totalDifficulty(protocolSchdeule)).isEqualTo(expectedTotalDifficulty); } - assertThat(receivingPeerCaptor.getAllValues()).containsAll(peers); + assertThat(receivingPeerCaptor.getAllValues().containsAll(peers)).isTrue(); } } @@ -1067,7 +970,7 @@ public void shouldSuccessfullyRespondToGetHeadersRequestLessThanZero() final BlockHeadersMessage headersMsg = BlockHeadersMessage.readFrom(message); final List headers = Lists.newArrayList(headersMsg.getHeaders(protocolSchedule)); - assertThat(headers).hasSize(receivedBlockCount); + assertThat(headers.size()).isEqualTo(receivedBlockCount); for (int i = 0; i < receivedBlockCount; i++) { assertThat(headers.get(i).getNumber()).isEqualTo(receivedBlockCount - 1 - i); } diff --git a/gradle.properties b/gradle.properties index ccb71efba54..49708e60e7a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=22.4.3-SNAPSHOT +version=22.4.3 # Workaround for Java 16 and spotless bug 834 https://github.com/diffplug/spotless/issues/834 org.gradle.jvmargs=--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \