-
Notifications
You must be signed in to change notification settings - Fork 27
forkchoice grafana visualization #426
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@g11tech Current design allows the observability API to briefly hold shared locks. Should we add rate limiting to prevent potential write starvation from excessive requests, or is the max slot cap sufficient? |
pkgs/cli/src/api_server.zig
Outdated
| var global_chain: ?*node.BeamChain = null; | ||
| var chain_mutex = std.Thread.Mutex{}; | ||
|
|
||
| /// Register the chain for API access | ||
| pub fn registerChain(chain: *node.BeamChain) void { | ||
| chain_mutex.lock(); | ||
| defer chain_mutex.unlock(); | ||
| global_chain = chain; | ||
| } | ||
|
|
||
| /// Get the global chain reference | ||
| fn getChain() ?*node.BeamChain { | ||
| chain_mutex.lock(); | ||
| defer chain_mutex.unlock(); | ||
| return global_chain; | ||
| } |
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.
I don't see how mutex is helping us here, the variable is not being manipulated. Also I think it is better if we can supply the chain in context of SimpleMetricsServer itself.
pkgs/cli/src/api_server.zig
Outdated
| // Parse query parameters for max_slots (default: 50) | ||
| var max_slots: usize = 50; | ||
| if (std.mem.indexOf(u8, request.head.target, "?slots=")) |query_start| { | ||
| const slots_param = request.head.target[query_start + 7 ..]; |
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.
What is 7? I think you trying to skip bytes but there should be a better regex way to do it.
pkgs/cli/src/api_server.zig
Outdated
| } | ||
|
|
||
| // Cap max_slots to prevent resource exhaustion | ||
| if (max_slots > 200) max_slots = 200; |
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.
Why 200 and if we have set it as 50 before. also declare these variables on top as constants.
| const role = if (is_finalized) | ||
| "finalized" | ||
| else if (is_justified) | ||
| "justified" | ||
| else if (is_head) | ||
| "head" | ||
| else if (is_orphaned) | ||
| "orphaned" | ||
| else | ||
| "normal"; |
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.
You can set role in each blk code blocks above itself.
| else | ||
| 0.0; |
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.
won't this be the default value of f64 anyway
| } | ||
|
|
||
| /// Recursively builds a tree branch visualization | ||
| fn visualizeTreeBranch(allocator: Allocator, tree_lines: *std.ArrayListUnmanaged(u8), nodes: []const fcFactory.ProtoNode, node_idx: usize, depth: usize, prefix: []const u8, max_depth: ?usize) !void { |
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.
I think this can lead to unbounded recursion even with max_depth there can be malicious nodes that can supply us blocks at shallow heights which this function will continue to process. We should also have a limit on the number of nodes it can handle while trying to visualize the tree branch
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.
those blocks can only be in forkchoice if they are valid, so whatever is the prvention mechanism needs to come before that
pkgs/cli/src/api_server.zig
Outdated
| const node = @import("@zeam/node"); | ||
|
|
||
| // Global chain reference for API access | ||
| var global_chain: ?*node.BeamChain = null; |
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.
i dont like global chain, you should register the routes on the api server using the forkchoice instance, not even chain
Summary
Adds real-time fork choice tree visualization via
/api/forkchoice/graphendpoint with thread-safe snapshot mechanism that doesn't block consensus operations.Key Features
Visualization API
Thread Safety
Correctness Improvements
Security & Performance
Screenshot sample
NOTES