Skip to content

feat: GossipSub v1.4#1448

Merged
richard-ramos merged 3 commits intomasterfrom
gossipsub_v1_4
Jul 20, 2025
Merged

feat: GossipSub v1.4#1448
richard-ramos merged 3 commits intomasterfrom
gossipsub_v1_4

Conversation

@ufarooqstatus
Copy link
Copy Markdown
Contributor

@ufarooqstatus ufarooqstatus commented Jun 6, 2025

Added GossipSub v1.4 implementation. Specs proposal here.

Still need to complete the safety strategy (in next PR)

Requires the compile flag: -d:libp2p_gossipsub_1_4, although running nimble testpubsub does add the flag automatically.

@ufarooqstatus ufarooqstatus requested a review from a team as a code owner June 6, 2025 11:39
@richard-ramos richard-ramos changed the title Gossipsub v1 4 feat: GossipSub v1.4 Jun 10, 2025
@richard-ramos richard-ramos marked this pull request as draft June 11, 2025 18:22
Comment thread libp2p/protocols/pubsub/gossipsub.nim Outdated
heartbeat "Gossipsub Peer Bandwidth Tracking", 1.seconds:
for (topic, peers) in g.gossipsub.pairs:
for peer in peers.items:
peer.bandwidthTracking.update()
Copy link
Copy Markdown
Contributor Author

@ufarooqstatus ufarooqstatus Jun 12, 2025

Choose a reason for hiding this comment

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

If there's no traffic for a few seconds, bandwidth estimate moves to 0.

Actually, we are interested in estimating how fast a peer will transfer to us. Maybe we can use $\frac{messageSize}{downloadTime - preambleTime}$, and use EMA to maintain it
We won't need bandwithHeartbeat in that case

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we can just skip updating the EMA if the sample is 0, altho that will leave you with a bandwidth estimation that is even less precise if the node is not chatty.

But, if going with this formula you suggest, what does the downloadTime and preambleTime refer to?

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.

yes, sounds good. we just need a rough estimate.
Preamble time is whe we received preamble. download time is when we received complete message from the same peer

Copy link
Copy Markdown
Contributor Author

@ufarooqstatus ufarooqstatus Jun 15, 2025

Choose a reason for hiding this comment

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

We just want to be able to configure that we only issue IMRECEIVING on receiving preamble from top X % of peers


BandwidthTracking* = ref object
upload*: ExponentialMovingAverage
download*: ExponentialMovingAverage
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.

We just need to know how fast a remote peer can transfer to us, so upload can suffice

@richard-ramos richard-ramos force-pushed the gossipsub_v1_4 branch 6 times, most recently from 255acb2 to 448e929 Compare June 17, 2025 21:52
Comment on lines +15 to +16
if ps.byId.hasKey(msgId):
ps.byId[msgId].deleted = true
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 replaces the preamble info we are watching (for expiry with the new one). Potentially mesh may keep sending us preambles and we will keep updating this.

Although this never happens because we check for existing entries here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, this is to keep the functionaliyu of PreambleStore to behave the same as a Table, (altho it internally also has a minheap). Except for the popExpired function, you'll notice that the API and behavior matches that of a Table.

Comment thread libp2p/protocols/pubsub/gossipsub/receivestore.nim Outdated
)
),
isHighPriority = true,
)
Copy link
Copy Markdown
Contributor Author

@ufarooqstatus ufarooqstatus Jun 18, 2025

Choose a reason for hiding this comment

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

we still dont know if peers[0] has the required message. what if we store 2-3 mesh members from here and 2-3 non-memsh members from here to preambleInfo (maybe as meshList and IHaveList). That can be more efficient, as we won't need to fetch mesh members, and we also won't need topicID in preambleInfo

@richard-ramos richard-ramos force-pushed the gossipsub_v1_4 branch 4 times, most recently from 12ebbcd to 62b8c89 Compare June 24, 2025 21:51
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 78.13620% with 61 lines in your changes missing coverage. Please review.

Project coverage is 84.45%. Comparing base (848fdde) to head (62b8c89).
Report is 14 commits behind head on master.

Files with missing lines Patch % Lines
libp2p/protocols/pubsub/gossipsub/behavior.nim 66.01% 35 Missing ⚠️
libp2p/protocols/pubsub/rpc/messages.nim 7.14% 13 Missing ⚠️
...ibp2p/protocols/pubsub/gossipsub/preamblestore.nim 91.17% 6 Missing ⚠️
libp2p/protocols/pubsub/rpc/protobuf.nim 88.37% 5 Missing ⚠️
libp2p/protocols/pubsub/gossipsub.nim 94.44% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1448      +/-   ##
==========================================
- Coverage   84.91%   84.45%   -0.46%     
==========================================
  Files         103      109       +6     
  Lines       18129    18341     +212     
==========================================
+ Hits        15394    15490      +96     
- Misses       2735     2851     +116     
Files with missing lines Coverage Δ
libp2p/protocols/pubsub/bandwidth.nim 100.00% <100.00%> (ø)
libp2p/protocols/pubsub/pubsubpeer.nim 88.51% <100.00%> (+1.68%) ⬆️
libp2p/protocols/pubsub/gossipsub.nim 92.89% <94.44%> (+1.70%) ⬆️
libp2p/protocols/pubsub/rpc/protobuf.nim 85.83% <88.37%> (+0.55%) ⬆️
...ibp2p/protocols/pubsub/gossipsub/preamblestore.nim 91.54% <91.17%> (ø)
libp2p/protocols/pubsub/rpc/messages.nim 45.00% <7.14%> (-9.55%) ⬇️
libp2p/protocols/pubsub/gossipsub/behavior.nim 88.39% <66.01%> (-4.31%) ⬇️

... and 11 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@richard-ramos richard-ramos marked this pull request as ready for review July 8, 2025 20:58
Copy link
Copy Markdown
Contributor

@gmelodie gmelodie left a comment

Choose a reason for hiding this comment

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

I think this PR should be split into smaller ones as it was with AutoTLS

@richard-ramos
Copy link
Copy Markdown
Member

@gmelodie: I think this PR should be split into smaller ones as it was with AutoTLS

yeah. that's a good idea. @ufarooqstatus I'll work on this if that's okay

@richard-ramos
Copy link
Copy Markdown
Member

@gmelodie PR is now small enough for review after extracting part of it in #1513 and #1515

@richard-ramos richard-ramos force-pushed the gossipsub_v1_4 branch 2 times, most recently from b1f7cca to 491bb76 Compare July 12, 2025 19:36
Comment thread libp2p/protocols/pubsub/gossipsub.nim
Comment thread libp2p/protocols/pubsub/gossipsub/behavior.nim Outdated
Comment thread libp2p/protocols/pubsub/gossipsub/behavior.nim Outdated
Comment thread libp2p/protocols/pubsub/gossipsub/behavior.nim Outdated
Comment thread libp2p/protocols/pubsub/gossipsub/behavior.nim Outdated
Comment thread libp2p/protocols/pubsub/gossipsub/behavior.nim
@richard-ramos richard-ramos moved this from new to In Progress in nim-libp2p Jul 18, 2025
Comment thread tests/pubsub/integration/testgossipsubcontrolmessages.nim
Comment thread libp2p/protocols/pubsub/gossipsub.nim Outdated
ufarooqstatus and others added 3 commits July 20, 2025 14:27
…d safety strategy

Add preamble threshold
Add bandwidth tracking
fix: send preamble on publish only if using `sendIDontWantOnPublish` parameter
adjusted bandwidth tracking
feat: preamble store and heartbeat for expiration
chore: send IWANT to mesh peer in expiry heartbeat
chore: store peers in preambleinfo
chore: hide 1_4 behind compile flag `-d:libp2p_gossipssub_1_4`
added support for push operation

Add behavior penalty for failed preamble commitment
@richard-ramos richard-ramos enabled auto-merge (squash) July 20, 2025 18:28
@richard-ramos richard-ramos merged commit 6576c5c into master Jul 20, 2025
22 of 23 checks passed
@richard-ramos richard-ramos deleted the gossipsub_v1_4 branch July 20, 2025 18:47
@github-project-automation github-project-automation Bot moved this from In Progress to done in nim-libp2p Jul 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants