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

Fix: Own our CertifiedAddrBook #555

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

MarcoPolo
Copy link
Contributor

@MarcoPolo MarcoPolo commented Apr 17, 2024

This is blocked until the next go-libp2p release that includes libp2p/go-libp2p#2759, but please still review.

Fixes GossipSub's Peer Exchange (PX) after go-libp2p's change to stop consuming signed peer records into its Certified Address book.

I'll briefly summarize the problem and this solution here, but for more context please follow the links below.

The problem:

  • GossipSub's PX relied on go-libp2p's Identify consuming the signed peer record and inserting it into the host's peerstore.
  • go-libp2p's Identify was updated to avoid saving the signed peer records because:
    • They were not consumed anywhere. (by go-libp2p)
    • We need to filter the addresses to avoid polluting the address book with local addresses.
  • GossipSub's PX silently broke as it depended on an up to date CertifiedAddrBook on the host, but it was effectively unused.

The proposed solution in this PR:

  • Use the emitted events from go-libp2p to maintain gossipsub's own Certified Address Book.

A slightly more long term solution would be for go-libp2p to support services libp2p/go-libp2p#1993 that can provide resources that can be shared amongst other services/protocols. Imagine if two services needed a certified address book, then it would make sense to have a separate service that could provide an up to date address book.

For now potentially duplicating data if multiple services require a certified addr book seems like an okay solution.

Related though, is anyone aware of other protocols that depend on the host's certified address book?

Fixes libp2p/go-libp2p#2754
Related to: libp2p/go-libp2p#2355

gossipsub.go Show resolved Hide resolved
@@ -522,6 +529,45 @@ func (gs *GossipSubRouter) Attach(p *PubSub) {
}
}

func (gs *GossipSubRouter) manageAddrBook() error {

Choose a reason for hiding this comment

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

could we just not return anything?

Copy link
Collaborator

Choose a reason for hiding this comment

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

it should, the error is ignored anyway.

Copy link
Collaborator

@vyzo vyzo left a comment

Choose a reason for hiding this comment

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

looks reasonable, let me know when it is ready to merge.

Comment on lines +548 to +553
case event.EvtPeerIdentificationCompleted:
if ev.SignedPeerRecord != nil {
cab, ok := peerstore.GetCertifiedAddrBook(gs.cab)
if ok {
ttl := peerstore.RecentlyConnectedAddrTTL
if gs.p.host.Network().Connectedness(ev.Peer) == network.Connected {
Copy link
Member

Choose a reason for hiding this comment

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

This API will also be confusing for users :(

Copy link
Member

@sukunrt sukunrt Apr 25, 2024

Choose a reason for hiding this comment

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

I think for all events we need to do host.Network().Connectedness(peer) checks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe this event should have a Connectedness method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Open question (for me): Can we be sure that a ConnectednessChange == Connected event will always happen before a EvtPeerIdentificationCompleted event?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(yes)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can improve this API, but that shouldn't block this fix. Let's do this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Identify protocol: SignedPeerRecords not being added to the CertifiedAddrBook
4 participants