-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement saving ENR/s to file and loading ENR/s from file #1
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
Conversation
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
gballet
left a comment
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.
in function names, please rename Enr to ENR, this is an acronym.
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
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.
Pull Request Overview
This PR implements comprehensive file I/O functionality for Ethereum Node Records (ENR), enabling saving and loading of ENR data to/from disk. It provides both single and batch operations for different ENR types.
- Adds helper functions for single and batch ENR file operations with support for custom delimiters
- Re-exposes core ENR types (
ENR,EncodedENR,SignableENR) from the dependency module for convenient access - Includes comprehensive test coverage with error handling scenarios and various ENR formats
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/root.zig | Implements core ENR file I/O functions with comprehensive test suite |
| build.zig.zon | Configures project dependencies and metadata |
| build.zig | Sets up build configuration with dependency imports |
| README.md | Documents project usage, building, and testing instructions |
| .github/workflows/ci.yml | Adds CI pipeline for automated testing and formatting checks |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| pub fn loadEncodedENRFromDisk(encoded_enr: *EncodedENR, file_path: []const u8) !void { | ||
| var buffer: [enrlib.max_enr_size]u8 = undefined; | ||
| const content = try readFileContent(file_path, &buffer); | ||
| encoded_enr.* = try EncodedENR.decodeTxtInto(content); |
Copilot
AI
Aug 28, 2025
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.
The function name decodeTxtInto suggests it should decode into a provided parameter, but here it's returning a value. Consider using EncodedENR.decodeTxt(content) for consistency with the naming pattern, or update the function to match the ENR.decodeTxtInto pattern that takes a pointer parameter.
| encoded_enr.* = try EncodedENR.decodeTxtInto(content); | |
| encoded_enr.* = try EncodedENR.decodeTxt(content); |
| const trimmed = std.mem.trim(u8, enr_txt, " \t\r\n"); | ||
| if (trimmed.len == 0) continue; // Skip empty entries | ||
|
|
||
| const encoded_enr = try EncodedENR.decodeTxtInto(trimmed); |
Copilot
AI
Aug 28, 2025
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.
Same inconsistency as above - decodeTxtInto is returning a value rather than decoding into a provided parameter. This inconsistent API usage could confuse developers.
| try readTempEncodedEnr(&tmp_dir, test_file, &loaded_encoded_enr); | ||
|
|
||
| var enr: ENR = undefined; | ||
| loaded_encoded_enr.decodeIntoENR(&enr); |
Copilot
AI
Aug 28, 2025
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.
The function call decodeIntoENR appears to not handle potential errors with try. If this function can fail, it should be called with try loaded_encoded_enr.decodeIntoENR(&enr);
| loaded_encoded_enr.decodeIntoENR(&enr); | |
| try loaded_encoded_enr.decodeIntoENR(&enr); |
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
|
|
||
| .dependencies = .{ | ||
| .secp256k1 = .{ | ||
| .url = "git+https://github.com/zig-bitcoin/libsecp256k1-zig#b96922b375a601f3303bf43be1dceb3d101df6c6", |
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.
does this solve the signature mismatch issue?
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.
yes, right now it can generate same signature with other implementations
g11tech
left a comment
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.
lgtm
Motivition
This pull requests add helper functions to save ENR to file and load ENR from file. It providers both single ENR operation and batch ENRs operation.
Implementation
ENR,EncodedENRandSignableENRfrom the dependency module.EncodedENRonly should be used as readonly access.ENR,EncodedENRandSignableENR.