Skip to content

feat: implement snappy for gossip objects follow the spec#240

Merged
g11tech merged 2 commits intoblockblaz:mainfrom
GrapeBaBa:snappy
Sep 27, 2025
Merged

feat: implement snappy for gossip objects follow the spec#240
g11tech merged 2 commits intoblockblaz:mainfrom
GrapeBaBa:snappy

Conversation

@GrapeBaBa
Copy link
Copy Markdown
Member

This pull request introduces Snappy compression support for network message handling in the ethlibp2p Zig module. The main changes include integrating the zig-snappy dependency, updating the build system to support it, and modifying message serialization and deserialization to use Snappy compression and decompression. This improves network efficiency and robustness by compressing outgoing messages and handling decompression errors gracefully.

Fix #219

Signed-off-by: Chen Kai <281165273grape@gmail.com>
Copilot AI review requested due to automatic review settings September 27, 2025 06:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces Snappy compression support for gossip objects in the ethlibp2p network module to follow the specification. The implementation adds compression for outgoing messages and decompression for incoming messages, improving network efficiency and robustness.

  • Integrates the zig-snappy dependency for compression/decompression functionality
  • Updates message handling to compress outgoing gossip messages before publishing
  • Adds decompression of incoming messages with proper error handling and debug logging

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
pkgs/network/src/ethlibp2p.zig Implements Snappy compression/decompression for gossip message handling
build.zig.zon Adds zig-snappy dependency configuration
build.zig Integrates snappyz module into the build system

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +204 to +211
defer serialized.deinit();
try ssz.serialize(types.SignedBeamBlock, data.block, &serialized);

break :blockbytes serialized.items;
break :blockbytes try serialized.toOwnedSlice();
},
.vote => votebytes: {
var serialized = std.ArrayList(u8).init(self.allocator);
defer serialized.deinit();
Copy link

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

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

Using defer serialized.deinit() followed by serialized.toOwnedSlice() is incorrect. The toOwnedSlice() method transfers ownership of the memory to the caller and clears the ArrayList, so the subsequent deinit() call will attempt to free already-transferred memory. Remove the defer serialized.deinit() line since toOwnedSlice() handles the cleanup.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

that is wrong, toOwnedSlice() allocated a new memory

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

actually toOwnedSlice does clear the memory as well so deinit is unnecessary but not harmful either
image

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, got it. unnecessary to call

Comment on lines +204 to +211
defer serialized.deinit();
try ssz.serialize(types.SignedBeamBlock, data.block, &serialized);

break :blockbytes serialized.items;
break :blockbytes try serialized.toOwnedSlice();
},
.vote => votebytes: {
var serialized = std.ArrayList(u8).init(self.allocator);
defer serialized.deinit();
Copy link

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

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

Using defer serialized.deinit() followed by serialized.toOwnedSlice() is incorrect. The toOwnedSlice() method transfers ownership of the memory to the caller and clears the ArrayList, so the subsequent deinit() call will attempt to free already-transferred memory. Remove the defer serialized.deinit() line since toOwnedSlice() handles the cleanup.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

that is wrong, toOwnedSlice() allocated a new memory

@g11tech g11tech merged commit 0fdae08 into blockblaz:main Sep 27, 2025
7 checks passed
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.

snappy encode/decode gossip objects

3 participants