-
Notifications
You must be signed in to change notification settings - Fork 474
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
p2p: introduce Gossip peer capability #5935
p2p: introduce Gossip peer capability #5935
Conversation
b1f874d
to
f2a05a6
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feature/p2p #5935 +/- ##
===============================================
+ Coverage 55.84% 55.88% +0.04%
===============================================
Files 490 490
Lines 68540 68628 +88
===============================================
+ Hits 38273 38353 +80
- Misses 27655 27665 +10
+ Partials 2612 2610 -2 ☔ View full report in Codecov by Sentry. |
628024a
to
d05816c
Compare
86d0be1
to
07bb5ce
Compare
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.
A few questions, but overall this makes a lot of sense.
peerIDs := s.host.Peerstore().Peers() | ||
for _, peerID := range peerIDs { | ||
ps := s.host.Peerstore().(*pstore.PeerStore) | ||
peerIDs := ps.GetAddresses(targetConnCount, phonebook.PhoneBookEntryRelayRole) |
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 is connecting via libp2p to known relays?
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 connects to peerstore relays that were either set via phonebook, DNS bootstrap, or discovered via DHT.
ph.ReplacePeerList(relaysSet, "default", PhoneBookEntryRelayRole) | ||
ph.ReplacePeerList(archiverSet, "default", PhoneBookEntryArchiverRole) | ||
ph.ReplacePeerList(infoRelaySet, "default", PhoneBookEntryRelayRole) | ||
ph.ReplacePeerList(infoArchiverSet, "default", PhoneBookEntryArchiverRole) |
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'm going to be killing off the archiver role in next PR.
var err error | ||
peers, err = n.capabilitiesDiscovery.PeersForCapability(p2p.Gossip, n.config.GossipFanout) | ||
if err != nil { | ||
n.log.Warnf("Error getting relay nodes from capabilities discovery: %v", err) |
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.
Shouldn't we be willing to connect to anyone, not just relays?
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 is to discuss. But there is no point to connect peers without gossip except to receive peers via peer exchange. Maybe it should be like 50/50 gossip/any
@@ -560,7 +605,19 @@ func (n *P2PNetwork) GetHTTPClient(address string) (*http.Client, error) { | |||
// this is the only indication that we have that we haven't formed a clique, where all incoming messages | |||
// arrive very quickly, but might be missing some votes. The usage of this call is expected to have similar | |||
// characteristics as with a watchdog timer. | |||
func (n *P2PNetwork) OnNetworkAdvance() {} | |||
func (n *P2PNetwork) OnNetworkAdvance() { |
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.
Am I understanding right, that we are checking based on something that we want to be connected to a participating node explicitly?
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 checks subscribes to gossipsub TX traffic if the node is participating in consensus
return netA.hasPeers() && netB.hasPeers() && netC.hasPeers() | ||
}, 2*time.Second, 50*time.Millisecond) | ||
|
||
time.Sleep(time.Second) // give time for peers to connect. |
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.
should the eventually cover this?
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 is the same in all 3 gossip tests. I tried to figure out why CI race build fails without it but no success.
} | ||
var result []peer.AddrInfo | ||
for _, addr := range unique { | ||
result = append(result, *addr) |
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.
nit: could use maps.Keys
50*time.Millisecond, | ||
) | ||
|
||
// check netB did not receive the messages |
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.
// check netB did not receive the messages | |
// check netC did not receive the messages |
right?
|
||
r2 := mergeP2PAddrInfoResolvedAddresses(info1, info2) | ||
if len(r2) != tt.expected { | ||
t.Errorf("Expected %d addresses, got %d", tt.expected, len(r2)) |
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.
nit: require.Len
would be useful here
@@ -735,6 +851,13 @@ func (n *P2PNetwork) txTopicHandleLoop() { | |||
// from gossipsub's point of view, it's just waiting to hear back from the validator, | |||
// and txHandler does all its work in the validator, so we don't need to do anything here | |||
_ = msg | |||
|
|||
// participation or configuration change, cancel subscription and quit | |||
if !n.wantTXGossip.Load() { |
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.
Hm, I'm not sure how often OnNetworkAdvance
can be called where it changes n.wantTXGossip
. If this runs less often than OnNetworkAdvance
, it's possible this routine won't notice swaps to n.wantTXGossip
and multiple routines could be listening. That could be addressed by storing the "config" version as an int and bailing out here if that version isn't what the routine was started with.
But in reality I'm assuming it will be very rare for n.wantTXGossip
to change?
Summary
This PR enables p2p relays by introducing a new gossip capability and preferring such peers for connection.
Gossip
peer from DHTGossip
peers when dialing. Ensure DHT subsystem maintains own peers and can connect to such DHT peers.relayMessages
conditionTest Plan
relayMessages
wantTXGossip
and gossip sub.