P2P: Connect to maintained connections at startup (#4543)

* Also adds a one time call to initiate connection to nodes in static nodes
  list after local node is ready. In the absence of this call, the connection attempt
  is made after the configured interval (default 60 seconds) to check maintained
  connections. This is to make sure the node doesn't have to wait for almost a minute
  before it can start interacting with peers (and sync blocks etc.)

Signed-off-by: Vinod Damle <vinod.damle@kaleido.io>
Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
Co-authored-by: Vinod Damle <vinod.damle@kaleido.io>
pull/4544/head
Sally MacFarlane 2 years ago committed by GitHub
parent 3ec23e4ecf
commit 1f04509aab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      CHANGELOG.md
  2. 4
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java
  3. 9
      ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetworkTest.java

@ -32,7 +32,8 @@
- Avoid a cyclic reference while printing EngineExchangeTransitionConfigurationParameter [#4357](https://github.com/hyperledger/besu/pull/4357)
- Corrects treating a block as bad on internal error [#4512](https://github.com/hyperledger/besu/issues/4512)
- In GraphQL update scalar parsing to be variable friendly [#4522](https://github.com/hyperledger/besu/pull/4522)
- update appache-commons-text to 1.10.0 to address CVE-2022-42889 [#4542](https://github.com/hyperledger/besu/pull/4542)
- Initiate connection to maintained peers soon after startup. [#4469](https://github.com/hyperledger/besu/pull/4469)
- Update apache-commons-text to 1.10.0 to address CVE-2022-42889 [#4542](https://github.com/hyperledger/besu/pull/4542)
### Download Links

@ -259,6 +259,10 @@ public class DefaultP2PNetwork implements P2PNetwork {
peerBondedObserverId =
OptionalLong.of(peerDiscoveryAgent.observePeerBondedEvents(this::handlePeerBondedEvent));
// Call checkMaintainedConnectionPeers() now that the local node is up, for immediate peer
// additions
checkMaintainedConnectionPeers();
// Periodically check maintained connections
final int checkMaintainedConnectionsSec = config.getCheckMaintainedConnectionsFrequencySec();
peerConnectionScheduler.scheduleWithFixedDelay(

@ -186,10 +186,11 @@ public final class DefaultP2PNetworkTest {
public void checkMaintainedConnectionPeers_unconnectedPeer() {
final DefaultP2PNetwork network = network();
final Peer peer = PeerTestHelper.createPeer();
maintainedPeers.add(peer);
network.start();
maintainedPeers.add(peer);
verify(rlpxAgent, times(0)).connect(peer);
network.checkMaintainedConnectionPeers();
@ -200,10 +201,11 @@ public final class DefaultP2PNetworkTest {
public void checkMaintainedConnectionPeers_connectedPeer() {
final DefaultP2PNetwork network = network();
final Peer peer = PeerTestHelper.createPeer();
maintainedPeers.add(peer);
network.start();
maintainedPeers.add(peer);
// Don't connect to an already connected peer
final CompletableFuture<PeerConnection> connectionFuture =
CompletableFuture.completedFuture(MockPeerConnection.create(peer));
@ -216,10 +218,11 @@ public final class DefaultP2PNetworkTest {
public void checkMaintainedConnectionPeers_connectingPeer() {
final DefaultP2PNetwork network = network();
final Peer peer = PeerTestHelper.createPeer();
maintainedPeers.add(peer);
network.start();
maintainedPeers.add(peer);
// Don't connect when connection is already pending.
final CompletableFuture<PeerConnection> connectionFuture = new CompletableFuture<>();
when(rlpxAgent.getPeerConnection(peer)).thenReturn(Optional.of(connectionFuture));

Loading…
Cancel
Save