-
-
Notifications
You must be signed in to change notification settings - Fork 451
fix: set finite gossipsub decode limits for control messages #9117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: unstable
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -179,6 +179,19 @@ export class Eth2Gossipsub { | |||||||||||||||||||||||||||||||||||||
| // This should be large enough to not send IDONTWANT for "small" messages | ||||||||||||||||||||||||||||||||||||||
| // See https://github.com/ChainSafe/lodestar/pull/7077#issuecomment-2383679472 | ||||||||||||||||||||||||||||||||||||||
| idontwantMinDataSize: 16829, | ||||||||||||||||||||||||||||||||||||||
| // Protobuf decode limits to bound memory allocation from untrusted RPC messages. | ||||||||||||||||||||||||||||||||||||||
| // js-gossipsub defaults all limits to Infinity. Setting finite values provides | ||||||||||||||||||||||||||||||||||||||
| // defense-in-depth against resource exhaustion via crafted control messages. | ||||||||||||||||||||||||||||||||||||||
| // See: Lighthouse v8.1.3 security patches for analogous rust-libp2p fixes. | ||||||||||||||||||||||||||||||||||||||
| decodeRpcLimits: { | ||||||||||||||||||||||||||||||||||||||
| maxSubscriptions: 512, | ||||||||||||||||||||||||||||||||||||||
| maxMessages: 256, | ||||||||||||||||||||||||||||||||||||||
| maxIhaveMessageIDs: 200, | ||||||||||||||||||||||||||||||||||||||
| maxIwantMessageIDs: 200, | ||||||||||||||||||||||||||||||||||||||
| maxIdontwantMessageIDs: 2000, | ||||||||||||||||||||||||||||||||||||||
| maxControlMessages: 500, | ||||||||||||||||||||||||||||||||||||||
| maxPeerInfos: 100, | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+191
to
+199
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For better maintainability and readability, it's good practice to extract these magic numbers into named constants. This makes it easier to understand their purpose and to modify them in the future. You could define these constants at the top of the file, for example after Example: /** Well above the ~140 CL topics (global + attestation subnets + sync subnets + blob/column topics) */
const DECODE_RPC_MAX_SUBSCRIPTIONS = 512;
/** Generous for burst messages (attestations, blob sidecars) */
const DECODE_RPC_MAX_MESSAGES = 256;
// ... and so on for the other limits
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a single 7-value object literal with a descriptive comment block and a rationale table in the PR body, I think the inline values are clear enough. Extracting to file-level constants would roughly double the line count without adding much readability — the values are only referenced in this one place. Keeping as-is. |
||||||||||||||||||||||||||||||||||||||
| })(modules.libp2p.services.components) as GossipSubInternal; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if (metrics) { | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capping
maxIhaveMessageIDsandmaxIwantMessageIDsat200is likely too low for valid gossipsub traffic under mainnet load, where honest peers can include far more message IDs in a single IHAVE/IWANT control message. Because this cap is enforced during protobuf decoding, oversized-but-valid control messages are rejected before normal gossip handling, which can drop propagation and create avoidable peer churn. Please set these decode limits to values aligned with the protocol/runtime control-message maxima rather than a low fixed value.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
GossipsubMaxIHaveLength = 5000in js-gossipsub means honest peers can include up to 5000 message IDs in IHAVE/IWANT per heartbeat. A decode limit of 200 would silently truncate legitimate messages at the protobuf layer before the runtime caps apply. Raised both to 5000 in7a02bc2to align with the protocol constant.