-
Notifications
You must be signed in to change notification settings - Fork 834
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
fix enr request order #4179
fix enr request order #4179
Conversation
Signed-off-by: Karim TAAM <[email protected]>
Signed-off-by: Karim TAAM <[email protected]>
.../main/java/org/hyperledger/besu/ethereum/p2p/discovery/internal/PeerDiscoveryController.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a sensible approach, one minor improvement suggested.
.../main/java/org/hyperledger/besu/ethereum/p2p/discovery/internal/PeerDiscoveryController.java
Show resolved
Hide resolved
.../main/java/org/hyperledger/besu/ethereum/p2p/discovery/internal/PeerDiscoveryController.java
Show resolved
Hide resolved
Signed-off-by: Karim TAAM <[email protected]>
@@ -111,6 +111,8 @@ public class PeerDiscoveryController { | |||
private final PeerTable peerTable; | |||
private final Cache<Bytes, DiscoveryPeer> bondingPeers = | |||
CacheBuilder.newBuilder().maximumSize(50).expireAfterWrite(10, TimeUnit.MINUTES).build(); | |||
private final Cache<Bytes, Packet> cachedEnrRequests = | |||
CacheBuilder.newBuilder().maximumSize(50).expireAfterWrite(30, SECONDS).build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs on CacheBuilder
recommend migrating to Caffeine. This is probably something to look into across the codebase - maybe for a follow-up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is 30 seconds overly generous? Maybe 10 seconds?
@@ -314,9 +316,12 @@ public void onMessage(final Packet packet, final DiscoveryPeer sender) { | |||
matchInteraction(packet) | |||
.ifPresent( | |||
interaction -> { | |||
System.out.println("ici"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stray println
@@ -1371,6 +1371,45 @@ public void shouldNotRespondToENRRequestForNonBondedPeer() { | |||
.send(eq(peers.get(0)), matchPacketOfType(PacketType.ENR_REQUEST)); | |||
} | |||
|
|||
@Test | |||
public void shouldNotRespondAndCacheENRRequestForBondingPeer() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test name is a bit confusing to me, what about:
public void shouldNotRespondAndCacheENRRequestForBondingPeer() { | |
public void shouldRespondToRecentENRRequestAfterBonding() { |
final Packet pongPacket = | ||
Packet.create(PacketType.PONG, pongRequestPacketData, nodeKeys.get(0)); | ||
|
||
controller.onMessage(enrPacket, peers.get(0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd verify here that we did not respond to the enr request directly with something like:
verify(outboundMessageHandler, never())
.send(any(), matchPacketOfType(PacketType.ENR_RESPONSE));
@@ -1371,6 +1371,45 @@ public void shouldNotRespondToENRRequestForNonBondedPeer() { | |||
.send(eq(peers.get(0)), matchPacketOfType(PacketType.ENR_REQUEST)); | |||
} | |||
|
|||
@Test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(optional) Might be nice to add another test that checks that we don't respond to an ENR request received way before a PONG message. Could do this by injecting a CacheBuilder
with a customer ticker that can be advanced from the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense! Proposed minor change for comment.
} else if (PeerDiscoveryStatus.BONDING.equals(peer.getStatus())) { | ||
LOG.trace("ENR_REQUEST cached for bonding peer Id: {}", peer.getId()); | ||
// it may happen that we receive the ENR_REQUEST just before the PONG. | ||
// Because peers want to send the ENR_REQUEST directly after the pong. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to mention that this can happen because discovery is using UDP?
Signed-off-by: Justin Florentine <[email protected]>
…omplete ping/pong handshakes Signed-off-by: Justin Florentine <[email protected]>
* fix enr request * add tests * removed errant debug * adds pr feedback and test to ensure ENR responses never go out to incomplete ping/pong handshakes Signed-off-by: Karim TAAM <[email protected]> Co-authored-by: Justin Florentine <[email protected]>
Signed-off-by: Karim TAAM [email protected]
PR description
After a Geth<>Besu peerring test we found that sometimes we had "ENR request failed id=68f8eb309602c1a6 addr=3.16.90.60:30303 err=“RPC timeout”
Besu does not respond to the ENR request. By investigating we found that sometimes ENR_REQUEST comes before the PONG and so Besu ignores the request.
This PR allows to cache the request if it arrives before the PONG to answer once the bond is done
Fixed Issue(s)
Documentation
doc-change-required
label to this PR ifupdates are required.
Changelog