enh/1231-add-gossipsub-1.3-support#1237
Draft
Winter-Soren wants to merge 17 commits intolibp2p:mainfrom
Draft
Conversation
…e function completions
149337d to
8af34e4
Compare
Contributor
|
@Winter-Soren , @IronJam11 : Neat progress, friends. Lets arrive at a good conclusion on this PR this week. Please resolve CI/CD issues too. This is a substantial and very thoughtful upgrade. Bringing full GossipSub v1.3 support (including proper Extensions handling, “at most once” semantics, misbehaviour scoring, and Topic Observation with immediate IHAVE notifications) is a big step forward for py-libp2p interoperability. The separation via I especially appreciate:
Once CI issues and merge conflicts are resolved, this will be a major milestone for pubsub maturity in py-libp2p. Strong progress 🚀 |
…o and Topic Observation, add safe_bytes_from_hex and fix tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
py-libp2p currently lacks full implementation of the GossipSub v1.3 specification (Extensions Control Message). The protocol ID
/meshsub/1.3.0is present and some extension plumbing exists, but the wire format, first-message semantics, and “at most once” rules from the spec are not satisfied. This issue tracks implementing v1.3 and the Topic Observation extension (from the ethresear.ch proposal) so that py-libp2p can interoperate with other implementations and support observing nodes that receive notifications without downloading full message copies.What was wrong?
Issue #1231 — py-libp2p did not fully implement the GossipSub v1.3 specification (Extensions Control Message) or the Topic Observation extension.
Gaps included:
rpc.protodid not match the spec: noControlExtensions(single message with optional fields per extension), and no Topic Observation / TestExtension messages.How was it fixed?
Spec-aligned protobuf: Updated
libp2p/pubsub/pb/rpc.prototo addControlExtensions(field 6 onControlMessage) withtopicObservationandtestExtensionplusControlObserve,ControlUnobserve, andTestExtensiononRPC. Regeneratedrpc_pb2.pyandrpc_pb2.pyi.Extensions state machine: Added
libp2p/pubsub/extensions.pywithPeerExtensions,ExtensionsState, andTopicObservationState.ExtensionsStatehandles:build_hello_extensions(peer_id, hello).First message injection: In
pubsub.py’s_handle_new_peer(), after building the hello packet, we call the router’sextensions_state.build_hello_extensions(peer_id, hello)when the router hasextensions_stateandsupports_v13_features(duck-typing +castfor type-checking). Only v1.3-capable routers add Extensions to the first message.GossipSub v1.3 wiring in
gossipsub.py: IntroducedPROTOCOL_ID_V13(/meshsub/1.3.0), included it inadd_peerand in protocol checks (e.g._get_in_topic_gossipsub_peers_from_minus). Router now hasextensions_stateandtopic_observation(TopicObservationState), initialised with optionalmy_extensions: PeerExtensions. Inhandle_rpc, we callextensions_state.handle_rpc(rpc, sender_peer_id)first for v1.3 peers, then dispatchhandle_observe/handle_unobservefor Topic Observation. Onremove_peer, we callextensions_state.remove_peer()andtopic_observation.remove_peer().Topic Observation behaviour: Subscribers record observers via
topic_observation.add_observer(topic, peer)on OBSERVE and remove them on UNOBSERVE. Inpublish(), after validating and caching a message, we call_notify_observers(topic_ids, msg_id)to send IHAVE to all observers of those topics immediately (not only at heartbeat). Addedemit_observe/emit_unobserveand the corresponding handlers; observers are only accepted when the peer advertised the Topic Observation extension.Misbehaviour on duplicate Extensions: When a peer sends Extensions and we already have their extensions, we call
_report_extensions_misbehaviour(peer_id), which usesscorer.penalize_behavior(peer_id, 1.0).Result: v1.3 protocol ID is supported, Extensions are sent only in the first message and at most once per peer, duplicate Extensions are penalised, and Topic Observation (OBSERVE/UNOBSERVE + immediate IHAVE to observers) is implemented, with a small set of well-scoped stub methods left for new contributors.
To-Do
Cute Animal Picture