p2p: introduce Gossip peer capability#5935
p2p: introduce Gossip peer capability#5935algorandskiy merged 14 commits intoalgorand:feature/p2pfrom
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
gmalouf
left a comment
There was a problem hiding this comment.
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.
this is connecting via libp2p to known relays?
There was a problem hiding this comment.
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.
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.
Shouldn't we be willing to connect to anyone, not just relays?
There was a problem hiding this comment.
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
| // 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.
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.
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.
should the eventually cover this?
There was a problem hiding this comment.
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.
nit: could use maps.Keys
| 50*time.Millisecond, | ||
| ) | ||
|
|
||
| // check netB did not receive the messages |
There was a problem hiding this comment.
| // 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.
nit: require.Len would be useful here
| _ = msg | ||
|
|
||
| // participation or configuration change, cancel subscription and quit | ||
| if !n.wantTXGossip.Load() { |
There was a problem hiding this comment.
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.
Gossippeer from DHTGossippeers when dialing. Ensure DHT subsystem maintains own peers and can connect to such DHT peers.relayMessagesconditionTest Plan
relayMessageswantTXGossipand gossip sub.