implement prune backoff for v1.1 spec#111
Conversation
Summary of ChangesHello @bomanaps, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request integrates the GossipSub v1.1 prune backoff mechanism, a critical enhancement for improving the stability and resilience of the pubsub network. The primary goal is to prevent rapid re-grafting by peers after they have been pruned, which helps in mitigating network churn and potential abuse. The implementation involves tracking backoff states for peers, enforcing these states during graft attempts, and ensuring that prune messages correctly communicate backoff durations, thereby aligning the system with the latest protocol specification. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request implements the prune backoff mechanism from the GossipSub v1.1 specification. While the overall approach for handling backoffs, including GRAFT messages and backoff information in PRUNE messages, is sound, a high-severity security vulnerability was identified. Specifically, the handling of incoming PRUNE messages allows an untrusted backoff value to cause an integer overflow and a process panic, leading to a Denial of Service. Furthermore, a critical memory safety issue exists in the backoff cleanup logic that could lead to a use-after-free. There are also medium-severity issues related to code duplication and a redundant entry in the .gitignore file. Addressing these points will significantly improve the robustness and security of the code.
| // GossipSub v1.1: Include backoff duration in PRUNE message | ||
| if (self.opts.gossipsub_v1_1) { | ||
| prune_msg[0] = .{ | ||
| .topic_i_d = topic, | ||
| .backoff = self.opts.prune_backoff_s, | ||
| .peers = null, // TODO: Implement peer exchange (PX) | ||
| }; | ||
|
|
||
| // Also add backoff for ourselves (both sides must respect backoff per spec) | ||
| const now_ms = std.time.milliTimestamp(); | ||
| const backoff_until_ms = now_ms + @as(i64, @intCast(self.opts.prune_backoff_s * 1000)); | ||
| self.addBackoff(topic, to.*, backoff_until_ms) catch |err| { | ||
| std.log.warn("failed to add backoff when pruning peer {} on topic {s}: {}", .{ to.*, topic, err }); | ||
| }; | ||
| } else { | ||
| prune_msg[0] = .{ | ||
| .topic_i_d = topic, | ||
| }; | ||
| } |
There was a problem hiding this comment.
This block duplicates the logic for creating a v1.1 PRUNE message and adding a backoff, which is also present in the makeControlMessage function. To improve maintainability and avoid code duplication, you can refactor this to use the makeControlMessage helper function.
prune_msg[0] = self.makeControlMessage(rpc.ControlPrune, topic, to.*);
|
@bomanaps can it be tested in a specific test? |
Add GossipSub v1.1 Prune Backoff
Implements the prune backoff mechanism from the GossipSub v1.1 spec. This prevents peers from re-grafting to mesh topics immediately after being pruned, reducing unnecessary churn and potential spam.