Skip to content

refactor: improve status output for v2 trees#1879

Merged
sergeytimoshin merged 1 commit intomainfrom
sergey/forester-status-v2
Jul 21, 2025
Merged

refactor: improve status output for v2 trees#1879
sergeytimoshin merged 1 commit intomainfrom
sergey/forester-status-v2

Conversation

@sergeytimoshin
Copy link
Contributor

@sergeytimoshin sergeytimoshin commented Jul 21, 2025

Summary by CodeRabbit

  • New Features

    • Console output for tree and queue information is now more detailed, providing batch-level statistics and summaries for different tree types.
    • Output formatting for forester assignments and tree info is simplified to a tab-separated format with clearer headers.
  • Improvements

    • Trees are now sorted by address before display, ensuring consistent ordering.
    • Reduced memory usage when processing tree data.
  • Bug Fixes

    • Removed unnecessary debug output from tree fullness calculations for cleaner logs.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 21, 2025

Walkthrough

The changes refactor the handling, sorting, and presentation of tree data and queue information in the forester system. Output formatting is simplified, tree sorting is standardized, and queue statistics reporting is made more detailed and type-specific. Several debug print statements are removed, and function signatures are updated for improved efficiency and clarity.

Changes

File(s) Change Summary
forester/src/forester_status.rs Trees are now sorted by their merkle_tree string, output formatting for assignments is simplified to tab-separated columns, and redundant cloning is reduced. Box-drawing table formatting is replaced with simpler headers.
forester/src/lib.rs run_queue_info now accepts a slice reference, sorts trees, and provides type-specific queue reporting with detailed Prometheus metrics.
forester/src/queue_helpers.rs Replaces queue length fetchers with functions that print detailed batch-level queue statistics and summaries, returning unprocessed item counts. Adds new function for input queue info.
forester/src/rollover/operations.rs Removes debug print statements from get_tree_fullness for cleaner output.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ForesterStatus
    participant Lib
    participant QueueHelpers

    User->>ForesterStatus: fetch_forester_status()
    ForesterStatus->>ForesterStatus: Fetch and sort trees by merkle_tree
    ForesterStatus->>Lib: run_queue_info(config, &sorted_trees, queue_type)
    Lib->>QueueHelpers: print_*_queue_info(rpc, pubkey)
    QueueHelpers-->>Lib: Print batch-level stats, return unprocessed count
    Lib-->>ForesterStatus: Print queue info, update metrics
    ForesterStatus-->>User: Print simplified assignments table
Loading

Estimated code review effort

3 (~45 minutes)

Poem

In the forest of code where the queues gently grow,
We sorted the trees so the data would flow.
Debug prints are gone, the output is clear,
Batch stats now sparkle—come gather near!
With tabs and with metrics, we hop on our way,
A rabbit’s neat garden at the end of the day. 🐇🌳


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2371981 and 857ce59.

📒 Files selected for processing (4)
  • forester/src/forester_status.rs (4 hunks)
  • forester/src/lib.rs (3 hunks)
  • forester/src/queue_helpers.rs (2 hunks)
  • forester/src/rollover/operations.rs (0 hunks)
💤 Files with no reviewable changes (1)
  • forester/src/rollover/operations.rs
🔇 Additional comments (11)
forester/src/forester_status.rs (4)

182-187: Excellent optimization - sorting trees once and reducing clones.

The refactoring to sort trees by merkle_tree string representation and collect them once is a good performance optimization that reduces cloning overhead when passing to run_queue_info.


192-196: Good change to pass trees by reference.

Converting run_queue_info calls to use borrowed slices (&trees) instead of cloning reduces memory overhead and improves performance.


199-209: Simplified output formatting improves readability.

The removal of square brackets and "Tree" prefix from the tree type display makes the output cleaner and more consistent with the overall formatting changes.


332-366: Tab-separated format is more machine-readable.

The change from box-drawing characters to tab-separated format improves both readability and machine parseability of the forester assignment output.

forester/src/lib.rs (3)

29-29: Good addition of itertools for sorting functionality.

Adding the itertools import to enable the sorted_by_key method is appropriate for the tree sorting requirements.


50-50: Excellent signature change to reduce cloning.

Changing the function parameter from Vec<TreeAccounts> to &[TreeAccounts] eliminates unnecessary cloning and improves performance.


70-145: Well-structured type-specific queue handling.

The refactored match statement provides excellent type-specific handling:

  • StateV1/AddressV1: Simple queue length reporting with appropriate constants
  • StateV2: Detailed append and nullify queue information with proper metric labeling
  • AddressV2: Comprehensive batch-level queue details

The separation of concerns and detailed output formatting significantly improve observability.

forester/src/queue_helpers.rs (4)

48-120: Excellent detailed output queue information function.

The print_state_v2_output_queue_info function provides comprehensive batch-level visibility:

  • Proper batch metadata extraction and processing
  • Detailed statistics calculation including completed vs pending operations
  • Clear summary output with total counts
  • Appropriate error handling for missing accounts

The logic for calculating pending operations and batch details is correct.


122-192: Comprehensive input queue information function.

The print_state_v2_input_queue_info function mirrors the output queue function well:

  • Consistent structure and formatting with the output queue function
  • Proper handling of merkle tree account data
  • Accurate calculation of nullify operation statistics
  • Clear differentiation in output labeling ("NULLIFY" vs "APPEND")

194-245: Well-implemented address queue information function.

The print_address_v2_queue_info function provides good visibility:

  • Appropriate use of DEFAULT_ADDRESS_ZKP_BATCH_SIZE constant
  • Simplified but sufficient batch detail reporting for address operations
  • Consistent error handling pattern
  • Clear output formatting

113-114: No division-by-zero risk in queue_helpers.rs
Both print_state_v2_output_queue_info and print_state_v2_input_queue_info initialize zkp_batch_size from non-zero defaults (500 and 250, respectively) and then overwrite it with on-chain metadata values that are validated at creation time to be > 0. Therefore total_unprocessed / zkp_batch_size cannot divide by zero.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

} else {
println!(
"│ {:9} │ {} │ UNASSIGNED (Eligible Index: {})",
"{:12}\t\t{}\tUNASSIGNED (Eligible Index: {})",
Copy link
Contributor

Choose a reason for hiding this comment

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

we could also use a table library for this, we use one in xtask

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have another idea. I want to remove this command entirely and instead create a small http server with a /status endpoint, so then, we could create a custom dashboard

@sergeytimoshin sergeytimoshin merged commit 0f49ddf into main Jul 21, 2025
21 checks passed
@sergeytimoshin sergeytimoshin deleted the sergey/forester-status-v2 branch July 21, 2025 22:20
@coderabbitai coderabbitai bot mentioned this pull request Jan 7, 2026
@coderabbitai coderabbitai bot mentioned this pull request Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants