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

Add lightning node data to info event #408

Merged
merged 1 commit into from
Dec 27, 2024

Conversation

grunch
Copy link
Member

@grunch grunch commented Dec 27, 2024

Fix #333

Summary by CodeRabbit

  • New Features

    • Introduced functionality to retrieve and represent Lightning Network node information.
    • Added a static variable to store the status of the Lightning Network node.
    • Updated tag generation to include detailed Lightning Network status information.
  • Bug Fixes

    • Enhanced error handling for connection failures to the Lightning Network node.
  • Documentation

    • Updated method signatures and function logic to reflect changes in handling Lightning Network status.

Copy link
Contributor

coderabbitai bot commented Dec 27, 2024

Walkthrough

The pull request introduces enhancements to the Lightning Network node information retrieval and representation across multiple files. A new LnStatus struct is created to encapsulate node details, with modifications in src/lightning/mod.rs to add a method for fetching node information. The src/main.rs file now initializes a static LN_STATUS variable to store this information. Corresponding updates in src/nip33.rs and src/scheduler.rs adapt the existing code to utilize the new LnStatus structure for generating tags and event information.

Changes

File Changes
src/lightning/mod.rs - Added get_node_info method to LndConnector
- Introduced LnStatus struct with from_get_info_response method
- Updated import statements
src/main.rs - Added static LN_STATUS variable
- Updated main function to retrieve and store node information
src/nip33.rs - Modified info_to_tags function to use LnStatus
- Added new tags for Lightning Network node details
src/scheduler.rs - Added import for LN_STATUS
- Updated job_info_event_send to use LnStatus

Sequence Diagram

sequenceDiagram
    participant Main as Main Function
    participant LndConnector as LND Connector
    participant LnStatus as LN Status
    participant Static as LN_STATUS

    Main->>LndConnector: Create instance
    Main->>LndConnector: get_node_info()
    LndConnector-->>Main: GetInfoResponse
    Main->>LnStatus: from_get_info_response()
    LnStatus-->>Main: LnStatus instance
    Main->>Static: Store LnStatus
Loading

Poem

🐰 Lightning nodes, oh so bright,
Bits of info taking flight!
Status locked, secrets unfurled,
Rabbit's code reshapes the world 🌐
Connecting networks with delight! ⚡


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.

Copy link
Contributor

@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: 2

🧹 Nitpick comments (2)
src/nip33.rs (1)

186-213: Good layering of LN node details, but consider fallback for empty fields.
The code properly tags LN-related fields like version and alias. For improved robustness, you could set fallback values (e.g., "unknown") if any field (such as node_alias) is absent or empty.

src/lightning/mod.rs (1)

255-263: get_node_info method is straightforward but watch for large error messages.
Mapping errors directly to MostroError::LnNodeError is fine, though you might want to sanitize or shorten the original error messages for user readability.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1aac442 and 4f5fbab.

📒 Files selected for processing (4)
  • src/lightning/mod.rs (2 hunks)
  • src/main.rs (3 hunks)
  • src/nip33.rs (3 hunks)
  • src/scheduler.rs (2 hunks)
🔇 Additional comments (9)
src/nip33.rs (2)

137-137: Use of ln_status parameter for LN tags is a solid approach.
Switching from a mostro_pubkey parameter to a full LnStatus object clarifies that the function intends to incorporate multiple LN-related attributes into the tag set. This change aligns with the new LnStatus struct usage in other parts of the code.


147-147: Confirm environment variable presence and handle missing values.
Referencing env!("GIT_HASH") can raise an error at compile time if the variable is not defined. Ensure build scripts or environment setups are properly handling it.

src/lightning/mod.rs (3)

14-14: Import statements are well-scoped.
The addition of GetInfoRequest and GetInfoResponse is needed for the new retrieval functionality. No issues noted.


19-19: Ordering import is properly used for fee comparison logic.
No action needed since std::cmp::Ordering is already used for comparing amounts.


266-288: LnStatus struct is well-defined.
Storing chain info and URIs in vectors is beneficial for future expansions. Just confirm all fields in GetInfoResponse are relevant to avoid clutter.

src/main.rs (2)

19-19: LnStatus import recognized.
This import centralizes LN status for downstream usage. No issues noted.


36-36: Good use of OnceLock for LN status.
Ensures the LN status is set exactly once. This pattern is safer than global mutable statics.

src/scheduler.rs (2)

8-8: Static LN status import is consistent with updated design.
Importing LN_STATUS here centralizes LN node data retrieval. No issues noted.


78-79: Calls info_to_tags using LN data, ensuring real-time LN details.
This is a great improvement, providing LN node context in the published info.

Comment on lines +90 to +94
let ln_status = ln_client.get_node_info().await?;
let ln_status = LnStatus::from_get_info_response(ln_status);
if LN_STATUS.set(ln_status).is_err() {
panic!("No connection to LND node - shutting down Mostro!");
};
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ensure fallback if LN node is unreachable.
Currently, a panic is triggered if the LN status fails to set. Consider a more graceful fallback if node connectivity fails, e.g., partial operation mode.

@@ -69,13 +70,13 @@ async fn job_info_event_send() {
Err(e) => return error!("{e}"),
};
let interval = Settings::get_mostro().publish_mostro_info_interval as u64;

let ln_status = LN_STATUS.get().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Unwrapping LN_STATUS can panic if LN status was never set.
Consider logging or gracefully handling missing LN status rather than unwrap(), as the node may be offline.

@grunch grunch merged commit 5746830 into main Dec 27, 2024
2 checks passed
@grunch grunch deleted the issue-333_add-ln-node-data-to-info-event branch December 27, 2024 18:56
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.

In events 38383 says Network: Mainnet, even if it is not mainnet
1 participant