check for self in one more spot (#4521)

* check for self in one more spot

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
pull/4542/head
Sally MacFarlane 2 years ago committed by GitHub
parent 86755923d4
commit ec13809695
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      CHANGELOG.md
  2. 2
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetwork.java
  3. 16
      ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/network/DefaultP2PNetworkTest.java
  4. 4
      ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/peers/PeerTestHelper.java

@ -19,9 +19,10 @@
- Improved RLP processing of zero-length string as 0x80 [#4283](https://github.com/hyperledger/besu/pull/4283) [#4388](https://github.com/hyperledger/besu/issues/4388)
- Increased level of detail in JSON-RPC parameter error log messages [#4510](https://github.com/hyperledger/besu/pull/4510)
- New unstable configuration options to set the maximum time, in milliseconds, a PoS block creation jobs is allowed to run [#4519](https://github.com/hyperledger/besu/pull/4519)
- Tune EthScheduler thread pools to avoid to recreate too many threads [#4529](https://github.com/hyperledger/besu/pull/4529)
- Tune EthScheduler thread pools to avoid recreating too many threads [#4529](https://github.com/hyperledger/besu/pull/4529)
- RocksDB snapshot based worldstate and plugin-api addition of Snapshot interfaces [#4409](https://github.com/hyperledger/besu/pull/4409)
- Continuously try to build better block proposals until timeout or GetPayload is called [#4516](https://github.com/hyperledger/besu/pull/4516)
- Avoid connecting to self when using static-nodes [#4521](https://github.com/hyperledger/besu/pull/4521)
### Bug Fixes
- Corrects emission of blockadded events when rewinding during a re-org. Fix for [#4495](https://github.com/hyperledger/besu/issues/4495)

@ -359,8 +359,10 @@ public class DefaultP2PNetwork implements P2PNetwork {
if (!localNode.isReady()) {
return;
}
final EnodeURL localEnodeURL = localNode.getPeer().getEnodeURL();
maintainedPeers
.streamPeers()
.filter(peer -> !peer.getEnodeURL().getNodeId().equals(localEnodeURL.getNodeId()))
.filter(p -> !rlpxAgent.getPeerConnection(p).isPresent())
.forEach(rlpxAgent::connect);
}

@ -52,6 +52,7 @@ import org.hyperledger.besu.nat.NatMethod;
import org.hyperledger.besu.nat.NatService;
import org.hyperledger.besu.nat.core.domain.NetworkProtocol;
import org.hyperledger.besu.nat.upnp.UpnpNatManager;
import org.hyperledger.besu.plugin.data.EnodeURL;
import java.util.ArrayList;
import java.util.Collections;
@ -166,6 +167,21 @@ public final class DefaultP2PNetworkTest {
verify(discoveryAgent, times(1)).dropPeer(peer);
}
@Test
public void checkMaintainedConnectionPeers_doesNotConnectToSelf() {
final DefaultP2PNetwork network = network();
network.start();
final Optional<EnodeURL> maybeSelfEnode = network.getLocalEnode();
final Peer selfPeer = PeerTestHelper.createPeer(maybeSelfEnode.get());
maintainedPeers.add(selfPeer);
verify(rlpxAgent, times(0)).connect(selfPeer);
network.checkMaintainedConnectionPeers();
verify(rlpxAgent, times(0)).connect(selfPeer);
}
@Test
public void checkMaintainedConnectionPeers_unconnectedPeer() {
final DefaultP2PNetwork network = network();

@ -27,6 +27,10 @@ public class PeerTestHelper {
return DefaultPeer.fromEnodeURL(enode());
}
public static Peer createPeer(final EnodeURL enodeURL) {
return DefaultPeer.fromEnodeURL(enodeURL);
}
public static Peer createPeer(final Bytes nodeId) {
return DefaultPeer.fromEnodeURL(enodeBuilder().nodeId(nodeId).build());
}

Loading…
Cancel
Save