Skip to content

feat(peer-store): introduce libp2p-peer-store #5724

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

Merged
merged 49 commits into from
Mar 4, 2025

Conversation

drHuangMHT
Copy link
Contributor

Description

Introduce libp2p-peer-store for a peer store implementation.

Related: #4103

Notes & open questions

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

@drHuangMHT
Copy link
Contributor Author

This is a very basic implementation, would love to hear more ideas on how to implement this!

Copy link
Member

@elenaf9 elenaf9 left a comment

Choose a reason for hiding this comment

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

Thanks for starting this effort @drHuangMHT!

If I understand the current implementation correctly, the purpose of this store is just to track connected peers, and explicitly added addresses. However, I think we have to keep in mind that protocols like kademlia or identify very frequently report all addresses that they learn as NewExternalAddrOfPeer. So with the current MemoryStore implementation, the store would grow unbounded with all of these addresses. I think there needs to be some GC strategy.

Also, after reading #4103 (comment), I think a peer store implementation could also do much more than just track explicitly added addresses, e.g.:

  • track how valuable a know address is, by using infos about how the address info was received, if we connected to it already, etc
  • implement a TTL for address records
  • track other meta data for a peer, e.g. public key

I don't think this needs to be implemented in this PR. But I think we could forward more of the already present info to the Store trait, so that a custom implementation can have more sophisticated logic.

@drHuangMHT
Copy link
Contributor Author

Oops that use<'a> syntax was stabilized in rust 1.82, the compiler on 1.80 wasn't happy with it.

Copy link
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

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

Thanks for starting this @drHuangMHT, already looking good! left some notes to allow further customization.
cc @elenaf9

 Store now handles FromSwarm directly; rename some on_* methods; allow removing address; update records on FromSwarm::ConnectionEstablished
@drHuangMHT
Copy link
Contributor Author

drHuangMHT commented Dec 16, 2024

  • track how valuable a know address is, by using infos about how the address info was received, if we connected to it already, etc

This can get very complicated very soon, for example how to record the activitiy on the address(there will be some overhead) and how to make it machine-readable(scoring system). The discussion will be quite lengthy.

  • implement a TTL for address records

I didn't see a good way to implement TTL(garbage collect) for records, any pointer?

  • track other meta data for a peer, e.g. public key

I don't see the remote public key being available through swarm itself, be it in the form of PeerRecord, SignedEnvelope or just PublicKey. But the pubkey is indeed a very important metadata of a peer.

@drHuangMHT
Copy link
Contributor Author

I forgot this very important reason why I want to support libp2p::core::PeerRecord(signed addresses) here in peer store: gossipsub PeerEXchange! So this is a series of PR preceding it: #5785 makes Identify a source of PeerRecord, this PR allow us to store it and I'm planning on one to enable the use of it in gossipsub.
@jxs thoughts?

Copy link
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

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

I forgot this very important reason why I want to support libp2p::core::PeerRecord(signed addresses) here in peer store: gossipsub PeerEXchange! So this is a series of PR preceding it: #5785 makes Identify a source of PeerRecord, this PR allow us to store it and I'm planning on one to enable the use of it in gossipsub.
@jxs thoughts?

Hi Dr Huang, can we do it on a subsequent PR?

Copy link
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

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

Ok almost ready to go Dr Huang, only missing removal of the serde code.
Thanks!

@drHuangMHT drHuangMHT marked this pull request as ready for review February 28, 2025 02:13
Copy link
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀 Thanks Dr Huang for starting this and the patience to drive it to the end! 🎆

@jxs jxs added the send-it label Mar 4, 2025
@mergify mergify bot merged commit 73383b8 into libp2p:master Mar 4, 2025
71 checks passed
@drHuangMHT drHuangMHT deleted the peer-store branch March 18, 2025 01:31
mergify bot pushed a commit that referenced this pull request Apr 11, 2025
When the `MemoryStore` receives a `FromSwarm::DialFailure` event, it will now modify the store appropriately:
- `LocalPeerId`: Remove the peer from the store.
- `WrongPeerId`: Remove the address for the dialed peer ID and readd it for the received peer ID.
- `Transport`: Remove the failed addresses from the store.
- other: no action.

Furthermore, we group some repeated event logic in a new function `push_event_and_wake` for internal use.

Follow-up to #5724

Pull-Request: #5926.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants