Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DNS peers handled the same as boot nodes #4178

Merged
merged 10 commits into from
Aug 2, 2022

Conversation

pinges
Copy link
Contributor

@pinges pinges commented Jul 27, 2022

Peers discovered through the DNSDaemon are now added to the peerTable. These peers are potentially used (16 are randomly chosen from the peer table) in RecursivePeerRefreshStateas as the initial peers for bonding and then for finding neighbours, etc.

Signed-off-by: Stefan stefan.pingel@consensys.net

pinges added 5 commits July 27, 2022 22:13
Signed-off-by: Stefan <stefan.pingel@consensys.net>
Signed-off-by: Stefan <stefan.pingel@consensys.net>
Signed-off-by: Stefan <stefan.pingel@consensys.net>
Signed-off-by: Stefan <stefan.pingel@consensys.net>
Copy link
Contributor

@matkt matkt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a few questions to understand the PR

@@ -278,6 +281,14 @@ public void processMessage(final Capability cap, final Message message) {
return;
}

if (messageData.getSize() > this.maxMessageSize) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why this modification is present in the PR

@@ -347,11 +344,16 @@ DNSDaemonListener createDaemonListener() {
.build();
final DiscoveryPeer peer = DiscoveryPeer.fromEnode(enodeURL);
peers.add(peer);
rlpxAgent.connect(peer);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we no longer trying to connect to the peer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you put this back in, right @pinges

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it is just moved to the subsequent block on line 357 after adding to the peer table

pinges added 2 commits July 28, 2022 18:57
Signed-off-by: Stefan <stefan.pingel@consensys.net>
Signed-off-by: Stefan <stefan.pingel@consensys.net>
@iamhsk iamhsk added the TeamRevenant GH issues worked on by Revenant Team label Aug 1, 2022
messageData.getSize(),
this.maxMessageSize);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is useful, although unrelated to this PR

@@ -93,6 +93,7 @@ private boolean reachedMaximumNumberOfRounds() {
}

private void addInitialPeers(final List<DiscoveryPeer> initialPeers) {
LOG.debug("INITIAL PEERS: {}", initialPeers);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another log not needed

@@ -347,11 +344,16 @@ DNSDaemonListener createDaemonListener() {
.build();
final DiscoveryPeer peer = DiscoveryPeer.fromEnode(enodeURL);
peers.add(peer);
rlpxAgent.connect(peer);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you put this back in, right @pinges

pinges added 2 commits August 2, 2022 17:27
Signed-off-by: Stefan <stefan.pingel@consensys.net>
Copy link
Contributor

@jflo jflo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and a slight initial speedup in gained peers was observed.

* @param limit The amount of results to return.
* @return The <code>limit</code> closest peers, at most.
*/
public List<DiscoveryPeer> nearestBondedPeers(final Bytes target, final int limit) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume this is necessary in order to not give remote clients a list of unverified peers from DNSDaemon lookups?

Copy link
Contributor Author

@pinges pinges Aug 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is using the definition of distance from the devP2P spec to find the limit number of closest peers to the target.
This is needed to respond to a peer asking for neighbours.

@jflo jflo merged commit 42cfff0 into hyperledger:main Aug 2, 2022
Copy link
Contributor

@garyschulte garyschulte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

retroactive LGTM

@pinges pinges deleted the addEnpNodesToInitialNodes branch August 2, 2022 23:21
@pinges pinges self-assigned this Aug 3, 2022
final PeerTable.AddResult result = peerTable.tryAdd(peer);
if (result.getOutcome() == PeerTable.AddResult.AddOutcome.SELF) {
return false;
}

// Reset the last seen timestamp.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(bug) This change is problematic - if we discover our own node, we will now attempt to connect to ourselves because we're no longer short-circuiting the notifyPeerBonded logic below. The call to notifyPeerBonded dispatches an event which will cause the RlpxAgent to attempt a new connection.

Copy link
Contributor Author

@pinges pinges Aug 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is not needed anymore. The peerPermissions.isallowedInPeerTable takes care of this, as the local node is checked in the PeerPermissionsDenylist isPermitted() method.

Comment on lines +284 to +290
if (messageData.getSize() > this.maxMessageSize) {
LOG.debug(
"Peer {} sent a message with size {}, larger than the max message size {}",
ethPeer,
messageData.getSize(),
this.maxMessageSize);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've had 2 tickets and 3 PRs recently touch this logic, and now we're silently modifying it again in an unrelated PR.
Related Issues:

We should not be including these kinds of changes mixed in with other functional changes. There's also no explanation for why we're changing this again here.

Note: I'm not saying we should remove this, just that as a practice we should not be lumping in unrelated functional changes into a PR with no documentation on why the change is being made.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just adding debug info so we can see which clients are sending these messages

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed that. The only time I saw it in the logs was from an older Besu version!

Comment on lines +182 to +185
public Optional<PeerDiscoveryController> getPeerDiscoveryController() {
return controller;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PeerDiscoveryController is marked as internal and is not intended to be accessed from outside the discovery package. Any functionally that is needed should be exposed through PeerDiscoveryAgent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines +392 to +397
public boolean addToPeerTable(final DiscoveryPeer peer) {
final PeerTable.AddResult result = peerTable.tryAdd(peer);

if (result.getOutcome() == PeerTable.AddResult.AddOutcome.SELF) {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(bug) This method bypasses peerPermissions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was missed. I will create a new PR to add this check.

@@ -193,7 +211,6 @@ private void buildBloomFilter() {
public List<DiscoveryPeer> nearestPeers(final Bytes target, final int limit) {
final Bytes keccak256 = Hash.keccak256(target);
return streamAllPeers()
.filter(p -> p.getStatus() == PeerDiscoveryStatus.BONDED)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why has this method been modified? And why did we create the very similar nearestBondedPeers? It looks like the functional effect of this is to make the periodic peer searches run across all peers, not just bonded peers. Perhaps this is desired, but it should be addressed in a separate PR.

I suspect the reason this was added is because we're now directly injecting peers into the discovery table instead of bonding with them first. I would suggest reverting these changes, and attempting to bond with the DNS peers rather than directly injecting them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be cleaner, I guess. I will do that in a separate PR.

Comment on lines -231 to +230
60000L,
1800000L,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the call to the DNS server fails, this introduces a big time lag before we try again.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. maybe somewhere in between?

if (peerDiscoveryController.isPresent()) {
final PeerDiscoveryController controller = peerDiscoveryController.get();
LOG.debug("Adding {} DNS peers to PeerTable", peers.size());
peers.forEach(controller::addToPeerTable);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned previously, we should be calling PeerDiscoveryAgent.bond here instead of directly injecting peers into the discovery peer table.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

@pinges pinges mentioned this pull request Aug 16, 2022
eum602 pushed a commit to lacchain/besu that referenced this pull request Nov 3, 2023
* DNS peers handled the same as boot nodes
* make sure that non bonded peers can be used as initial peers
* try to connect to DNS nodes

Signed-off-by: Stefan <stefan.pingel@consensys.net>

Co-authored-by: Justin Florentine <justin+github@florentine.us>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mainnet peering TeamRevenant GH issues worked on by Revenant Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants