Skip to content
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

[Networking] Enhance Gossipsub Resilience: Configurable Threshold for Invalid Topic IDs in Control Messages #5391

Merged
merged 13 commits into from
Feb 23, 2024

Conversation

kc1116
Copy link
Contributor

@kc1116 kc1116 commented Feb 14, 2024

This pull request mitigates the potential for false positives arising from edge cases in Gossipsub, specifically addressing scenarios where a node receives control messages containing apparently invalid topics (e.g., the node is not subscribed to the topic, subscription dissemination glitches, etc.). The enhancement introduces a configurable invalid-topic-id-threshold for graft, prune, and ihave control message topic validation. Now, an error is triggered only when the number of encountered invalid topic ids surpasses this configured threshold. Additionally, the PR includes XX_AboveThreshold and XX_BelowThreshold tests, ensuring that the dissemination of an invalid control message notification aligns with expectations based on whether the count is above or below the configured threshold.

Copy link
Contributor

@yhassanzadeh13 yhassanzadeh13 left a comment

Choose a reason for hiding this comment

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

🚀

config/default-config.yml Outdated Show resolved Hide resolved
config/default-config.yml Outdated Show resolved Hide resolved
config/default-config.yml Outdated Show resolved Hide resolved
config/default-config.yml Outdated Show resolved Hide resolved
c.metrics.OnInvalidTopicIdDetectedForControlMessage(p2pmsg.CtrlMsgGraft)
return err, ctrlMsgType
if totalInvalidTopicIdErrs > c.config.GraftPrune.InvalidTopicIdThreshold {
return err, ctrlMsgType
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider returning a specific error type (e.g., ErrInvalidTopicIdExceedThreshold) instead of using the generic error from validateTopics. This approach provides clearer context, indicating misbehavior from exceeding the threshold, rather than signaling a single invalid topic. This also aligns with our general approach on returning an error when exceeding threshold, e.g., for duplicate topic ids we already have:

			if totalDuplicateTopicIds > c.config.GraftPrune.DuplicateTopicIdThreshold {
				c.metrics.OnGraftDuplicateTopicIdsExceedThreshold()
				return NewDuplicateTopicErr(topic.String(), totalDuplicateTopicIds, p2pmsg.CtrlMsgGraft), p2p.CtrlMsgNonClusterTopicType
			}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

c.metrics.OnInvalidTopicIdDetectedForControlMessage(p2pmsg.CtrlMsgPrune)
return err, ctrlMsgType
if totalInvalidTopicIdErrs > c.config.GraftPrune.InvalidTopicIdThreshold {
return err, ctrlMsgType
Copy link
Contributor

@yhassanzadeh13 yhassanzadeh13 Feb 17, 2024

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

c.metrics.OnInvalidTopicIdDetectedForControlMessage(p2pmsg.CtrlMsgIHave)
return err, ctrlMsgType
if totalInvalidTopicIdErrs > c.config.IHave.InvalidTopicIdThreshold {
return err, ctrlMsgType
Copy link
Contributor

@yhassanzadeh13 yhassanzadeh13 Feb 17, 2024

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yhassanzadeh13 yhassanzadeh13 changed the title Khalil/6934 Invalid Topic ID Threshold [Networking] Enhance Gossipsub Resilience: Configurable Threshold for Invalid Topic IDs in Control Messages Feb 17, 2024
kc1116 and others added 6 commits February 21, 2024 09:36
Co-authored-by: Yahya Hassanzadeh, Ph.D. <yhassanzadeh@ieee.org>
Co-authored-by: Yahya Hassanzadeh, Ph.D. <yhassanzadeh@ieee.org>
Co-authored-by: Yahya Hassanzadeh, Ph.D. <yhassanzadeh@ieee.org>
Co-authored-by: Yahya Hassanzadeh, Ph.D. <yhassanzadeh@ieee.org>
@kc1116 kc1116 enabled auto-merge February 21, 2024 15:38
@codecov-commenter
Copy link

codecov-commenter commented Feb 21, 2024

Codecov Report

Attention: Patch coverage is 30.57851% with 84 lines in your changes are missing coverage. Please review.

Project coverage is 55.98%. Comparing base (514461a) to head (3e393bb).

Files Patch % Lines
...dule/metrics/gossipsub_rpc_validation_inspector.go 0.00% 57 Missing ⚠️
module/metrics/noop.go 0.00% 19 Missing ⚠️
network/netconf/flags.go 20.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5391      +/-   ##
==========================================
- Coverage   55.99%   55.98%   -0.01%     
==========================================
  Files        1026     1026              
  Lines       99815    99902      +87     
==========================================
+ Hits        55894    55933      +39     
- Misses      39627    39674      +47     
- Partials     4294     4295       +1     
Flag Coverage Δ
unittests 55.98% <30.57%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kc1116 kc1116 added this pull request to the merge queue Feb 23, 2024
Merged via the queue into master with commit 8f4ecc4 Feb 23, 2024
49 of 51 checks passed
@kc1116 kc1116 deleted the khalil/6934-invalid-topicid-threshold branch February 23, 2024 01:49
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.

4 participants