eg/1130-add-gossipsub-comparison-and-standalone-examples#1139
eg/1130-add-gossipsub-comparison-and-standalone-examples#1139Winter-Soren wants to merge 21 commits intolibp2p:mainfrom
Conversation
…2.0 showcase with peer scoring, adaptive gossip, and security features
…files with examples
…s' of https://github.com/Winter-Soren/py-libp2p into eg/1130-add-gossipsub-comparison-and-standalone-examples
…ype checking errors in gossipsub examples
|
Missing:
[v1.1]
|
…lty in gossipsub 1.0 and 1.1 examples
Hey @IronJam11, Thank you for flagging this!
Fanout (v1.0) and P6/P7 + PX + prune backoff + app score (v1.1) are now covered. |
|
@Winter-Soren , @IronJam11 : Hi friends. Appreciate the efforts. The PR does an excellent job of making the evolution of Gossipsub (v1.0 → v2.0) tangible through well-structured, runnable examples, something that has been missing in py-libp2p for a while. The multi-version comparison, scenario-based simulations (churn, spam, partitions), and especially the interactive v2.0 showcase with peer scoring and adaptive gossip provide real educational and debugging value for both new and experienced contributors. It’s also great to see the feedback loop handled so well, fanout behavior in v1.0 and the inclusion of P6/P7, PX, prune backoff, and optional app scoring in v1.1 really strengthen the completeness and accuracy of the examples. The attention to concurrency (trio nursery management), error handling, and metrics output makes this not just illustrative but practically usable. I’m aligned with the approach to scope this PR to all versions except v1.3 and take that up separately to avoid blocking the release. This is in a very good state to land once the final check clears, would be great to get this merged ahead of the upcoming release. |
…path to run the examples
|
Added Discussion page #1297, which explains the differences among all Gossipsub versions, along with instructions on how to run these examples. |
|
Hi @seetadev @pacrob @acul71 @sumanjeet0012 @yashksaini-coder |
yashksaini-coder
left a comment
There was a problem hiding this comment.
Thanks for putting this together @Winter-Soren — the educational progression from v1.0 through v2.0 is genuinely useful and this has been missing from py-libp2p for a while. The per-version feature checklists and the companion discussion (#1297) are nice touches.
That said, I've flagged a few things that need attention before this can be merged. The big ones are: missing newsfragment (project policy blocker), heavy code duplication across the 6 example files, and the v2.0 example implying a standardized protocol that doesn't exist in the spec. Details inline below.
Also the commit history still needs squashing (21 commits with 9 merge commits) — the PR TODO has this unchecked too.
| logger = logging.getLogger("gossipsub-v2.0") | ||
|
|
||
| # Protocol version | ||
| GOSSIPSUB_V20 = TProtocol("/meshsub/2.0.0") |
There was a problem hiding this comment.
This protocol ID /meshsub/2.0.0 doesn't exist in the libp2p spec — the official GossipSub spec only goes up to v1.2. py-libp2p has this constant internally but the example's docstring reads like v2.0 is a standardized thing with distinct features like "equivocation detection" and "eclipse attack protection via IP diversity", which are really just v1.4 features repackaged.
This will confuse users who look at the spec and can't find v2.0 anywhere. Can you either:
- Add a clear disclaimer at the top of the docstring: "Note: GossipSub 2.0 is an experimental/internal protocol version in py-libp2p, not part of the official libp2p specification"
- Or drop this file and end the progression at v1.4
What do you think?
| self.messages_sent = 0 | ||
| self.messages_received = 0 | ||
|
|
||
| async def start(self): |
There was a problem hiding this comment.
This entire method body (start, publish_message, receive_messages, connect_to_peer) is copy-pasted nearly identically across all 6 version files. Same for the Demo class (setup_network, start_network, _connect_nodes, _print_statistics, main). I diffed v1.0 against v1.1 and the method signatures are identical — only the GossipSub constructor args change.
That's roughly 200+ lines of boilerplate repeated 6 times. If anything in the demo infra needs fixing (say, the connection logic or nursery management), you'd have to patch all 6 files.
Would you consider extracting a shared BaseGossipsubNode + BaseGossipsubDemo that each version file subclasses? Each file would then only need to override the GossipSub config and the feature checklist printout — maybe 40-60 lines per version instead of 300-550. Happy to help sketch this out if useful.
| self.pubsub = Pubsub(self.host, self.gossipsub) | ||
|
|
||
| # Start services | ||
| import multiaddr |
There was a problem hiding this comment.
Minor: import multiaddr is inside the method body here and in connect_to_peer(). In the v1.3 and v1.4 examples it's imported at module level. Should be consistent — move it to the top with the other imports.
| print(" (node_0 is fanout-only: publishes via fanout, not in mesh)") | ||
| print(f"{'=' * 60}\n") | ||
|
|
||
| while time.time() < end_time: |
There was a problem hiding this comment.
time.time() in a trio async context can drift since trio has its own clock. Consider using trio.current_time() with relative deadline tracking, or just count iterations — it's more idiomatic for trio code.
| print("Protocol: /meshsub/1.1.0") | ||
| print( | ||
| "Features: Peer scoring (P1-P7), prune backoff, peer exchange (PX)," | ||
| "optional app score" |
There was a problem hiding this comment.
Looks like there's a missing space before "optional app score" — the string concatenation drops it:
"Features: Peer scoring (P1-P7), prune backoff, peer exchange (PX),"
"optional app score"Should be "...PX), " with a trailing space, or ", optional app score".
|
|
||
| await sparse_connect(hosts, degree) | ||
| await trio.sleep(0.1) # Allow connections to establish | ||
| # Match test_sparse_connect / test_dense_connect_fallback: pubsub streams need |
There was a problem hiding this comment.
This test fix (sleep 0.1s → 2s for CI stability) makes sense but it's unrelated to the gossipsub examples. Would be cleaner as its own 1-line PR so it can land independently without waiting for the examples review to finish. Up to you though, not blocking on this.
Implements comprehensive examples showcasing Gossipsub protocol evolution (v1.0-v2.0) with interactive demonstrations of peer scoring, adaptive gossip, and security features.
What was wrong?
Issue #1130
The py-libp2p did not have comprehensive examples demonstrating the differences between Gossipsub protocol versions and showcasing the advanced features of Gossipsub 2.0.
How was it fixed?
Created a complete example suite in
examples/pubsub/gossipsub/with three main components:1. Multi-Version Comparison Demo (
version_comparison.py)2. Gossipsub 2.0 Feature Showcase (
v2_showcase.py)3. Convenient Runner Script (
run_examples.py)Key Technical Fixes:
To-Do
Cute Animal Picture