Skip to content

Commit

Permalink
check for self in one more spot (hyperledger#4521)
Browse files Browse the repository at this point in the history
* check for self in one more spot

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
  • Loading branch information
macfarla authored Oct 19, 2022
1 parent 8675592 commit ec13809
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,10 @@ void checkMaintainedConnectionPeers() {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
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;
Expand Down Expand Up @@ -166,6 +167,21 @@ public void removeMaintainedConnectionPeer_nonMaintainedPeer() {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public static Peer createPeer() {
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());
}
Expand Down

0 comments on commit ec13809

Please sign in to comment.