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.
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.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
does this solve the signature mismatch issue?
There was a problem hiding this comment.
yes, right now it can generate same signature with other implementations
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.