Skip to content

fix(floodsub): apply decode limits and clean up the topic map#3568

Merged
tabcat merged 1 commit into
libp2p:mainfrom
tabcat:fix/floodsub-rpc-decode-limits
Jul 16, 2026
Merged

fix(floodsub): apply decode limits and clean up the topic map#3568
tabcat merged 1 commit into
libp2p:mainfrom
tabcat:fix/floodsub-rpc-decode-limits

Conversation

@tabcat

@tabcat tabcat commented Jul 15, 2026

Copy link
Copy Markdown
Member

Description

@libp2p/floodsub now bounds how many elements a single inbound RPC frame decodes into, and tidies up some peer/topic bookkeeping.

  • Decode limits. Incoming RPCs are decoded with configurable element caps via a new decodeRpcLimits option (defaulting to 5000 subscriptions and 5000 messages per frame), so the number of elements decoded from one frame is bounded. This uses @libp2p/utils pbStream's decode-options support.
  • Drop the unused control block. floodsub's RPC proto still carried gossipsub's ControlMessage (field 3), which floodsub never reads. It is removed (the field is reserved), so an inbound control block is skipped as an unknown field rather than decoded and discarded.
  • Topic map bookkeeping. Empty peer sets are removed from the topic map on unsubscribe and peer removal, and the map is cleared on stop(), matching @libp2p/gossipsub.
  • Peer teardown on inbound error. When a peer's inbound stream errors, the peer is now closed and removed instead of being left with a dead inbound stream.

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

Passes configurable decode limits to the inbound RPC decoder and drops the unused gossipsub control block from the wire proto so it is skipped rather than decoded. Closes the peer when its inbound stream errors instead of leaving it half-open, and removes empty peer sets from the topic map on unsubscribe, peer removal and stop.
@tabcat
tabcat marked this pull request as ready for review July 16, 2026 15:05
@tabcat
tabcat requested a review from a team as a code owner July 16, 2026 15:05
@tabcat
tabcat merged commit fb9e8a7 into libp2p:main Jul 16, 2026
33 of 34 checks passed
@tabcat tabcat mentioned this pull request Jul 15, 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