From e1c8eb7fb04f6602da602e75b84795f2e3220326 Mon Sep 17 00:00:00 2001 From: Justin Florentine Date: Tue, 2 Aug 2022 13:36:12 -0400 Subject: [PATCH] applies merge filtering to peers after 2 finalized (#4124) * applies merge filtering to peers after 2 finalized * fixes logical error in handling status messages Signed-off-by: Justin Florentine --- .../besu/controller/MergeBesuControllerBuilder.java | 10 ++++++---- .../besu/ethereum/eth/manager/EthProtocolManager.java | 8 +++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java index bb140b87ed..860385ae44 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/MergeBesuControllerBuilder.java @@ -104,11 +104,13 @@ public class MergeBesuControllerBuilder extends BesuControllerBuilder { ethPeers.setBestChainComparator(mergeBestPeerComparator); mergeContext.observeNewIsPostMergeState(mergeBestPeerComparator); - if (mergePeerFilter.isPresent()) { + Optional filterToUse = Optional.of(new MergePeerFilter()); - mergeContext.observeNewIsPostMergeState(mergePeerFilter.get()); - mergeContext.addNewForkchoiceMessageListener(mergePeerFilter.get()); + if (mergePeerFilter.isPresent()) { + filterToUse = mergePeerFilter; } + mergeContext.observeNewIsPostMergeState(filterToUse.get()); + mergeContext.addNewForkchoiceMessageListener(filterToUse.get()); EthProtocolManager ethProtocolManager = super.createEthProtocolManager( @@ -121,7 +123,7 @@ public class MergeBesuControllerBuilder extends BesuControllerBuilder { ethMessages, scheduler, peerValidators, - mergePeerFilter); + filterToUse); return ethProtocolManager; } 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 5edcb3236d..2710cc1879 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 @@ -376,11 +376,9 @@ public class EthProtocolManager implements ProtocolManager, MinedBlockObserver { networkId, status.genesisHash()); peer.disconnect(DisconnectReason.SUBPROTOCOL_TRIGGERED); - } else if (mergePeerFilter.isPresent()) { - final boolean disconnected = mergePeerFilter.get().disconnectIfPoW(status, peer); - if (disconnected) { - handleDisconnect(peer.getConnection(), DisconnectReason.SUBPROTOCOL_TRIGGERED, false); - } + } else if (mergePeerFilter.isPresent() + && mergePeerFilter.get().disconnectIfPoW(status, peer)) { + handleDisconnect(peer.getConnection(), DisconnectReason.SUBPROTOCOL_TRIGGERED, false); } else { LOG.debug("Received status message from {}: {}", peer, status); peer.registerStatusReceived(