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

p2p: introduce Gossip peer capability #5935

Merged
merged 14 commits into from
Feb 23, 2024

Conversation

algorandskiy
Copy link
Contributor

@algorandskiy algorandskiy commented Feb 12, 2024

Summary

This PR enables p2p relays by introducing a new gossip capability and preferring such peers for connection.

  • Add DHT capability
  • Update peerstore methods (and tests) to support AddInfo/multiaddrs
  • Query Gossip peer from DHT
  • Prefer Gossip peers when dialing. Ensure DHT subsystem maintains own peers and can connect to such DHT peers.
  • Added relayMessages condition
  • Do not send TX traffic to NPN nodes

Test Plan

  • Unit tests for relayMessages
  • Unit tests for wantTXGossip and gossip sub.
  • Unit test for gossip capability

@algorandskiy algorandskiy added Enhancement p2p Work related to the p2p project labels Feb 12, 2024
@algorandskiy algorandskiy self-assigned this Feb 12, 2024
Copy link

codecov bot commented Feb 13, 2024

Codecov Report

Attention: Patch coverage is 77.05882% with 39 lines in your changes are missing coverage. Please review.

Project coverage is 55.88%. Comparing base (2df76fd) to head (4ee6bb2).
Report is 3 commits behind head on feature/p2p.

Files Patch % Lines
network/p2pNetwork.go 79.02% 24 Missing and 6 partials ⚠️
network/p2p/p2p.go 12.50% 7 Missing ⚠️
network/p2p/peerstore/peerstore.go 93.75% 1 Missing ⚠️
network/p2p/pubsub.go 0.00% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@algorandskiy algorandskiy marked this pull request as ready for review February 15, 2024 23:18
Copy link
Contributor

@gmalouf gmalouf left a 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)
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 connecting via libp2p to known relays?

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 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)
Copy link
Contributor

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)
Copy link
Contributor

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?

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 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() {
Copy link
Contributor

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?

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 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.
Copy link
Contributor

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?

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 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)
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// 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))
Copy link
Contributor

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() {
Copy link
Contributor

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?

@algorandskiy algorandskiy merged commit ef82b2b into algorand:feature/p2p Feb 23, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement p2p Work related to the p2p project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants