From 3075049e712a725ab1d0176358a00270a34ca0e8 Mon Sep 17 00:00:00 2001 From: Roman Vaseev <4833306+Filter94@users.noreply.github.com> Date: Tue, 26 Jul 2022 21:18:09 +0300 Subject: [PATCH 01/20] Fixed desired gas limit setting in the reference tests service (#4170) Signed-off-by: Roman Vaseev <4833306+Filter94@users.noreply.github.com> Co-authored-by: Justin Florentine Signed-off-by: Sally MacFarlane --- .../besu/ethereum/retesteth/methods/TestMineBlocks.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java index 2598451d8a9..047d6225ef7 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/methods/TestMineBlocks.java @@ -64,7 +64,7 @@ private boolean mineNewBlock() { final PoWBlockCreator blockCreator = new PoWBlockCreator( context.getCoinbase(), - () -> Optional.of(10_000_000L), + () -> Optional.of(blockchain.getChainHeadHeader().getGasLimit()), header -> context.getExtraData(), context.getTransactionPool().getPendingTransactions(), protocolContext, From 9854bb3bd793c80f50a4c7c6e79ac28748687720 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 28 Jul 2022 10:33:51 +1000 Subject: [PATCH 02/20] first draft of introducing a lower bound on number of peers Signed-off-by: Sally MacFarlane --- .../org/hyperledger/besu/RunnerBuilder.java | 2 +- .../besu/cli/DefaultCommandValues.java | 2 +- .../eth/manager/EthProtocolManager.java | 8 +++++- .../p2p/config/RlpxConfiguration.java | 19 ++++++++----- .../p2p/network/DefaultP2PNetwork.java | 5 ++-- .../ethereum/p2p/network/NetworkRunner.java | 1 + .../besu/ethereum/p2p/rlpx/RlpxAgent.java | 28 +++++++++++++------ .../p2p/config/RlpxConfigurationTest.java | 8 +++--- .../ethereum/p2p/network/P2PNetworkTest.java | 2 +- .../p2p/network/P2PPlainNetworkTest.java | 2 +- .../besu/ethereum/p2p/rlpx/RlpxAgentTest.java | 4 +-- 11 files changed, 53 insertions(+), 28 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java b/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java index a21408a80d1..89118e23bc2 100644 --- a/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java @@ -444,7 +444,7 @@ public Runner build() { RlpxConfiguration.create() .setBindHost(p2pListenInterface) .setBindPort(p2pListenPort) - .setMaxPeers(maxPeers) + .setPeerUpperBound(maxPeers) .setSupportedProtocols(subProtocols) .setClientId(BesuInfo.nodeName(identityString)) .setLimitRemoteWireConnectionsEnabled(limitRemoteWireConnectionsEnabled) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java index 3b439180a99..bb52b0a44d7 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java @@ -57,7 +57,7 @@ public interface DefaultCommandValues { NatMethod DEFAULT_NAT_METHOD = NatMethod.AUTO; JwtAlgorithm DEFAULT_JWT_ALGORITHM = JwtAlgorithm.RS256; int FAST_SYNC_MIN_PEER_COUNT = 5; - int DEFAULT_MAX_PEERS = 25; + int DEFAULT_MAX_PEERS = 64; int DEFAULT_HTTP_MAX_CONNECTIONS = 80; int DEFAULT_WS_MAX_CONNECTIONS = 80; int DEFAULT_WS_MAX_FRAME_SIZE = 1024 * 1024; 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 5edcb3236d8..e5f9bbaa9f8 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 @@ -265,6 +265,8 @@ public void processMessage(final Capability cap, final Message message) { if (this.mergePeerFilter.isPresent()) { if (this.mergePeerFilter.get().disconnectIfGossipingBlocks(message, ethPeer)) { + LOG.info( + "here we are disconnecting at request from mergePeerFilter disconnectIfGossipingBlocks"); handleDisconnect(ethPeer.getConnection(), DisconnectReason.SUBPROTOCOL_TRIGGERED, false); return; } @@ -379,7 +381,11 @@ private void handleStatusMessage(final EthPeer peer, final MessageData data) { } else if (mergePeerFilter.isPresent()) { final boolean disconnected = mergePeerFilter.get().disconnectIfPoW(status, peer); if (disconnected) { - handleDisconnect(peer.getConnection(), DisconnectReason.SUBPROTOCOL_TRIGGERED, false); + LOG.info("here we are disconnecting at request from mergePeerFilter disconnectIfPoW"); + handleDisconnect( + peer.getConnection(), + DisconnectReason.SUBPROTOCOL_TRIGGERED, + false); // TODO should this be true } } else { LOG.debug("Received status message from {}: {}", peer, status); diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java index 62e7ca96a75..c74deecdce0 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java @@ -29,7 +29,8 @@ public class RlpxConfiguration { private String clientId = "TestClient/1.0.0"; private String bindHost = NetworkUtility.INADDR_ANY; private int bindPort = 30303; - private int maxPeers = 25; + private int peerUpperBound = 100; + private final int peerLowerBound = 64; private boolean limitRemoteWireConnectionsEnabled = false; private float fractionRemoteWireConnectionsAllowed = DEFAULT_FRACTION_REMOTE_CONNECTIONS_ALLOWED; private List supportedProtocols = Collections.emptyList(); @@ -70,13 +71,13 @@ public RlpxConfiguration setBindPort(final int bindPort) { return this; } - public RlpxConfiguration setMaxPeers(final int peers) { - maxPeers = peers; + public RlpxConfiguration setPeerUpperBound(final int peers) { + peerUpperBound = peers; return this; } - public int getMaxPeers() { - return maxPeers; + public int getPeerUpperBound() { + return peerUpperBound; } public String getClientId() { @@ -105,10 +106,10 @@ public RlpxConfiguration setFractionRemoteWireConnectionsAllowed( public int getMaxRemotelyInitiatedConnections() { if (!limitRemoteWireConnectionsEnabled) { - return maxPeers; + return peerUpperBound; } - return (int) Math.floor(maxPeers * fractionRemoteWireConnectionsAllowed); + return (int) Math.floor(peerUpperBound * fractionRemoteWireConnectionsAllowed); } @Override @@ -136,4 +137,8 @@ public String toString() { sb.append('}'); return sb.toString(); } + + public int getPeerLowerBound() { + return peerLowerBound; + } } diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java index afbf7872837..18b41535d9f 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java @@ -188,8 +188,9 @@ public class DefaultP2PNetwork implements P2PNetwork { this.nodeId = nodeKey.getPublicKey().getEncodedBytes(); this.peerPermissions = peerPermissions; - final int maxPeers = config.getRlpx().getMaxPeers(); - peerDiscoveryAgent.addPeerRequirement(() -> rlpxAgent.getConnectionCount() >= maxPeers); + final int peerLowerBound = config.getRlpx().getPeerLowerBound(); + LOG.info("setting peerLowerBound {}", peerLowerBound); + peerDiscoveryAgent.addPeerRequirement(() -> rlpxAgent.getConnectionCount() >= peerLowerBound); subscribeDisconnect(reputationManager); } diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/NetworkRunner.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/NetworkRunner.java index 97993092133..248937f62de 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/NetworkRunner.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/NetworkRunner.java @@ -154,6 +154,7 @@ private void setupHandlers() { connection.getAgreedCapabilities(), protocolManager.getSupportedCapabilities())) { return; } + LOG.info("network runner - disconnect peerInitiated? {}", initiatedByPeer); protocolManager.handleDisconnect(connection, disconnectReason, initiatedByPeer); }); } diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgent.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgent.java index 5691c63bdba..35fa398f9b6 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgent.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgent.java @@ -70,6 +70,7 @@ public class RlpxAgent { private final PeerRlpxPermissions peerPermissions; private final PeerPrivileges peerPrivileges; private final int maxConnections; + private final int targetMaxConnections; private final boolean randomPeerPriority; private final int maxRemotelyInitiatedConnections; // xor'ing with this mask will allow us to randomly let new peers connect @@ -99,6 +100,8 @@ private RlpxAgent( this.peerPermissions = peerPermissions; this.peerPrivileges = peerPrivileges; this.maxConnections = maxConnections; + // TODO set or compute a sensible default + this.targetMaxConnections = maxConnections > 30 ? maxConnections - 10 : maxConnections; this.randomPeerPriority = randomPeerPriority; this.maxRemotelyInitiatedConnections = Math.min(maxConnections, maxRemotelyInitiatedConnections); @@ -174,7 +177,7 @@ public void connect(final Stream peerStream) { return; } peerStream - .takeWhile(peer -> Math.max(0, maxConnections - getConnectionCount()) > 0) + .takeWhile(peer -> Math.max(0, targetMaxConnections - getConnectionCount()) > 0) .filter(peer -> !connectionsById.containsKey(peer.getId())) .filter(peer -> peer.getEnodeURL().isListening()) .filter(peerPermissions::allowNewOutboundConnectionTo) @@ -362,15 +365,20 @@ private void handleIncomingConnection(final PeerConnection peerConnection) { // Disconnect if too many peers if (!peerPrivileges.canExceedConnectionLimits(peer) && getConnectionCount() >= maxConnections) { - LOG.debug("Too many peers. Disconnect incoming connection: {}", peerConnection); + LOG.debug( + "Too many peers. Disconnect incoming connection: {} currentCount {} > max {}", + peerConnection, + getConnectionCount(), + maxConnections); peerConnection.disconnect(DisconnectReason.TOO_MANY_PEERS); return; } // Disconnect if too many remotely-initiated connections if (!peerPrivileges.canExceedConnectionLimits(peer) && remoteConnectionLimitReached()) { LOG.debug( - "Too many remotely-initiated connections. Disconnect incoming connection: {}", - peerConnection); + "Too many remotely-initiated connections. Disconnect incoming connection: {}, maxRemote={}", + peerConnection, + maxRemotelyInitiatedConnections); peerConnection.disconnect(DisconnectReason.TOO_MANY_PEERS); return; } @@ -462,8 +470,9 @@ private void enforceRemoteConnectionLimits() { .forEach( conn -> { LOG.debug( - "Too many remotely initiated connections. Disconnect low-priority connection: {}", - conn); + "Too many remotely initiated connections. Disconnect low-priority connection: {}, maxRemote={}", + conn, + maxRemotelyInitiatedConnections); conn.disconnect(DisconnectReason.TOO_MANY_PEERS); }); } @@ -479,7 +488,10 @@ private void enforceConnectionLimits() { .filter(c -> !peerPrivileges.canExceedConnectionLimits(c.getPeer())) .forEach( conn -> { - LOG.debug("Too many connections. Disconnect low-priority connection: {}", conn); + LOG.debug( + "Too many connections. Disconnect low-priority connection: {}, maxConnections={}", + conn, + maxConnections); conn.disconnect(DisconnectReason.TOO_MANY_PEERS); }); } @@ -610,7 +622,7 @@ public RlpxAgent build() { connectionInitializer, rlpxPermissions, peerPrivileges, - config.getMaxPeers(), + config.getPeerUpperBound(), config.getMaxRemotelyInitiatedConnections(), randomPeerPriority, metricsSystem); diff --git a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfigurationTest.java b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfigurationTest.java index f0a8106ff4a..5cfe0bab7d7 100644 --- a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfigurationTest.java +++ b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfigurationTest.java @@ -26,7 +26,7 @@ public void getMaxRemotelyInitiatedConnections_remoteLimitsDisabled() { RlpxConfiguration.create() .setFractionRemoteWireConnectionsAllowed(.5f) .setLimitRemoteWireConnectionsEnabled(false) - .setMaxPeers(20); + .setPeerUpperBound(20); assertThat(config.getMaxRemotelyInitiatedConnections()).isEqualTo(20); } @@ -37,7 +37,7 @@ public void getMaxRemotelyInitiatedConnections_remoteLimitsEnabled() { RlpxConfiguration.create() .setFractionRemoteWireConnectionsAllowed(.5f) .setLimitRemoteWireConnectionsEnabled(true) - .setMaxPeers(20); + .setPeerUpperBound(20); assertThat(config.getMaxRemotelyInitiatedConnections()).isEqualTo(10); } @@ -48,7 +48,7 @@ public void getMaxRemotelyInitiatedConnections_remoteLimitsEnabledWithNonInteger RlpxConfiguration.create() .setFractionRemoteWireConnectionsAllowed(.5f) .setLimitRemoteWireConnectionsEnabled(true) - .setMaxPeers(25); + .setPeerUpperBound(25); assertThat(config.getMaxRemotelyInitiatedConnections()).isEqualTo(12); } @@ -59,7 +59,7 @@ public void getMaxRemotelyInitiatedConnections_remoteLimitsEnabledRoundsToZero() RlpxConfiguration.create() .setFractionRemoteWireConnectionsAllowed(.5f) .setLimitRemoteWireConnectionsEnabled(true) - .setMaxPeers(1); + .setPeerUpperBound(1); assertThat(config.getMaxRemotelyInitiatedConnections()).isEqualTo(0); } diff --git a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/P2PNetworkTest.java b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/P2PNetworkTest.java index c5aa0193840..55d6ddb7d60 100644 --- a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/P2PNetworkTest.java +++ b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/P2PNetworkTest.java @@ -132,7 +132,7 @@ public void limitMaxPeers() throws Exception { .setRlpx( RlpxConfiguration.create() .setBindPort(0) - .setMaxPeers(maxPeers) + .setPeerUpperBound(maxPeers) .setSupportedProtocols(subProtocol())); try (final P2PNetwork listener = builder().nodeKey(nodeKey).config(listenerConfig).build(); final P2PNetwork connector1 = builder().build(); diff --git a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/P2PPlainNetworkTest.java b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/P2PPlainNetworkTest.java index 3390bc1d3f7..378b5241aac 100644 --- a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/P2PPlainNetworkTest.java +++ b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/P2PPlainNetworkTest.java @@ -143,7 +143,7 @@ public void limitMaxPeers() throws Exception { .setRlpx( RlpxConfiguration.create() .setBindPort(0) - .setMaxPeers(maxPeers) + .setPeerUpperBound(maxPeers) .setSupportedProtocols(subProtocol())); try (final P2PNetwork listener = builder("partner1client1").nodeKey(nodeKey).config(listenerConfig).build(); diff --git a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgentTest.java b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgentTest.java index 8adc5cc3505..d875bdc50b1 100644 --- a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgentTest.java +++ b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgentTest.java @@ -85,7 +85,7 @@ public class RlpxAgentTest { public void setup() { // Set basic defaults when(peerPrivileges.canExceedConnectionLimits(any())).thenReturn(false); - config.setMaxPeers(5); + config.setPeerUpperBound(5); } @Test @@ -1028,7 +1028,7 @@ private void startAgentWithMaxPeers( final int maxPeers, final Function buildCustomization, final Consumer rlpxConfigurationModifier) { - config.setMaxPeers(maxPeers); + config.setPeerUpperBound(maxPeers); agent = agent(buildCustomization, rlpxConfigurationModifier); startAgent(); } From 7b11607021d7e40f3d890e390761c9e9659ae16f Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 28 Jul 2022 11:09:20 +1000 Subject: [PATCH 03/20] added lower bound CLI option Signed-off-by: Sally MacFarlane --- .../java/org/hyperledger/besu/RunnerBuilder.java | 7 +++++++ .../java/org/hyperledger/besu/cli/BesuCommand.java | 13 ++++++++++++- .../hyperledger/besu/cli/DefaultCommandValues.java | 3 ++- .../besu/ethereum/p2p/config/RlpxConfiguration.java | 7 ++++++- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java b/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java index 89118e23bc2..de058ab7d60 100644 --- a/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java @@ -165,6 +165,7 @@ public class RunnerBuilder { private String natManagerServiceName; private boolean natMethodFallbackEnabled; private int maxPeers; + private int peerLowerBound; private boolean limitRemoteWireConnectionsEnabled = false; private float fractionRemoteConnectionsAllowed; private EthNetworkConfig ethNetworkConfig; @@ -271,6 +272,11 @@ public RunnerBuilder maxPeers(final int maxPeers) { return this; } + public RunnerBuilder peerLowerBound(final int peerLowerBound) { + this.peerLowerBound = peerLowerBound; + return this; + } + public RunnerBuilder limitRemoteWireConnectionsEnabled( final boolean limitRemoteWireConnectionsEnabled) { this.limitRemoteWireConnectionsEnabled = limitRemoteWireConnectionsEnabled; @@ -445,6 +451,7 @@ public Runner build() { .setBindHost(p2pListenInterface) .setBindPort(p2pListenPort) .setPeerUpperBound(maxPeers) + .setPeerLowerBound(peerLowerBound) .setSupportedProtocols(subProtocols) .setClientId(BesuInfo.nodeName(identityString)) .setLimitRemoteWireConnectionsEnabled(limitRemoteWireConnectionsEnabled) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index ce53d8cdb43..09c4788161f 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -424,11 +424,19 @@ static class P2PDiscoveryOptionGroup { private final Integer p2pPort = EnodeURLImpl.DEFAULT_LISTENING_PORT; @Option( - names = {"--max-peers"}, + names = {"--max-peers", "--p2p-peer-upper-bound"}, paramLabel = MANDATORY_INTEGER_FORMAT_HELP, description = "Maximum P2P connections that can be established (default: ${DEFAULT-VALUE})") private final Integer maxPeers = DEFAULT_MAX_PEERS; + // TODO make this a hidden experimental option + @Option( + names = {"--p2p-peer-lower-bound"}, + paramLabel = MANDATORY_INTEGER_FORMAT_HELP, + description = + "Lower bound on the target number of P2P connections (default: ${DEFAULT-VALUE})") + private final Integer peerLowerBound = DEFAULT_PEER_LOWER_BOUND; + @Option( names = {"--remote-connections-limit-enabled"}, description = @@ -1599,6 +1607,7 @@ private Runner buildRunner() { p2PDiscoveryOptionGroup.peerDiscoveryEnabled, ethNetworkConfig, p2PDiscoveryOptionGroup.maxPeers, + p2PDiscoveryOptionGroup.peerLowerBound, p2PDiscoveryOptionGroup.p2pHost, p2PDiscoveryOptionGroup.p2pInterface, p2PDiscoveryOptionGroup.p2pPort, @@ -2774,6 +2783,7 @@ private Runner synchronize( final boolean peerDiscoveryEnabled, final EthNetworkConfig ethNetworkConfig, final int maxPeers, + final int peerLowerBound, final String p2pAdvertisedHost, final String p2pListenInterface, final int p2pListenPort, @@ -2808,6 +2818,7 @@ private Runner synchronize( .p2pListenInterface(p2pListenInterface) .p2pListenPort(p2pListenPort) .maxPeers(maxPeers) + .peerLowerBound(peerLowerBound) .limitRemoteWireConnectionsEnabled( p2PDiscoveryOptionGroup.isLimitRemoteWireConnectionsEnabled) .fractionRemoteConnectionsAllowed( diff --git a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java index bb52b0a44d7..c626126df3c 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java @@ -57,7 +57,8 @@ public interface DefaultCommandValues { NatMethod DEFAULT_NAT_METHOD = NatMethod.AUTO; JwtAlgorithm DEFAULT_JWT_ALGORITHM = JwtAlgorithm.RS256; int FAST_SYNC_MIN_PEER_COUNT = 5; - int DEFAULT_MAX_PEERS = 64; + int DEFAULT_MAX_PEERS = 100; + int DEFAULT_PEER_LOWER_BOUND = 64; int DEFAULT_HTTP_MAX_CONNECTIONS = 80; int DEFAULT_WS_MAX_CONNECTIONS = 80; int DEFAULT_WS_MAX_FRAME_SIZE = 1024 * 1024; diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java index c74deecdce0..facf2771170 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java @@ -30,7 +30,7 @@ public class RlpxConfiguration { private String bindHost = NetworkUtility.INADDR_ANY; private int bindPort = 30303; private int peerUpperBound = 100; - private final int peerLowerBound = 64; + private int peerLowerBound = 64; private boolean limitRemoteWireConnectionsEnabled = false; private float fractionRemoteWireConnectionsAllowed = DEFAULT_FRACTION_REMOTE_CONNECTIONS_ALLOWED; private List supportedProtocols = Collections.emptyList(); @@ -138,6 +138,11 @@ public String toString() { return sb.toString(); } + public RlpxConfiguration setPeerLowerBound(final int peers) { + peerLowerBound = peers; + return this; + } + public int getPeerLowerBound() { return peerLowerBound; } From 59a7feab4049c100c30c2bd07e2530499cc2c783 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Fri, 29 Jul 2022 10:19:34 +1000 Subject: [PATCH 04/20] change default values back to current defaults Signed-off-by: Sally MacFarlane --- .../java/org/hyperledger/besu/cli/DefaultCommandValues.java | 4 ++-- .../besu/ethereum/p2p/config/RlpxConfiguration.java | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java index c626126df3c..60b6c7f84fb 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java @@ -57,8 +57,8 @@ public interface DefaultCommandValues { NatMethod DEFAULT_NAT_METHOD = NatMethod.AUTO; JwtAlgorithm DEFAULT_JWT_ALGORITHM = JwtAlgorithm.RS256; int FAST_SYNC_MIN_PEER_COUNT = 5; - int DEFAULT_MAX_PEERS = 100; - int DEFAULT_PEER_LOWER_BOUND = 64; + int DEFAULT_MAX_PEERS = 25; + int DEFAULT_PEER_LOWER_BOUND = 20; int DEFAULT_HTTP_MAX_CONNECTIONS = 80; int DEFAULT_WS_MAX_CONNECTIONS = 80; int DEFAULT_WS_MAX_FRAME_SIZE = 1024 * 1024; diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java index facf2771170..23282573c6a 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java @@ -73,6 +73,7 @@ public RlpxConfiguration setBindPort(final int bindPort) { public RlpxConfiguration setPeerUpperBound(final int peers) { peerUpperBound = peers; + // TODO if lower bound not explicitly set what is a sensible default return this; } From 3c1003f994f11db83c9f866ba7e207c57c65624d Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Mon, 1 Aug 2022 09:08:21 +1000 Subject: [PATCH 05/20] hidden CLI option Signed-off-by: Sally MacFarlane --- .../org/hyperledger/besu/cli/BesuCommand.java | 3 +- .../p2p/config/RlpxConfiguration.java | 2 +- .../p2p/network/DefaultP2PNetwork.java | 1 + .../besu/ethereum/p2p/rlpx/RlpxAgent.java | 35 ++++++++++--------- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index 5d0ebe7140d..a4c32bd3202 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -431,7 +431,8 @@ static class P2PDiscoveryOptionGroup { // TODO make this a hidden experimental option @Option( - names = {"--p2p-peer-lower-bound"}, + hidden = true, + names = {"--Xp2p-peer-lower-bound"}, paramLabel = MANDATORY_INTEGER_FORMAT_HELP, description = "Lower bound on the target number of P2P connections (default: ${DEFAULT-VALUE})") diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java index 23282573c6a..d4577859cd4 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java @@ -73,7 +73,6 @@ public RlpxConfiguration setBindPort(final int bindPort) { public RlpxConfiguration setPeerUpperBound(final int peers) { peerUpperBound = peers; - // TODO if lower bound not explicitly set what is a sensible default return this; } @@ -145,6 +144,7 @@ public RlpxConfiguration setPeerLowerBound(final int peers) { } public int getPeerLowerBound() { + // TODO if lower bound not explicitly set what is a sensible default return peerLowerBound; } } diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java index 18b41535d9f..faf1000abe4 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java @@ -188,6 +188,7 @@ public class DefaultP2PNetwork implements P2PNetwork { this.nodeId = nodeKey.getPublicKey().getEncodedBytes(); this.peerPermissions = peerPermissions; + // set the requirement here that the number of peers be greater than the lower bound final int peerLowerBound = config.getRlpx().getPeerLowerBound(); LOG.info("setting peerLowerBound {}", peerLowerBound); peerDiscoveryAgent.addPeerRequirement(() -> rlpxAgent.getConnectionCount() >= peerLowerBound); diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgent.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgent.java index 35fa398f9b6..1fac27158e6 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgent.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgent.java @@ -69,8 +69,8 @@ public class RlpxAgent { private final PeerRlpxPermissions peerPermissions; private final PeerPrivileges peerPrivileges; - private final int maxConnections; - private final int targetMaxConnections; + private final int upperBoundConnections; + private final int lowerBoundConnections; private final boolean randomPeerPriority; private final int maxRemotelyInitiatedConnections; // xor'ing with this mask will allow us to randomly let new peers connect @@ -90,7 +90,8 @@ private RlpxAgent( final ConnectionInitializer connectionInitializer, final PeerRlpxPermissions peerPermissions, final PeerPrivileges peerPrivileges, - final int maxConnections, + final int upperBoundConnections, + final int lowerBoundConnections, final int maxRemotelyInitiatedConnections, final boolean randomPeerPriority, final MetricsSystem metricsSystem) { @@ -99,12 +100,11 @@ private RlpxAgent( this.connectionInitializer = connectionInitializer; this.peerPermissions = peerPermissions; this.peerPrivileges = peerPrivileges; - this.maxConnections = maxConnections; - // TODO set or compute a sensible default - this.targetMaxConnections = maxConnections > 30 ? maxConnections - 10 : maxConnections; + this.upperBoundConnections = upperBoundConnections; + this.lowerBoundConnections = lowerBoundConnections; this.randomPeerPriority = randomPeerPriority; this.maxRemotelyInitiatedConnections = - Math.min(maxConnections, maxRemotelyInitiatedConnections); + Math.min(upperBoundConnections, maxRemotelyInitiatedConnections); // Setup metrics connectedPeersCounter = @@ -120,7 +120,7 @@ private RlpxAgent( BesuMetricCategory.ETHEREUM, "peer_limit", "The maximum number of peers this node allows to connect", - () -> maxConnections); + () -> upperBoundConnections); } public static Builder builder() { @@ -177,7 +177,7 @@ public void connect(final Stream peerStream) { return; } peerStream - .takeWhile(peer -> Math.max(0, targetMaxConnections - getConnectionCount()) > 0) + .takeWhile(peer -> Math.max(0, lowerBoundConnections - getConnectionCount()) > 0) .filter(peer -> !connectionsById.containsKey(peer.getId())) .filter(peer -> peer.getEnodeURL().isListening()) .filter(peerPermissions::allowNewOutboundConnectionTo) @@ -237,10 +237,10 @@ public CompletableFuture connect(final Peer peer) { return peerConnection.get(); } // Check max peers - if (!peerPrivileges.canExceedConnectionLimits(peer) && getConnectionCount() >= maxConnections) { + if (!peerPrivileges.canExceedConnectionLimits(peer) && getConnectionCount() >= upperBoundConnections) { final String errorMsg = "Max peer connections established (" - + maxConnections + + upperBoundConnections + "). Cannot connect to peer: " + peer; return CompletableFuture.failedFuture(new IllegalStateException(errorMsg)); @@ -364,12 +364,12 @@ private void handleIncomingConnection(final PeerConnection peerConnection) { if (!randomPeerPriority) { // Disconnect if too many peers if (!peerPrivileges.canExceedConnectionLimits(peer) - && getConnectionCount() >= maxConnections) { + && getConnectionCount() >= upperBoundConnections) { LOG.debug( "Too many peers. Disconnect incoming connection: {} currentCount {} > max {}", peerConnection, getConnectionCount(), - maxConnections); + upperBoundConnections); peerConnection.disconnect(DisconnectReason.TOO_MANY_PEERS); return; } @@ -440,7 +440,7 @@ && getConnectionCount() >= maxConnections) { } private boolean shouldLimitRemoteConnections() { - return maxRemotelyInitiatedConnections < maxConnections; + return maxRemotelyInitiatedConnections < upperBoundConnections; } private boolean remoteConnectionLimitReached() { @@ -478,20 +478,20 @@ private void enforceRemoteConnectionLimits() { } private void enforceConnectionLimits() { - if (connectionsById.size() < maxConnections) { + if (connectionsById.size() < upperBoundConnections) { // Nothing to do - we're under our limits return; } getActivePrioritizedConnections() - .skip(maxConnections) + .skip(upperBoundConnections) .filter(c -> !peerPrivileges.canExceedConnectionLimits(c.getPeer())) .forEach( conn -> { LOG.debug( "Too many connections. Disconnect low-priority connection: {}, maxConnections={}", conn, - maxConnections); + upperBoundConnections); conn.disconnect(DisconnectReason.TOO_MANY_PEERS); }); } @@ -623,6 +623,7 @@ public RlpxAgent build() { rlpxPermissions, peerPrivileges, config.getPeerUpperBound(), + config.getPeerLowerBound(), config.getMaxRemotelyInitiatedConnections(), randomPeerPriority, metricsSystem); From 40bd6ff0c134d1760b596ded0e541e1a2f29ed4a Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Mon, 1 Aug 2022 09:13:01 +1000 Subject: [PATCH 06/20] formatting Signed-off-by: Sally MacFarlane --- .../main/java/org/hyperledger/besu/cli/BesuCommand.java | 2 +- .../org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgent.java | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index a4c32bd3202..63452e27618 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -431,7 +431,7 @@ static class P2PDiscoveryOptionGroup { // TODO make this a hidden experimental option @Option( - hidden = true, + hidden = true, names = {"--Xp2p-peer-lower-bound"}, paramLabel = MANDATORY_INTEGER_FORMAT_HELP, description = diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgent.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgent.java index 1fac27158e6..45ae000f6e2 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgent.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgent.java @@ -237,7 +237,8 @@ public CompletableFuture connect(final Peer peer) { return peerConnection.get(); } // Check max peers - if (!peerPrivileges.canExceedConnectionLimits(peer) && getConnectionCount() >= upperBoundConnections) { + if (!peerPrivileges.canExceedConnectionLimits(peer) + && getConnectionCount() >= upperBoundConnections) { final String errorMsg = "Max peer connections established (" + upperBoundConnections @@ -369,7 +370,7 @@ && getConnectionCount() >= upperBoundConnections) { "Too many peers. Disconnect incoming connection: {} currentCount {} > max {}", peerConnection, getConnectionCount(), - upperBoundConnections); + upperBoundConnections); peerConnection.disconnect(DisconnectReason.TOO_MANY_PEERS); return; } @@ -491,7 +492,7 @@ private void enforceConnectionLimits() { LOG.debug( "Too many connections. Disconnect low-priority connection: {}, maxConnections={}", conn, - upperBoundConnections); + upperBoundConnections); conn.disconnect(DisconnectReason.TOO_MANY_PEERS); }); } From 8a1da6e31aa4129d054c95b852d7de753e444263 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Mon, 1 Aug 2022 10:28:55 +1000 Subject: [PATCH 07/20] add test Signed-off-by: Sally MacFarlane --- .../org/hyperledger/besu/RunnerBuilder.java | 8 +----- .../org/hyperledger/besu/cli/BesuCommand.java | 12 --------- .../besu/cli/DefaultCommandValues.java | 2 +- .../options/unstable/NetworkingOptions.java | 10 +++++++ .../cli/options/NetworkingOptionsTest.java | 26 +++++++++++++++++++ 5 files changed, 38 insertions(+), 20 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java b/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java index 1c5cebafa8f..2841336addf 100644 --- a/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java @@ -165,7 +165,6 @@ public class RunnerBuilder { private String natManagerServiceName; private boolean natMethodFallbackEnabled; private int maxPeers; - private int peerLowerBound; private boolean limitRemoteWireConnectionsEnabled = false; private float fractionRemoteConnectionsAllowed; private EthNetworkConfig ethNetworkConfig; @@ -272,11 +271,6 @@ public RunnerBuilder maxPeers(final int maxPeers) { return this; } - public RunnerBuilder peerLowerBound(final int peerLowerBound) { - this.peerLowerBound = peerLowerBound; - return this; - } - public RunnerBuilder limitRemoteWireConnectionsEnabled( final boolean limitRemoteWireConnectionsEnabled) { this.limitRemoteWireConnectionsEnabled = limitRemoteWireConnectionsEnabled; @@ -451,7 +445,7 @@ public Runner build() { .setBindHost(p2pListenInterface) .setBindPort(p2pListenPort) .setPeerUpperBound(maxPeers) - .setPeerLowerBound(peerLowerBound) + .setPeerLowerBound(networkingConfiguration.getRlpx().getPeerLowerBound()) .setSupportedProtocols(subProtocols) .setClientId(BesuInfo.nodeName(identityString)) .setLimitRemoteWireConnectionsEnabled(limitRemoteWireConnectionsEnabled) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index 63452e27618..c0cb23c6a7d 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -429,15 +429,6 @@ static class P2PDiscoveryOptionGroup { description = "Maximum P2P connections that can be established (default: ${DEFAULT-VALUE})") private final Integer maxPeers = DEFAULT_MAX_PEERS; - // TODO make this a hidden experimental option - @Option( - hidden = true, - names = {"--Xp2p-peer-lower-bound"}, - paramLabel = MANDATORY_INTEGER_FORMAT_HELP, - description = - "Lower bound on the target number of P2P connections (default: ${DEFAULT-VALUE})") - private final Integer peerLowerBound = DEFAULT_PEER_LOWER_BOUND; - @Option( names = {"--remote-connections-limit-enabled"}, description = @@ -1611,7 +1602,6 @@ private Runner buildRunner() { p2PDiscoveryOptionGroup.peerDiscoveryEnabled, ethNetworkConfig, p2PDiscoveryOptionGroup.maxPeers, - p2PDiscoveryOptionGroup.peerLowerBound, p2PDiscoveryOptionGroup.p2pHost, p2PDiscoveryOptionGroup.p2pInterface, p2PDiscoveryOptionGroup.p2pPort, @@ -2784,7 +2774,6 @@ private Runner synchronize( final boolean peerDiscoveryEnabled, final EthNetworkConfig ethNetworkConfig, final int maxPeers, - final int peerLowerBound, final String p2pAdvertisedHost, final String p2pListenInterface, final int p2pListenPort, @@ -2819,7 +2808,6 @@ private Runner synchronize( .p2pListenInterface(p2pListenInterface) .p2pListenPort(p2pListenPort) .maxPeers(maxPeers) - .peerLowerBound(peerLowerBound) .limitRemoteWireConnectionsEnabled( p2PDiscoveryOptionGroup.isLimitRemoteWireConnectionsEnabled) .fractionRemoteConnectionsAllowed( diff --git a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java index 60b6c7f84fb..832d00b3fd1 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java @@ -58,7 +58,7 @@ public interface DefaultCommandValues { JwtAlgorithm DEFAULT_JWT_ALGORITHM = JwtAlgorithm.RS256; int FAST_SYNC_MIN_PEER_COUNT = 5; int DEFAULT_MAX_PEERS = 25; - int DEFAULT_PEER_LOWER_BOUND = 20; + int DEFAULT_P2P_PEER_LOWER_BOUND = 20; int DEFAULT_HTTP_MAX_CONNECTIONS = 80; int DEFAULT_WS_MAX_CONNECTIONS = 80; int DEFAULT_WS_MAX_FRAME_SIZE = 1024 * 1024; diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NetworkingOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NetworkingOptions.java index bb0045d612f..3608ba039e4 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NetworkingOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NetworkingOptions.java @@ -31,6 +31,8 @@ public class NetworkingOptions implements CLIOptions { "--Xp2p-check-maintained-connections-frequency"; private final String DNS_DISCOVERY_SERVER_OVERRIDE_FLAG = "--Xp2p-dns-discovery-server"; private final String DISCOVERY_PROTOCOL_V5_ENABLED = "--Xv5-discovery-enabled"; + public final int DEFAULT_PEER_LOWER_BOUND = 50; + private final String P2P_PEER_LOWER_BOUND_FLAG = "--Xp2p-peer-lower-bound"; @CommandLine.Option( names = INITIATE_CONNECTIONS_FREQUENCY_FLAG, @@ -66,6 +68,13 @@ public class NetworkingOptions implements CLIOptions { description = "Whether to enable P2P Discovery Protocol v5 (default: ${DEFAULT-VALUE})") private final Boolean isPeerDiscoveryV5Enabled = false; + @CommandLine.Option( + hidden = true, + names = {P2P_PEER_LOWER_BOUND_FLAG}, + description = + "Lower bound on the target number of P2P connections (default: ${DEFAULT-VALUE})") + private final Integer peerLowerBound = DEFAULT_PEER_LOWER_BOUND; + private NetworkingOptions() {} public static NetworkingOptions create() { @@ -90,6 +99,7 @@ public NetworkingConfiguration toDomainObject() { config.setInitiateConnectionsFrequency(initiateConnectionsFrequencySec); config.setDnsDiscoveryServerOverride(dnsDiscoveryServerOverride); config.getDiscovery().setDiscoveryV5Enabled(isPeerDiscoveryV5Enabled); + config.getRlpx().setPeerLowerBound(peerLowerBound); return config; } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java index 330bbc524a1..c1ce5f2b24a 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java @@ -16,6 +16,7 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; +import static org.hyperledger.besu.cli.DefaultCommandValues.DEFAULT_P2P_PEER_LOWER_BOUND; import org.hyperledger.besu.cli.options.unstable.NetworkingOptions; import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration; @@ -125,6 +126,31 @@ public void checkDiscoveryV5Enabled_isNotSet() { assertThat(commandOutput.toString(UTF_8)).isEmpty(); } + @Test + public void checkP2pPeerLowerBound_isSet() { + final int lowerBound = 13; + final TestBesuCommand cmd = parseCommand("--Xp2p-peer-lower-bound", String.valueOf(lowerBound)); + + final NetworkingOptions options = cmd.getNetworkingOptions(); + final NetworkingConfiguration networkingConfig = options.toDomainObject(); + assertThat(networkingConfig.getRlpx().getPeerLowerBound()).isEqualTo(lowerBound); + + assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); + assertThat(commandOutput.toString(UTF_8)).isEmpty(); + } + + @Test + public void checkP2pPeerLowerBound_isNotSet() { + final TestBesuCommand cmd = parseCommand(); + + final NetworkingOptions options = cmd.getNetworkingOptions(); + final NetworkingConfiguration networkingConfig = options.toDomainObject(); + assertThat(networkingConfig.getRlpx().getPeerLowerBound()).isEqualTo(DEFAULT_P2P_PEER_LOWER_BOUND); + + assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); + assertThat(commandOutput.toString(UTF_8)).isEmpty(); + } + @Override NetworkingConfiguration createDefaultDomainObject() { return NetworkingConfiguration.create(); From e4265524d47262870cc5813f721e6fb900fc3fa6 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Mon, 1 Aug 2022 10:49:19 +1000 Subject: [PATCH 08/20] test Signed-off-by: Sally MacFarlane --- .../besu/cli/options/unstable/NetworkingOptions.java | 12 ++++++------ .../besu/cli/options/NetworkingOptionsTest.java | 3 ++- .../besu/ethereum/p2p/config/RlpxConfiguration.java | 3 +-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NetworkingOptions.java b/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NetworkingOptions.java index 3608ba039e4..bc8629c9b12 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NetworkingOptions.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/options/unstable/NetworkingOptions.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.cli.options.unstable; +import org.hyperledger.besu.cli.DefaultCommandValues; import org.hyperledger.besu.cli.options.CLIOptions; import org.hyperledger.besu.cli.options.OptionParser; import org.hyperledger.besu.ethereum.p2p.config.NetworkingConfiguration; @@ -31,7 +32,6 @@ public class NetworkingOptions implements CLIOptions { "--Xp2p-check-maintained-connections-frequency"; private final String DNS_DISCOVERY_SERVER_OVERRIDE_FLAG = "--Xp2p-dns-discovery-server"; private final String DISCOVERY_PROTOCOL_V5_ENABLED = "--Xv5-discovery-enabled"; - public final int DEFAULT_PEER_LOWER_BOUND = 50; private final String P2P_PEER_LOWER_BOUND_FLAG = "--Xp2p-peer-lower-bound"; @CommandLine.Option( @@ -69,11 +69,11 @@ public class NetworkingOptions implements CLIOptions { private final Boolean isPeerDiscoveryV5Enabled = false; @CommandLine.Option( - hidden = true, - names = {P2P_PEER_LOWER_BOUND_FLAG}, - description = - "Lower bound on the target number of P2P connections (default: ${DEFAULT-VALUE})") - private final Integer peerLowerBound = DEFAULT_PEER_LOWER_BOUND; + hidden = true, + names = {P2P_PEER_LOWER_BOUND_FLAG}, + description = + "Lower bound on the target number of P2P connections (default: ${DEFAULT-VALUE})") + private final Integer peerLowerBound = DefaultCommandValues.DEFAULT_P2P_PEER_LOWER_BOUND; private NetworkingOptions() {} diff --git a/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java b/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java index c1ce5f2b24a..5c7c5d4a079 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/options/NetworkingOptionsTest.java @@ -145,7 +145,8 @@ public void checkP2pPeerLowerBound_isNotSet() { final NetworkingOptions options = cmd.getNetworkingOptions(); final NetworkingConfiguration networkingConfig = options.toDomainObject(); - assertThat(networkingConfig.getRlpx().getPeerLowerBound()).isEqualTo(DEFAULT_P2P_PEER_LOWER_BOUND); + assertThat(networkingConfig.getRlpx().getPeerLowerBound()) + .isEqualTo(DEFAULT_P2P_PEER_LOWER_BOUND); assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); assertThat(commandOutput.toString(UTF_8)).isEmpty(); diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java index d4577859cd4..4546d033e3f 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java @@ -29,7 +29,7 @@ public class RlpxConfiguration { private String clientId = "TestClient/1.0.0"; private String bindHost = NetworkUtility.INADDR_ANY; private int bindPort = 30303; - private int peerUpperBound = 100; + private int peerUpperBound = 100; // TODO copied Teku's defaults private int peerLowerBound = 64; private boolean limitRemoteWireConnectionsEnabled = false; private float fractionRemoteWireConnectionsAllowed = DEFAULT_FRACTION_REMOTE_CONNECTIONS_ALLOWED; @@ -144,7 +144,6 @@ public RlpxConfiguration setPeerLowerBound(final int peers) { } public int getPeerLowerBound() { - // TODO if lower bound not explicitly set what is a sensible default return peerLowerBound; } } From 9ce3374d429c49c71e81113e4dd8b7c6784a5b6b Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Mon, 1 Aug 2022 12:12:22 +1000 Subject: [PATCH 09/20] added rlpx test Signed-off-by: Sally MacFarlane --- .../besu/ethereum/p2p/rlpx/RlpxAgentTest.java | 66 ++++++++++++------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgentTest.java b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgentTest.java index d875bdc50b1..a9e9eaed459 100644 --- a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgentTest.java +++ b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgentTest.java @@ -283,7 +283,7 @@ public void incomingConnection_deduplicatedWhenAlreadyConnected_peerWithLowerVal @Test public void connect_failsWhenMaxPeersConnected() { // Saturate connections - startAgentWithMaxPeers(1); + startAgentWithLowerBoundPeers(1); agent.connect(createPeer()); final Peer peer = createPeer(); @@ -303,7 +303,7 @@ public void connect_failsWhenMaxPeersConnected() { public void incomingConnection_maxPeersExceeded() throws ExecutionException, InterruptedException { // Saturate connections - startAgentWithMaxPeers(1); + startAgentWithLowerBoundPeers(1); final Peer existingPeer = createPeer(); final PeerConnection existingConnection = agent.connect(existingPeer).get(); // Sanity check @@ -329,7 +329,8 @@ public void incomingConnection_maxPeersExceeded() public void incomingConnection_succeedsEventuallyWithRandomPeerPrioritization() { // Saturate connections with one local and one remote final int maxPeers = 25; - startAgentWithMaxPeers( + startAgentWithLowerBoundPeers( + maxPeers, maxPeers, builder -> builder.randomPeerPriority(true), rlpxConfiguration -> rlpxConfiguration.setLimitRemoteWireConnectionsEnabled(false)); @@ -374,7 +375,7 @@ public void incomingConnection_afterMaxRemotelyInitiatedConnectionsHaveBeenEstab final float maxRemotePeersFraction = (float) maxRemotePeers / (float) maxPeers; config.setLimitRemoteWireConnectionsEnabled(true); config.setFractionRemoteWireConnectionsAllowed(maxRemotePeersFraction); - startAgentWithMaxPeers(maxPeers); + startAgentWithLowerBoundPeers(maxPeers); // Connect max remote peers for (int i = 0; i < maxRemotePeers; i++) { @@ -398,7 +399,7 @@ public void connect_afterMaxRemotelyInitiatedConnectionsHaveBeenEstablished() { final float maxRemotePeersFraction = (float) maxRemotePeers / (float) maxPeers; config.setLimitRemoteWireConnectionsEnabled(true); config.setFractionRemoteWireConnectionsAllowed(maxRemotePeersFraction); - startAgentWithMaxPeers(maxPeers); + startAgentWithLowerBoundPeers(maxPeers); // Connect max remote peers for (int i = 0; i < maxRemotePeers; i++) { @@ -424,7 +425,7 @@ public void incomingConnection_withMaxRemotelyInitiatedConnectionsAt100Percent() final float maxRemotePeersFraction = 1.0f; config.setLimitRemoteWireConnectionsEnabled(true); config.setFractionRemoteWireConnectionsAllowed(maxRemotePeersFraction); - startAgentWithMaxPeers(maxPeers); + startAgentWithLowerBoundPeers(maxPeers); // Connect max remote peers for (int i = 0; i < maxPeers; i++) { @@ -441,7 +442,7 @@ public void connect_withMaxRemotelyInitiatedConnectionsAt100Percent() { final float maxRemotePeersFraction = 1.0f; config.setLimitRemoteWireConnectionsEnabled(true); config.setFractionRemoteWireConnectionsAllowed(maxRemotePeersFraction); - startAgentWithMaxPeers(maxPeers); + startAgentWithLowerBoundPeers(maxPeers); // Connect max peers locally for (int i = 0; i < maxPeers; i++) { @@ -459,7 +460,7 @@ public void incomingConnection_withMaxRemotelyInitiatedConnectionsAtZeroPercent( final float maxRemotePeersFraction = 0.0f; config.setLimitRemoteWireConnectionsEnabled(true); config.setFractionRemoteWireConnectionsAllowed(maxRemotePeersFraction); - startAgentWithMaxPeers(maxPeers); + startAgentWithLowerBoundPeers(maxPeers); // First remote connection should be rejected final Peer remotelyInitiatedPeer = createPeer(); @@ -474,7 +475,7 @@ public void connect_withMaxRemotelyInitiatedConnectionsAtZeroPercent() { final float maxRemotePeersFraction = 0.0f; config.setLimitRemoteWireConnectionsEnabled(true); config.setFractionRemoteWireConnectionsAllowed(maxRemotePeersFraction); - startAgentWithMaxPeers(maxPeers); + startAgentWithLowerBoundPeers(maxPeers); // Connect max local peers for (int i = 0; i < maxPeers; i++) { @@ -493,7 +494,7 @@ public void incomingConnection_succeedsForPrivilegedPeerWhenMaxRemoteConnections final float maxRemotePeersFraction = (float) maxRemotePeers / (float) maxPeers; config.setLimitRemoteWireConnectionsEnabled(true); config.setFractionRemoteWireConnectionsAllowed(maxRemotePeersFraction); - startAgentWithMaxPeers(maxPeers); + startAgentWithLowerBoundPeers(maxPeers); // Connect max remote peers for (int i = 0; i < maxRemotePeers; i++) { @@ -530,7 +531,7 @@ public void connect_succeedsForExemptPeerWhenMaxPeersConnected() connectionInitializer.setAutocompleteConnections(false); // Saturate connections - startAgentWithMaxPeers(1); + startAgentWithLowerBoundPeers(1); final CompletableFuture existingConnectionFuture = agent.connect(createPeer()); connectionInitializer.completePendingFutures(); final MockPeerConnection existingConnection = @@ -557,7 +558,7 @@ public void connect_succeedsForExemptPeerWhenMaxExemptPeersConnected() { // successfully added to the internal connections set. This mimics async production behavior. connectionInitializer.setAutocompleteConnections(false); - startAgentWithMaxPeers(1); + startAgentWithLowerBoundPeers(1); final Peer peerA = createPeer(); final Peer peerB = createPeer(); when(peerPrivileges.canExceedConnectionLimits(peerA)).thenReturn(true); @@ -588,7 +589,7 @@ public void incomingConnection_maxPeersExceeded_incomingConnectionExemptFromLimi when(peerPrivileges.canExceedConnectionLimits(peerB)).thenReturn(true); // Saturate connections - startAgentWithMaxPeers(1); + startAgentWithLowerBoundPeers(1); // Add existing peer final MockPeerConnection existingConnection = (MockPeerConnection) agent.connect(peerA).get(); @@ -615,7 +616,7 @@ public void incomingConnection_maxPeersExceeded_existingConnectionExemptFromLimi when(peerPrivileges.canExceedConnectionLimits(peerA)).thenReturn(true); // Saturate connections - startAgentWithMaxPeers(1); + startAgentWithLowerBoundPeers(1); // Add existing peer final PeerConnection existingConnection = agent.connect(peerA).get(); @@ -643,7 +644,7 @@ public void incomingConnection_maxPeersExceeded_allConnectionsExemptFromLimits() when(peerPrivileges.canExceedConnectionLimits(peerB)).thenReturn(true); // Saturate connections - startAgentWithMaxPeers(1); + startAgentWithLowerBoundPeers(1); // Add existing peer final CompletableFuture existingConnection = agent.connect(peerA); @@ -702,7 +703,7 @@ public void connect_largeStreamOfPeers() { final int maxPeers = 5; final Stream peerStream = Stream.generate(PeerTestHelper::createPeer).limit(20); - startAgentWithMaxPeers(maxPeers); + startAgentWithLowerBoundPeers(maxPeers); agent = spy(agent); agent.connect(peerStream); @@ -711,6 +712,20 @@ public void connect_largeStreamOfPeers() { verify(agent, times(maxPeers)).connect(any(Peer.class)); } + @Test + public void connect_largeStreamOfPeersWithMinAndMaxPeers() { + final int minPeers = 5; + final Stream peerStream = Stream.generate(PeerTestHelper::createPeer).limit(20); + + startAgentWithLowerBoundPeers(minPeers, minPeers + 5); + agent = spy(agent); + agent.connect(peerStream); + + assertThat(agent.getConnectionCount()).isEqualTo(minPeers); + // Check that stream was not fully iterated + verify(agent, times(minPeers)).connect(any(Peer.class)); + } + @Test public void connect_largeStreamOfPeersFirstFewImpostors() { final int maxPeers = 5; @@ -718,7 +733,7 @@ public void connect_largeStreamOfPeersFirstFewImpostors() { connectionInitializer.setAutoDisconnectCounter(impostorsCount); final Stream peerStream = Stream.generate(PeerTestHelper::createPeer).limit(20); - startAgentWithMaxPeers(maxPeers); + startAgentWithLowerBoundPeers(maxPeers); agent = spy(agent); agent.connect(peerStream); @@ -1020,15 +1035,22 @@ private void startAgent() { startAgent(Peer.randomId()); } - private void startAgentWithMaxPeers(final int maxPeers) { - startAgentWithMaxPeers(maxPeers, Function.identity(), __ -> {}); + private void startAgentWithLowerBoundPeers(final int lowerBound, final int upperBound) { + startAgentWithLowerBoundPeers(lowerBound, upperBound, Function.identity(), __ -> {}); + } + + private void startAgentWithLowerBoundPeers(final int lowerBound) { + // TODO add upperBound param + startAgentWithLowerBoundPeers(lowerBound, lowerBound, Function.identity(), __ -> {}); } - private void startAgentWithMaxPeers( - final int maxPeers, + private void startAgentWithLowerBoundPeers( + final int lowerBound, + final int upperBound, final Function buildCustomization, final Consumer rlpxConfigurationModifier) { - config.setPeerUpperBound(maxPeers); + config.setPeerLowerBound(lowerBound); + config.setPeerUpperBound(upperBound); agent = agent(buildCustomization, rlpxConfigurationModifier); startAgent(); } From 2fa135c717a95cb417451bdd97371f336b3723a1 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Mon, 1 Aug 2022 12:25:49 +1000 Subject: [PATCH 10/20] changelog Signed-off-by: Sally MacFarlane --- CHANGELOG.md | 6 ++++++ .../besu/ethereum/eth/manager/EthProtocolManager.java | 5 +---- .../hyperledger/besu/ethereum/p2p/rlpx/RlpxAgentTest.java | 1 - 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c165eae6b8b..554d1d786ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog + +## 22.7.1 + +### Additions and Improvements +- Experimental CLI option for --Xp2p-peer-lower-bound [#4200](https://github.com/hyperledger/besu/pull/4200) + ## 22.7.0 ### Additions and Improvements 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 e5f9bbaa9f8..384a406b206 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 @@ -382,10 +382,7 @@ private void handleStatusMessage(final EthPeer peer, final MessageData data) { final boolean disconnected = mergePeerFilter.get().disconnectIfPoW(status, peer); if (disconnected) { LOG.info("here we are disconnecting at request from mergePeerFilter disconnectIfPoW"); - handleDisconnect( - peer.getConnection(), - DisconnectReason.SUBPROTOCOL_TRIGGERED, - false); // TODO should this be true + handleDisconnect(peer.getConnection(), DisconnectReason.SUBPROTOCOL_TRIGGERED, false); } } else { LOG.debug("Received status message from {}: {}", peer, status); diff --git a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgentTest.java b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgentTest.java index a9e9eaed459..07590bf794c 100644 --- a/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgentTest.java +++ b/ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgentTest.java @@ -1040,7 +1040,6 @@ private void startAgentWithLowerBoundPeers(final int lowerBound, final int upper } private void startAgentWithLowerBoundPeers(final int lowerBound) { - // TODO add upperBound param startAgentWithLowerBoundPeers(lowerBound, lowerBound, Function.identity(), __ -> {}); } From 64b97ed837c2ccbd2bff58354be9968d35961af9 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Mon, 1 Aug 2022 14:48:01 +1000 Subject: [PATCH 11/20] changed defaults Signed-off-by: Sally MacFarlane --- .../java/org/hyperledger/besu/cli/DefaultCommandValues.java | 4 ++-- .../hyperledger/besu/ethereum/p2p/network/NetworkRunner.java | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java index 832d00b3fd1..965a5fe6402 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java @@ -57,8 +57,8 @@ public interface DefaultCommandValues { NatMethod DEFAULT_NAT_METHOD = NatMethod.AUTO; JwtAlgorithm DEFAULT_JWT_ALGORITHM = JwtAlgorithm.RS256; int FAST_SYNC_MIN_PEER_COUNT = 5; - int DEFAULT_MAX_PEERS = 25; - int DEFAULT_P2P_PEER_LOWER_BOUND = 20; + int DEFAULT_MAX_PEERS = 100; // TODO this is changing default behavior + int DEFAULT_P2P_PEER_LOWER_BOUND = 64; int DEFAULT_HTTP_MAX_CONNECTIONS = 80; int DEFAULT_WS_MAX_CONNECTIONS = 80; int DEFAULT_WS_MAX_FRAME_SIZE = 1024 * 1024; diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/NetworkRunner.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/NetworkRunner.java index 248937f62de..97993092133 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/NetworkRunner.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/NetworkRunner.java @@ -154,7 +154,6 @@ private void setupHandlers() { connection.getAgreedCapabilities(), protocolManager.getSupportedCapabilities())) { return; } - LOG.info("network runner - disconnect peerInitiated? {}", initiatedByPeer); protocolManager.handleDisconnect(connection, disconnectReason, initiatedByPeer); }); } From fa6e752e5e481691637c86368393dc661854e88d Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Mon, 1 Aug 2022 15:03:54 +1000 Subject: [PATCH 12/20] changed defaults Signed-off-by: Sally MacFarlane --- .../test/java/org/hyperledger/besu/cli/BesuCommandTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java index 3ab6e7bbc7c..8ce7756afa1 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -228,7 +228,7 @@ public void callingVersionDisplayBesuInfoVersion() { public void callingBesuCommandWithoutOptionsMustSyncWithDefaultValues() throws Exception { parseCommand(); - final int maxPeers = 25; + final int maxPeers = 100; final ArgumentCaptor ethNetworkArg = ArgumentCaptor.forClass(EthNetworkConfig.class); @@ -865,7 +865,7 @@ public void noOverrideDefaultValuesIfKeyIsNotPresentInConfigFile() throws IOExce MAINNET_DISCOVERY_URL)); verify(mockRunnerBuilder).p2pAdvertisedHost(eq("127.0.0.1")); verify(mockRunnerBuilder).p2pListenPort(eq(30303)); - verify(mockRunnerBuilder).maxPeers(eq(25)); + verify(mockRunnerBuilder).maxPeers(eq(100)); verify(mockRunnerBuilder).limitRemoteWireConnectionsEnabled(eq(true)); verify(mockRunnerBuilder).fractionRemoteConnectionsAllowed(eq(0.6f)); verify(mockRunnerBuilder).jsonRpcConfiguration(eq(jsonRpcConfiguration)); From f95996f988fa8dcb8e45255beac0486d1c9a1d51 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Tue, 2 Aug 2022 11:30:15 +1000 Subject: [PATCH 13/20] log Signed-off-by: Sally MacFarlane --- .../java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgent.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgent.java index 45ae000f6e2..6c679e23177 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgent.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/rlpx/RlpxAgent.java @@ -367,7 +367,7 @@ private void handleIncomingConnection(final PeerConnection peerConnection) { if (!peerPrivileges.canExceedConnectionLimits(peer) && getConnectionCount() >= upperBoundConnections) { LOG.debug( - "Too many peers. Disconnect incoming connection: {} currentCount {} > max {}", + "Too many peers. Disconnect incoming connection: {} currentCount {}, max {}", peerConnection, getConnectionCount(), upperBoundConnections); From 0daf9b39e35db8e418829fb85862bd47c8a3e90f Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Wed, 3 Aug 2022 13:53:04 +1000 Subject: [PATCH 14/20] add validateOptions and some tests Signed-off-by: Sally MacFarlane --- .../org/hyperledger/besu/cli/BesuCommand.java | 1 + .../besu/cli/DefaultCommandValues.java | 2 +- .../hyperledger/besu/cli/BesuCommandTest.java | 44 +++++++++++++++++++ .../p2p/config/RlpxConfiguration.java | 2 +- 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index c000194e275..2698e37e4ea 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -1724,6 +1724,7 @@ private void validateOptions() { validateNatParams(); validateNetStatsParams(); validateDnsOptionsParams(); + validatePeerBoundParams(); validateRpcOptionsParams(); p2pTLSConfigOptions.checkP2PTLSOptionsDependencies(logger, commandLine); pkiBlockCreationOptions.checkPkiBlockCreationOptionsDependencies(logger, commandLine); diff --git a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java index 965a5fe6402..b4e35a8ca79 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java @@ -57,7 +57,7 @@ public interface DefaultCommandValues { NatMethod DEFAULT_NAT_METHOD = NatMethod.AUTO; JwtAlgorithm DEFAULT_JWT_ALGORITHM = JwtAlgorithm.RS256; int FAST_SYNC_MIN_PEER_COUNT = 5; - int DEFAULT_MAX_PEERS = 100; // TODO this is changing default behavior + int DEFAULT_MAX_PEERS = 100; int DEFAULT_P2P_PEER_LOWER_BOUND = 64; int DEFAULT_HTTP_MAX_CONNECTIONS = 80; int DEFAULT_WS_MAX_CONNECTIONS = 80; diff --git a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java index 8ce7756afa1..92279b36d84 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -1542,6 +1542,50 @@ public void maxpeersOptionMustBeUsed() { assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); } + @Test + public void p2pPeerUpperBound_without_p2pPeerLowerBound_shouldSetDefaultLowerBoundLessThanMaxPeers() { + + final int maxPeers = 23; + parseCommand("--p2p-peer-upper-bound", String.valueOf(maxPeers)); + + verify(mockRunnerBuilder).maxPeers(intArgumentCaptor.capture()); + verify(mockRunnerBuilder).build(); + + assertThat(intArgumentCaptor.getValue()).isEqualTo(maxPeers); + + assertThat(commandOutput.toString(UTF_8)).isEmpty(); + assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); + } + + @Test + public void p2pPeerUpperBound_lessThan_p2pPeerLowerBound_givesError() { + + final int maxPeers = 23; + parseCommand("--p2p-peer-upper-bound", String.valueOf(maxPeers), "--Xp2p-peer-lower-bound", String.valueOf(maxPeers * 2)); + + Mockito.verifyNoInteractions(mockRunnerBuilder); + + assertThat(commandOutput.toString(UTF_8)).isEmpty(); + assertThat(commandErrorOutput.toString(UTF_8)) + .contains("lower bound must not exceed max-peers."); + } + + @Test + public void maxpeersSet_p2pPeerLowerBoundSet() { + + final int maxPeers = 123; + final int minPeers = 66; + parseCommand("--max-peers", String.valueOf(maxPeers), "--Xp2p-peer-lower-bound", String.valueOf(minPeers)); + + verify(mockRunnerBuilder).maxPeers(intArgumentCaptor.capture()); + verify(mockRunnerBuilder).build(); + + assertThat(intArgumentCaptor.getValue()).isEqualTo(maxPeers); + + assertThat(commandOutput.toString(UTF_8)).isEmpty(); + assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); + } + @Test public void remoteConnectionsPercentageOptionMustBeUsed() { diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java index 4546d033e3f..facf2771170 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/config/RlpxConfiguration.java @@ -29,7 +29,7 @@ public class RlpxConfiguration { private String clientId = "TestClient/1.0.0"; private String bindHost = NetworkUtility.INADDR_ANY; private int bindPort = 30303; - private int peerUpperBound = 100; // TODO copied Teku's defaults + private int peerUpperBound = 100; private int peerLowerBound = 64; private boolean limitRemoteWireConnectionsEnabled = false; private float fractionRemoteWireConnectionsAllowed = DEFAULT_FRACTION_REMOTE_CONNECTIONS_ALLOWED; From 85b4b43ca612cecf3b022888afe3b04f69b873c7 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Wed, 3 Aug 2022 13:53:56 +1000 Subject: [PATCH 15/20] formatting Signed-off-by: Sally MacFarlane --- .../org/hyperledger/besu/cli/BesuCommand.java | 6 +++--- .../hyperledger/besu/cli/BesuCommandTest.java | 17 +++++++++++++---- .../eth/manager/EthProtocolManager.java | 9 ++++----- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index 2698e37e4ea..5ef1ce43d57 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -1798,10 +1798,10 @@ private void validateDnsOptionsParams() { } private void validatePeerBoundParams() { - if (unstableNetworkingOptions.toDomainObject().getRlpx().getPeerLowerBound() > p2PDiscoveryOptionGroup.maxPeers) { + if (unstableNetworkingOptions.toDomainObject().getRlpx().getPeerLowerBound() + > p2PDiscoveryOptionGroup.maxPeers) { throw new ParameterException( - this.commandLine, - "The `--Xp2p-peer-lower-bound` must not exceed --max-peers "); + this.commandLine, "The `--Xp2p-peer-lower-bound` must not exceed --max-peers "); } } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java index 92279b36d84..209e992b58c 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -1543,7 +1543,8 @@ public void maxpeersOptionMustBeUsed() { } @Test - public void p2pPeerUpperBound_without_p2pPeerLowerBound_shouldSetDefaultLowerBoundLessThanMaxPeers() { + public void + p2pPeerUpperBound_without_p2pPeerLowerBound_shouldSetDefaultLowerBoundLessThanMaxPeers() { final int maxPeers = 23; parseCommand("--p2p-peer-upper-bound", String.valueOf(maxPeers)); @@ -1561,13 +1562,17 @@ public void p2pPeerUpperBound_without_p2pPeerLowerBound_shouldSetDefaultLowerBou public void p2pPeerUpperBound_lessThan_p2pPeerLowerBound_givesError() { final int maxPeers = 23; - parseCommand("--p2p-peer-upper-bound", String.valueOf(maxPeers), "--Xp2p-peer-lower-bound", String.valueOf(maxPeers * 2)); + parseCommand( + "--p2p-peer-upper-bound", + String.valueOf(maxPeers), + "--Xp2p-peer-lower-bound", + String.valueOf(maxPeers * 2)); Mockito.verifyNoInteractions(mockRunnerBuilder); assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)) - .contains("lower bound must not exceed max-peers."); + .contains("lower bound must not exceed max-peers."); } @Test @@ -1575,7 +1580,11 @@ public void maxpeersSet_p2pPeerLowerBoundSet() { final int maxPeers = 123; final int minPeers = 66; - parseCommand("--max-peers", String.valueOf(maxPeers), "--Xp2p-peer-lower-bound", String.valueOf(minPeers)); + parseCommand( + "--max-peers", + String.valueOf(maxPeers), + "--Xp2p-peer-lower-bound", + String.valueOf(minPeers)); verify(mockRunnerBuilder).maxPeers(intArgumentCaptor.capture()); verify(mockRunnerBuilder).build(); 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 ae32c3d3041..1536ab5e137 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 @@ -268,8 +268,7 @@ public void processMessage(final Capability cap, final Message message) { if (this.mergePeerFilter.isPresent()) { if (this.mergePeerFilter.get().disconnectIfGossipingBlocks(message, ethPeer)) { - LOG.info( - "Post-merge disconnect: peer still gossiping blocks {}", ethPeer); + LOG.info("Post-merge disconnect: peer still gossiping blocks {}", ethPeer); handleDisconnect(ethPeer.getConnection(), DisconnectReason.SUBPROTOCOL_TRIGGERED, false); return; } @@ -390,9 +389,9 @@ private void handleStatusMessage(final EthPeer peer, final MessageData data) { status.genesisHash()); peer.disconnect(DisconnectReason.SUBPROTOCOL_TRIGGERED); } else if (mergePeerFilter.isPresent() - && mergePeerFilter.get().disconnectIfPoW(status, peer)) { - LOG.info("Post-merge disconnect: peer still PoW {}", peer); - handleDisconnect(peer.getConnection(), DisconnectReason.SUBPROTOCOL_TRIGGERED, false); + && mergePeerFilter.get().disconnectIfPoW(status, peer)) { + LOG.info("Post-merge disconnect: peer still PoW {}", peer); + handleDisconnect(peer.getConnection(), DisconnectReason.SUBPROTOCOL_TRIGGERED, false); } else { LOG.debug("Received status message from {}: {}", peer, status); peer.registerStatusReceived( From a6e0bc7e33c184f8b38369e06c5c2c3d2f90c28c Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Wed, 3 Aug 2022 14:40:12 +1000 Subject: [PATCH 16/20] more tests; set min = max if in doubt Signed-off-by: Sally MacFarlane --- .../dsl/node/ThreadBesuNodeRunner.java | 2 ++ .../org/hyperledger/besu/RunnerBuilder.java | 12 ++++++- .../org/hyperledger/besu/cli/BesuCommand.java | 23 +++++++++---- .../hyperledger/besu/cli/BesuCommandTest.java | 34 ++++++------------- .../besu/cli/CommandTestAbstract.java | 1 + 5 files changed, 42 insertions(+), 30 deletions(-) diff --git a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java index 35c1a69c381..b0ca91315ad 100644 --- a/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java +++ b/acceptance-tests/dsl/src/main/java/org/hyperledger/besu/tests/acceptance/dsl/node/ThreadBesuNodeRunner.java @@ -161,6 +161,7 @@ public void startNode(final BesuNode node) { .build(); final int maxPeers = 25; + final int minPeers = 25; builder .synchronizerConfiguration(new SynchronizerConfiguration.Builder().build()) @@ -198,6 +199,7 @@ public void startNode(final BesuNode node) { .p2pAdvertisedHost(node.getHostName()) .p2pListenPort(0) .maxPeers(maxPeers) + .minPeers(minPeers) .networkingConfiguration(node.getNetworkingConfiguration()) .jsonRpcConfiguration(node.jsonRpcConfiguration()) .webSocketConfiguration(node.webSocketConfiguration()) diff --git a/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java b/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java index 2841336addf..f50f64a7e7e 100644 --- a/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java @@ -165,6 +165,7 @@ public class RunnerBuilder { private String natManagerServiceName; private boolean natMethodFallbackEnabled; private int maxPeers; + private int minPeers; private boolean limitRemoteWireConnectionsEnabled = false; private float fractionRemoteConnectionsAllowed; private EthNetworkConfig ethNetworkConfig; @@ -445,7 +446,7 @@ public Runner build() { .setBindHost(p2pListenInterface) .setBindPort(p2pListenPort) .setPeerUpperBound(maxPeers) - .setPeerLowerBound(networkingConfiguration.getRlpx().getPeerLowerBound()) + .setPeerLowerBound(minPeers) .setSupportedProtocols(subProtocols) .setClientId(BesuInfo.nodeName(identityString)) .setLimitRemoteWireConnectionsEnabled(limitRemoteWireConnectionsEnabled) @@ -1158,4 +1159,13 @@ private Optional createMetricsService( final Vertx vertx, final MetricsConfiguration configuration) { return MetricsService.create(vertx, configuration, metricsSystem); } + + public int getMinPeers() { + return minPeers; + } + + public RunnerBuilder minPeers(final int minPeers) { + this.minPeers = minPeers; + return this; + } } diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index 5ef1ce43d57..b8039a1eafe 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -429,6 +429,8 @@ static class P2PDiscoveryOptionGroup { description = "Maximum P2P connections that can be established (default: ${DEFAULT-VALUE})") private final Integer maxPeers = DEFAULT_MAX_PEERS; + private int minPeers; + @Option( names = {"--remote-connections-limit-enabled"}, description = @@ -1602,6 +1604,7 @@ private Runner buildRunner() { p2PDiscoveryOptionGroup.peerDiscoveryEnabled, ethNetworkConfig, p2PDiscoveryOptionGroup.maxPeers, + p2PDiscoveryOptionGroup.minPeers, p2PDiscoveryOptionGroup.p2pHost, p2PDiscoveryOptionGroup.p2pInterface, p2PDiscoveryOptionGroup.p2pPort, @@ -1724,7 +1727,7 @@ private void validateOptions() { validateNatParams(); validateNetStatsParams(); validateDnsOptionsParams(); - validatePeerBoundParams(); + ensureValidPeerBoundParams(); validateRpcOptionsParams(); p2pTLSConfigOptions.checkP2PTLSOptionsDependencies(logger, commandLine); pkiBlockCreationOptions.checkPkiBlockCreationOptionsDependencies(logger, commandLine); @@ -1797,11 +1800,17 @@ private void validateDnsOptionsParams() { } } - private void validatePeerBoundParams() { - if (unstableNetworkingOptions.toDomainObject().getRlpx().getPeerLowerBound() - > p2PDiscoveryOptionGroup.maxPeers) { - throw new ParameterException( - this.commandLine, "The `--Xp2p-peer-lower-bound` must not exceed --max-peers "); + private void ensureValidPeerBoundParams() { + final int min = unstableNetworkingOptions.toDomainObject().getRlpx().getPeerLowerBound(); + final int max = p2PDiscoveryOptionGroup.maxPeers; + if (min > max) { + logger.warn("`--Xp2p-peer-lower-bound` " + min + " must not exceed --max-peers " + max); + // modify the --X lower-bound value if it's not valid, we don't want unstable defaults + // breaking things + unstableNetworkingOptions.toDomainObject().getRlpx().setPeerLowerBound(max); + p2PDiscoveryOptionGroup.minPeers = max; + } else { + p2PDiscoveryOptionGroup.minPeers = min; } } @@ -2783,6 +2792,7 @@ private Runner synchronize( final boolean peerDiscoveryEnabled, final EthNetworkConfig ethNetworkConfig, final int maxPeers, + final int minPeers, final String p2pAdvertisedHost, final String p2pListenInterface, final int p2pListenPort, @@ -2817,6 +2827,7 @@ private Runner synchronize( .p2pListenInterface(p2pListenInterface) .p2pListenPort(p2pListenPort) .maxPeers(maxPeers) + .minPeers(minPeers) .limitRemoteWireConnectionsEnabled( p2PDiscoveryOptionGroup.isLimitRemoteWireConnectionsEnabled) .fractionRemoteConnectionsAllowed( diff --git a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java index 209e992b58c..4ebf72a330f 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -1543,36 +1543,21 @@ public void maxpeersOptionMustBeUsed() { } @Test - public void - p2pPeerUpperBound_without_p2pPeerLowerBound_shouldSetDefaultLowerBoundLessThanMaxPeers() { + public void p2pPeerUpperBound_without_p2pPeerLowerBound_shouldSetLowerBoundEqualToUpperBound() { final int maxPeers = 23; parseCommand("--p2p-peer-upper-bound", String.valueOf(maxPeers)); - verify(mockRunnerBuilder).maxPeers(intArgumentCaptor.capture()); - verify(mockRunnerBuilder).build(); - - assertThat(intArgumentCaptor.getValue()).isEqualTo(maxPeers); - assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); - } - @Test - public void p2pPeerUpperBound_lessThan_p2pPeerLowerBound_givesError() { - - final int maxPeers = 23; - parseCommand( - "--p2p-peer-upper-bound", - String.valueOf(maxPeers), - "--Xp2p-peer-lower-bound", - String.valueOf(maxPeers * 2)); + verify(mockRunnerBuilder).maxPeers(intArgumentCaptor.capture()); + assertThat(intArgumentCaptor.getValue()).isEqualTo(maxPeers); - Mockito.verifyNoInteractions(mockRunnerBuilder); + verify(mockRunnerBuilder).minPeers(intArgumentCaptor.capture()); + assertThat(intArgumentCaptor.getValue()).isEqualTo(maxPeers); - assertThat(commandOutput.toString(UTF_8)).isEmpty(); - assertThat(commandErrorOutput.toString(UTF_8)) - .contains("lower bound must not exceed max-peers."); + verify(mockRunnerBuilder).build(); } @Test @@ -1587,10 +1572,13 @@ public void maxpeersSet_p2pPeerLowerBoundSet() { String.valueOf(minPeers)); verify(mockRunnerBuilder).maxPeers(intArgumentCaptor.capture()); - verify(mockRunnerBuilder).build(); - assertThat(intArgumentCaptor.getValue()).isEqualTo(maxPeers); + verify(mockRunnerBuilder).minPeers(intArgumentCaptor.capture()); + assertThat(intArgumentCaptor.getValue()).isEqualTo(minPeers); + + verify(mockRunnerBuilder).build(); + assertThat(commandOutput.toString(UTF_8)).isEmpty(); assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); } diff --git a/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java b/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java index 14fd6dae6a0..649d54efaf6 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/CommandTestAbstract.java @@ -254,6 +254,7 @@ public void initMocks() throws Exception { when(mockRunnerBuilder.p2pListenInterface(anyString())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.permissioningConfiguration(any())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.maxPeers(anyInt())).thenReturn(mockRunnerBuilder); + when(mockRunnerBuilder.minPeers(anyInt())).thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.limitRemoteWireConnectionsEnabled(anyBoolean())) .thenReturn(mockRunnerBuilder); when(mockRunnerBuilder.fractionRemoteConnectionsAllowed(anyFloat())) From 73107bcec30347bcd2f2c5dab268f9c95c6432b3 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 4 Aug 2022 13:06:35 +1000 Subject: [PATCH 17/20] logging Signed-off-by: Sally MacFarlane --- besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java | 1 + .../besu/ethereum/eth/manager/EthProtocolManager.java | 4 ++-- .../besu/ethereum/p2p/network/DefaultP2PNetwork.java | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java index b8039a1eafe..4011428fb99 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java @@ -1807,6 +1807,7 @@ private void ensureValidPeerBoundParams() { logger.warn("`--Xp2p-peer-lower-bound` " + min + " must not exceed --max-peers " + max); // modify the --X lower-bound value if it's not valid, we don't want unstable defaults // breaking things + logger.warn("setting --Xp2p-peer-lower-bound=" + max); unstableNetworkingOptions.toDomainObject().getRlpx().setPeerLowerBound(max); p2PDiscoveryOptionGroup.minPeers = max; } else { 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 1536ab5e137..3956ce1cf29 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 @@ -268,7 +268,7 @@ public void processMessage(final Capability cap, final Message message) { if (this.mergePeerFilter.isPresent()) { if (this.mergePeerFilter.get().disconnectIfGossipingBlocks(message, ethPeer)) { - LOG.info("Post-merge disconnect: peer still gossiping blocks {}", ethPeer); + LOG.debug("Post-merge disconnect: peer still gossiping blocks {}", ethPeer); handleDisconnect(ethPeer.getConnection(), DisconnectReason.SUBPROTOCOL_TRIGGERED, false); return; } @@ -390,7 +390,7 @@ private void handleStatusMessage(final EthPeer peer, final MessageData data) { peer.disconnect(DisconnectReason.SUBPROTOCOL_TRIGGERED); } else if (mergePeerFilter.isPresent() && mergePeerFilter.get().disconnectIfPoW(status, peer)) { - LOG.info("Post-merge disconnect: peer still PoW {}", peer); + LOG.debug("Post-merge disconnect: peer still PoW {}", peer); handleDisconnect(peer.getConnection(), DisconnectReason.SUBPROTOCOL_TRIGGERED, false); } else { LOG.debug("Received status message from {}: {}", peer, status); diff --git a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java index 3e1df601037..35b29c89b43 100644 --- a/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java +++ b/ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java @@ -187,7 +187,7 @@ public class DefaultP2PNetwork implements P2PNetwork { // set the requirement here that the number of peers be greater than the lower bound final int peerLowerBound = config.getRlpx().getPeerLowerBound(); - LOG.info("setting peerLowerBound {}", peerLowerBound); + LOG.debug("setting peerLowerBound {}", peerLowerBound); peerDiscoveryAgent.addPeerRequirement(() -> rlpxAgent.getConnectionCount() >= peerLowerBound); subscribeDisconnect(reputationManager); } From 20d1880e20927e89e67e48b65bf5416bbadfc95a Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Thu, 4 Aug 2022 13:48:35 +1000 Subject: [PATCH 18/20] defaults minPeers/maxPeers 25/50 Signed-off-by: Sally MacFarlane --- .../java/org/hyperledger/besu/cli/DefaultCommandValues.java | 4 ++-- .../test/java/org/hyperledger/besu/cli/BesuCommandTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java index b4e35a8ca79..19c383d39d1 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java @@ -57,8 +57,8 @@ public interface DefaultCommandValues { NatMethod DEFAULT_NAT_METHOD = NatMethod.AUTO; JwtAlgorithm DEFAULT_JWT_ALGORITHM = JwtAlgorithm.RS256; int FAST_SYNC_MIN_PEER_COUNT = 5; - int DEFAULT_MAX_PEERS = 100; - int DEFAULT_P2P_PEER_LOWER_BOUND = 64; + int DEFAULT_MAX_PEERS = 50; + int DEFAULT_P2P_PEER_LOWER_BOUND = 25; int DEFAULT_HTTP_MAX_CONNECTIONS = 80; int DEFAULT_WS_MAX_CONNECTIONS = 80; int DEFAULT_WS_MAX_FRAME_SIZE = 1024 * 1024; diff --git a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java index 4ebf72a330f..dc84a78d04a 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -228,7 +228,7 @@ public void callingVersionDisplayBesuInfoVersion() { public void callingBesuCommandWithoutOptionsMustSyncWithDefaultValues() throws Exception { parseCommand(); - final int maxPeers = 100; + final int maxPeers = 50; final ArgumentCaptor ethNetworkArg = ArgumentCaptor.forClass(EthNetworkConfig.class); @@ -865,7 +865,7 @@ public void noOverrideDefaultValuesIfKeyIsNotPresentInConfigFile() throws IOExce MAINNET_DISCOVERY_URL)); verify(mockRunnerBuilder).p2pAdvertisedHost(eq("127.0.0.1")); verify(mockRunnerBuilder).p2pListenPort(eq(30303)); - verify(mockRunnerBuilder).maxPeers(eq(100)); + verify(mockRunnerBuilder).maxPeers(eq(50)); verify(mockRunnerBuilder).limitRemoteWireConnectionsEnabled(eq(true)); verify(mockRunnerBuilder).fractionRemoteConnectionsAllowed(eq(0.6f)); verify(mockRunnerBuilder).jsonRpcConfiguration(eq(jsonRpcConfiguration)); From 104ac959b477caf2d7a5428e28bfb86e99dffad5 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Fri, 5 Aug 2022 09:44:02 +1000 Subject: [PATCH 19/20] defaults minPeers/maxPeers 25/30 Signed-off-by: Sally MacFarlane --- .../java/org/hyperledger/besu/cli/DefaultCommandValues.java | 2 +- .../test/java/org/hyperledger/besu/cli/BesuCommandTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java index 19c383d39d1..f1051413824 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java @@ -57,7 +57,7 @@ public interface DefaultCommandValues { NatMethod DEFAULT_NAT_METHOD = NatMethod.AUTO; JwtAlgorithm DEFAULT_JWT_ALGORITHM = JwtAlgorithm.RS256; int FAST_SYNC_MIN_PEER_COUNT = 5; - int DEFAULT_MAX_PEERS = 50; + int DEFAULT_MAX_PEERS = 30; int DEFAULT_P2P_PEER_LOWER_BOUND = 25; int DEFAULT_HTTP_MAX_CONNECTIONS = 80; int DEFAULT_WS_MAX_CONNECTIONS = 80; diff --git a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java index dc84a78d04a..d7b128fcd4f 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -228,7 +228,7 @@ public void callingVersionDisplayBesuInfoVersion() { public void callingBesuCommandWithoutOptionsMustSyncWithDefaultValues() throws Exception { parseCommand(); - final int maxPeers = 50; + final int maxPeers = 30; final ArgumentCaptor ethNetworkArg = ArgumentCaptor.forClass(EthNetworkConfig.class); @@ -865,7 +865,7 @@ public void noOverrideDefaultValuesIfKeyIsNotPresentInConfigFile() throws IOExce MAINNET_DISCOVERY_URL)); verify(mockRunnerBuilder).p2pAdvertisedHost(eq("127.0.0.1")); verify(mockRunnerBuilder).p2pListenPort(eq(30303)); - verify(mockRunnerBuilder).maxPeers(eq(50)); + verify(mockRunnerBuilder).maxPeers(eq(30)); verify(mockRunnerBuilder).limitRemoteWireConnectionsEnabled(eq(true)); verify(mockRunnerBuilder).fractionRemoteConnectionsAllowed(eq(0.6f)); verify(mockRunnerBuilder).jsonRpcConfiguration(eq(jsonRpcConfiguration)); From ca216c152c4fdfe8ad73e6f643eaff6536e02636 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Fri, 5 Aug 2022 14:03:32 +1000 Subject: [PATCH 20/20] changed defaults to 25/25 Signed-off-by: Sally MacFarlane --- .../java/org/hyperledger/besu/cli/DefaultCommandValues.java | 2 +- .../test/java/org/hyperledger/besu/cli/BesuCommandTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java index f1051413824..2ca3b5d7ab1 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/DefaultCommandValues.java @@ -57,7 +57,7 @@ public interface DefaultCommandValues { NatMethod DEFAULT_NAT_METHOD = NatMethod.AUTO; JwtAlgorithm DEFAULT_JWT_ALGORITHM = JwtAlgorithm.RS256; int FAST_SYNC_MIN_PEER_COUNT = 5; - int DEFAULT_MAX_PEERS = 30; + int DEFAULT_MAX_PEERS = 25; int DEFAULT_P2P_PEER_LOWER_BOUND = 25; int DEFAULT_HTTP_MAX_CONNECTIONS = 80; int DEFAULT_WS_MAX_CONNECTIONS = 80; diff --git a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java index d7b128fcd4f..fe72df7af9f 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -228,7 +228,7 @@ public void callingVersionDisplayBesuInfoVersion() { public void callingBesuCommandWithoutOptionsMustSyncWithDefaultValues() throws Exception { parseCommand(); - final int maxPeers = 30; + final int maxPeers = 25; final ArgumentCaptor ethNetworkArg = ArgumentCaptor.forClass(EthNetworkConfig.class); @@ -865,7 +865,7 @@ public void noOverrideDefaultValuesIfKeyIsNotPresentInConfigFile() throws IOExce MAINNET_DISCOVERY_URL)); verify(mockRunnerBuilder).p2pAdvertisedHost(eq("127.0.0.1")); verify(mockRunnerBuilder).p2pListenPort(eq(30303)); - verify(mockRunnerBuilder).maxPeers(eq(30)); + verify(mockRunnerBuilder).maxPeers(eq(25)); verify(mockRunnerBuilder).limitRemoteWireConnectionsEnabled(eq(true)); verify(mockRunnerBuilder).fractionRemoteConnectionsAllowed(eq(0.6f)); verify(mockRunnerBuilder).jsonRpcConfiguration(eq(jsonRpcConfiguration));