Skip to content

fix(floodsub): use monotonic sequence numbers - #3672

Merged
tabcat merged 2 commits into
libp2p:mainfrom
tabcat:fix/floodsub-seqno-length
Oct 18, 2026
Merged

tabcat merged 2 commits into
libp2p:mainfrom
tabcat:fix/floodsub-seqno-length

Conversation

@tabcat

@tabcat tabcat commented Oct 18, 2026

Copy link
Copy Markdown
Member

Description

floodsub picked a random 64-bit sequence number for each message and encoded it with leading zero bytes removed, so about 1 in 256 messages went out with a sequence number shorter than 8 bytes. gossipsub peers using fallbackToFloodsub reject any sequence number that is not exactly 8 bytes, so those messages were dropped silently. This is also why the gossipsub fallbacks to floodsub publish tests time out intermittently.

The pubsub spec requires a linearly increasing 64-bit big-endian sequence number. floodsub now uses a counter seeded from the wall clock in nanoseconds, the same as gossipsub, go-libp2p and rust-libp2p. The seed is above 2^56, so the sequence number always encodes to 8 bytes, and it keeps increasing across restarts for validators that drop non-increasing sequence numbers.

Notes & open questions

  • Messages already sent by older floodsub versions keep their old encoding. Encoding and signature verification are unchanged, so nothing new is rejected.
  • randomSeqno is renamed to nextSeqno. It is internal (not in the package exports).

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

Seed the sequence number from the wall clock in nanoseconds and increment it, as the pubsub spec requires, instead of picking random values.
@tabcat
tabcat marked this pull request as ready for review October 18, 2026 18:08
@tabcat
tabcat requested a review from a team as a code owner October 18, 2026 18:08
@tabcat
tabcat merged commit aa5ba42 into libp2p:main Oct 18, 2026
34 checks passed
@tabcat tabcat mentioned this pull request Oct 18, 2026
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.

1 participant