Skip to content
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

chore: cleanups to improve feedback #101

Merged
merged 3 commits into from
Feb 6, 2025

Conversation

abailly
Copy link
Contributor

@abailly abailly commented Feb 6, 2025

Summary by CodeRabbit

  • Refactor

    • Improved internal data handling for header management and chain selection to enhance overall clarity and consistency.
  • Chore

    • Enhanced logging during consensus events to provide more detailed contextual information for improved monitoring and debugging.
    • Updated method names for clarity in header storage and retrieval processes.

As we are automatically generating spans from method names, it's
better to have something more expressive than get/put :)

Signed-off-by: Arnaud Bailly <[email protected]>
Copy link

coderabbitai bot commented Feb 6, 2025

Walkthrough

This pull request standardises header storage and retrieval across several crates. In Amaru’s CLI tool and ChainStore trait implementations, the methods have been renamed from put/get to store_header/load_header. The ChainSelection enum’s SwitchToFork variant has been refactored into a struct with named fields to improve clarity. Additionally, consensus logging levels have been adjusted from INFO to DEBUG, with extra instrumentation added, and a new logging constant introduced. The overall control flow remains similar, with modifications primarily focusing on method signature updates and enhanced debugging output.

Changes

File(s) Change Summary
crates/amaru/src/bin/amaru/cmd/import_chain_db.rs Updated header storage in handle_response: replaced db.put() with db.store_header().
crates/amaru/src/sync/mod.rs Changed header retrieval: replaced chain_store.get() with chain_store.load_header() in make_chain_selector.
crates/consensus/src/consensus/chain_selection.rs Refactored SwitchToFork variant from tuple to a struct with named fields; updated roll_forward and rollback methods accordingly.
crates/consensus/src/consensus/mod.rs Adjusted logging levels to DEBUG; added new logging fields; updated usages of store_header and destructured ChainSelection.
crates/consensus/src/consensus/store.rs, …/store/rocksdb.rs Renamed trait and implementation methods: get/put became load_header/store_header while retaining the original functionality.

Sequence Diagram(s)

sequenceDiagram
    participant CMD as ImportChainDB Command
    participant DB as Database Store
    CMD->>DB: Call store_header(hash, header)
    alt Storage Failure
        DB-->>CMD: Return error
        CMD->>CMD: Trigger WorkerError::Panic
    else Successful Storage
        DB-->>CMD: Acknowledge success
    end
Loading
sequenceDiagram
    participant HS as HeaderStage (Consensus)
    participant CS as ChainStore
    participant CSel as ChainSelection
    participant Log as Logging System
    HS->>CS: Call load_header(hash)
    CS-->>HS: Return header
    HS->>CSel: Process header (roll_forward/rollback)
    CSel-->>HS: Return SwitchToFork struct (with peer, rollback_point, tip, fork)
    HS->>Log: Emit debug log with detailed instrumentation
Loading

Possibly related PRs

Suggested reviewers

  • KtorZ
  • jeluard

Poem

In our code’s vast grove a header takes flight,
From ‘put’ to ‘store_header’, shining ever so bright.
Logs now whisper secrets at a debugging sway,
With chains reformed and errors kept at bay.
Cheers to our refactors—smooth as a cuppa tea,
Dancing through code like a merry old jamboree!
Here’s to clarity and the brilliance of our day!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

@abailly abailly requested review from KtorZ and jeluard February 6, 2025 18:11
@@ -111,7 +113,10 @@ impl HeaderStage {
.or_panic()
}

#[instrument(level = Level::INFO, skip(self))]
#[instrument(level = Level::DEBUG, skip_all,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the switch back to DEBUG here? I thought that it's a significant enough (and occasional) event that it deserves being treated as log, no ?

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 thought this was a mistake as we/you changed all instrument to DEBUG.

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 really think we should not care about those levels in the code, but I will revert back to INFO

Copy link
Contributor

Choose a reason for hiding this comment

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

Funny enough, I went for DEBUG in ADR-007 because i didn't see that tracing had a TRACE level. So I will be switching those DEBUG to TRACE in an upcoming commit.

So that anything DEBUG/INFO will be treated as log. It'll be less confusing.

Still for this one, I really think it shouldn't be a trace, but a log. A debug one perhaps but as you said, I don't think we should care about those levels for logging. Every log as INFO is good IMO.

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 am having a hard time making a difference between logs and traces, they are one and the same thing. the difference happens downstream with the use you make of that information: you can ignore timing and treat the entry or exit of a function as a log, being interested in the discrete event this represents, or you can care about the duration, or perhaps the fact it raised and error, and/or the call tree it produced, with or without timings.

IMNSHO, those differences we make up-front are probably short-sighted and only breeds confusion and complexity in the code base. But I value more alignment within the team than opinion so I will make sure to read and follow the policy we agreed on in the ADR 👍

Copy link
Contributor

@KtorZ KtorZ Feb 6, 2025

Choose a reason for hiding this comment

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

We can summarize the difference simply:

  • logs = for humans
  • traces = for programs

As a human, I cannot process outputs on stdout when my terminal is flooded with thousands of lines per second. So of course, I can redirect the output, or export it to a sub-system for analysis/observability (which I believe is what you are advocating for).

But, it's also nice to have some readily available output meant for immediate human-consumption. Something which I need not to spin up an telemetry backend with a collector and a trace visualizer to make sense of (which I believe, you have also been advocating for 😅 ...).

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
crates/consensus/src/consensus/chain_selection.rs (2)

24-24: Fix typo in documentation.

There's a small typo in the doc comment: "sqeuence" should be "sequence". Just a wee fix needed there!


169-169: Consider adding block height to instrumentation.

The logging is good, but adding header.block_height() would give us the full picture. It's like having a pint without knowing how full it is!

-    #[instrument(level = Level::DEBUG, skip(self, header), fields(header.slot = header.slot(), header.hash = header.hash().to_string()))]
+    #[instrument(level = Level::DEBUG, skip(self, header), fields(header.slot = header.slot(), header.hash = header.hash().to_string(), header.height = header.block_height()))]
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fb9b7cf and 5567f89.

📒 Files selected for processing (2)
  • crates/consensus/src/consensus/chain_selection.rs (8 hunks)
  • crates/consensus/src/consensus/mod.rs (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/consensus/src/consensus/mod.rs
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build on windows-latest with target x86_64-pc-windows-msvc
🔇 Additional comments (6)
crates/consensus/src/consensus/chain_selection.rs (6)

18-18: LGTM! Clean import addition.

The tracing import is spot on for the new instrumentation changes.


100-105: Brilliant refactor to named fields!

This is a cracking improvement! Moving from tuple to struct format makes the code much more self-documenting. It's like going from "fish and chips in newspaper" to "fish and chips in a proper box with labels" - you know exactly what you're getting!


212-212: Spot on with the instrumentation!

The instrumentation matches the suggested format perfectly.


222-223: Consider implementing the intersection optimization.

The TODO comment flags a good optimization opportunity. Instead of always switching to the anchor point, finding the best intersection point could reduce unnecessary rollbacks. It's like taking the M25 when there's a shortcut through the city!

Would you like me to help create an issue to track this optimization task?


249-249: Nice consistent instrumentation!

Keeping the same instrumentation pattern across related methods. Good stuff!


346-354: Tests updated properly for the new struct format.

All test assertions have been properly updated to match the new SwitchToFork struct format. Good job keeping the tests in sync!

Also applies to: 458-466

@abailly abailly requested a review from KtorZ February 6, 2025 20:35
@abailly abailly merged commit 4bb7483 into main Feb 6, 2025
7 checks passed
@abailly abailly deleted the abailly/cleanups-to-improve-feedback branch February 6, 2025 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants