Skip to content

p2p: introduce Gossip peer capability#5935

Merged
algorandskiy merged 14 commits intoalgorand:feature/p2pfrom
algorandskiy:pavel/p2p-relay-dht
Feb 23, 2024
Merged

p2p: introduce Gossip peer capability#5935
algorandskiy merged 14 commits intoalgorand:feature/p2pfrom
algorandskiy:pavel/p2p-relay-dht

Conversation

@algorandskiy
Copy link
Copy Markdown
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
@codecov
Copy link
Copy Markdown

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
Copy Markdown
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.

Comment thread network/p2p/p2p.go
peerIDs := s.host.Peerstore().Peers()
for _, peerID := range peerIDs {
ps := s.host.Peerstore().(*pstore.PeerStore)
peerIDs := ps.GetAddresses(targetConnCount, phonebook.PhoneBookEntryRelayRole)
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread network/p2pNetwork.go
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
Copy Markdown
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
Copy Markdown
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

Comment thread network/p2pNetwork.go
// 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread network/p2pNetwork.go
}
var result []peer.AddrInfo
for _, addr := range unique {
result = append(result, *addr)
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Comment thread network/p2pNetwork.go
_ = msg

// participation or configuration change, cancel subscription and quit
if !n.wantTXGossip.Load() {
Copy link
Copy Markdown
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
@algorandskiy algorandskiy deleted the pavel/p2p-relay-dht branch March 16, 2026 20:06
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