refactor: abstract help fn for justifications#213
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the justifications map handling in the process_attestations function by extracting the logic into two helper functions: loadJustificationsMap and flattenJustificationsMap. The changes improve code organization, memory management, and error handling while maintaining the same functionality.
Key changes:
- Extracted justifications map initialization into
loadJustificationsMaphelper function - Extracted justifications map flattening into
flattenJustificationsMaphelper function - Changed from managed to unmanaged hash map for more explicit memory control
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| try justifications.put(allocator, vote.target.root, targetjustifications); | ||
| break :targetjustifications targetjustifications; | ||
| }; | ||
|
|
||
| target_justifications[validator_id] = 1; | ||
| try justifications.put(vote.target.root, target_justifications); | ||
| try justifications.put(allocator, vote.target.root, target_justifications); |
There was a problem hiding this comment.
The put method for std.AutoHashMapUnmanaged requires only two parameters (key and value), but three parameters are being passed here. The allocator should not be passed to the put method directly.
| try justifications.put(allocator, vote.target.root, targetjustifications); | ||
| break :targetjustifications targetjustifications; | ||
| }; | ||
|
|
||
| target_justifications[validator_id] = 1; | ||
| try justifications.put(vote.target.root, target_justifications); | ||
| try justifications.put(allocator, vote.target.root, target_justifications); |
There was a problem hiding this comment.
The put method for std.AutoHashMapUnmanaged requires only two parameters (key and value), but three parameters are being passed here. The allocator should not be passed to the put method directly.
|
|
||
| std.debug.assert(end_idx <= state.justifications_validators.len); | ||
|
|
||
| justifications.put(allocator, blockRoot, state.justifications_validators[start_idx..end_idx]) catch |e| { |
There was a problem hiding this comment.
The put method for std.AutoHashMapUnmanaged requires only two parameters (key and value), but three parameters are being passed here. The allocator should not be passed to the put method directly.
| justifications.put(allocator, blockRoot, state.justifications_validators[start_idx..end_idx]) catch |e| { | |
| justifications.put(blockRoot, state.justifications_validators[start_idx..end_idx]) catch |e| { |
…blaz#198) * fix: make start node test friendly and fix several memory leak Signed-off-by: Chen Kai <281165273grape@gmail.com> * Update pkgs/types/src/lib.zig Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: fix more memory leak when error Signed-off-by: Chen Kai <281165273grape@gmail.com> * fix: fix one more error meory leak Signed-off-by: Chen Kai <281165273grape@gmail.com> * Update pkgs/cli/src/node.zig * Update pkgs/cli/src/main.zig * fix: flattening order (blockblaz#208) * update sig size to 4000 bytes as per spec (blockblaz#210) * fix: abstract away network args into a function Signed-off-by: Chen Kai <281165273grape@gmail.com> --------- Signed-off-by: Chen Kai <281165273grape@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: g11tech <develop@g11tech.io> Co-authored-by: Anshal Shukla <53994948+anshalshukla@users.noreply.github.com> Co-authored-by: g11tech <gajinder@zeam.in>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
0a00f67 to
c3b9e5b
Compare
Signed-off-by: Chen Kai <281165273grape@gmail.com>
Signed-off-by: Chen Kai <281165273grape@gmail.com>
|
to be merge and rebased on top of this PR: so this PR waits till that time |
This pull request refactors how the justifications map is handled in the
process_attestationsfunction oftransition.zig. The main improvements are the extraction of logic into helper functions for loading and flattening the justifications map, and making memory management more explicit and robust. These changes improve code readability, maintainability, and safety.Fix #182