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

Fix network in order event #452

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Catrya
Copy link
Collaborator

@Catrya Catrya commented Feb 22, 2025

fix #435
Now in order event 38383 the network that comes out is the correct one: mainnet, regtest, etc

Summary by CodeRabbit

  • New Features

    • Integrated real-time Lightning Network status into the order processing flow, ensuring event tags now reflect the current network state.
  • Refactor

    • Streamlined the process for retrieving network status and generating dynamic tags, replacing previously static network values and improving error handling.

Now in orers event 38383 the network that comes out is the correct one
@Catrya
Copy link
Collaborator Author

Catrya commented Feb 22, 2025

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Feb 22, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

coderabbitai bot commented Feb 22, 2025

Walkthrough

This pull request integrates asynchronous fetching of the Lightning Network status into multiple order event workflows. A new function get_ln_status() is added to retrieve node information, which is then incorporated into the tagging process for orders. Several modules (app, main, util, and nip33) have been updated to call this function and pass the resulting status to order_to_tags(), replacing previous static or multi-step methods. Error handling for LN status retrieval remains in place while code formatting is slightly refined.

Changes

Files Change Summary
src/lightning/mod.rs Added new asynchronous function get_ln_status() and defined the LnStatus struct with a mapping method (from_get_info_response) to encapsulate node info.
src/app/release.rs, src/main.rs,
src/util.rs
Updated to use the new get_ln_status() call for retrieving LN status. Modified control flows in order event creation, publishing, and updating to pass the LN status to order_to_tags(). Formatting improvements in main.rs.
src/nip33.rs Modified the order_to_tags function signature to include an additional &LnStatus parameter. Updated logic to generate the "network" tag dynamically from LN status.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Order Workflow
    participant LN as Lightning Module
    participant Tag as order_to_tags Function

    Caller->>LN: await get_ln_status()
    LN-->>Caller: LnStatus / Error
    Caller->>Tag: order_to_tags(order, data, ln_status)
    Tag-->>Caller: Generated Tags
Loading

Possibly related PRs

Poem

I'm a rabbit with a code delight,
Hopping through async calls all day and night,
LN status joins the tagging race,
Bringing network charm to every place,
A skip and a hop, the code’s set right!
🐰💻


📜 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 298575e and fd02bbf.

📒 Files selected for processing (5)
  • src/app/release.rs (2 hunks)
  • src/lightning/mod.rs (1 hunks)
  • src/main.rs (2 hunks)
  • src/nip33.rs (2 hunks)
  • src/util.rs (3 hunks)
🔇 Additional comments (8)
src/main.rs (1)

21-21: LGTM! The changes improve code readability and maintainability.

The changes simplify the process of obtaining LN status by using a single function call instead of a two-step process. The error handling for setting the LN status remains unchanged, ensuring robustness.

Also applies to: 97-101

src/nip33.rs (1)

79-79: LGTM! The changes fix the network output in order events.

The dynamic network tag value is now correctly derived from the LN status instead of using a hardcoded value, addressing the issue mentioned in PR #435.

Also applies to: 111-111

src/lightning/mod.rs (1)

274-279: LGTM! The new function encapsulates LN status retrieval.

The get_ln_status() function provides a clean abstraction for retrieving LN status, making it easier to maintain and reuse across the codebase.

src/app/release.rs (1)

4-4: LGTM! The changes integrate LN status into order events.

The changes correctly integrate the LN status into the order event creation process, ensuring that network information is accurately reflected in the events.

Also applies to: 410-417

src/util.rs (4)

9-9: LGTM!

The import of get_ln_status from the lightning module is correctly added.


208-210: LGTM!

The Lightning Network status is correctly fetched before generating order tags, aligning with the PR's objective to fix network output in order events.


412-414: LGTM!

Similar to the publish_order function, the Lightning Network status is correctly fetched before updating the order event.


212-216:

✅ Verification successful

Verify error handling in upstream code.

The order_to_tags function now requires an additional ln_status parameter. While the changes here are correct, ensure that all other callers of this function have been updated accordingly.

Also applies to: 416-416


🏁 Script executed:

#!/bin/bash
# Description: Find all calls to order_to_tags to verify they've been updated with the new parameter

# Search for function calls
rg -A 3 'order_to_tags\(' --type rust

Length of output: 1069


All callers of order_to_tags appear correctly updated with the new ln_status parameter

  • The grep output confirms that in both src/app/release.rs and src/util.rs the function order_to_tags is invoked with the expected additional parameter.
  • Error handling upstream (e.g., mapping errors after event creation) is consistent and does not require further changes.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

@@ -271,6 +271,13 @@ impl LndConnector {
}
}

pub async fn get_ln_status() -> Result<LnStatus, MostroError> {
Copy link
Member

Choose a reason for hiding this comment

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

we don't need this function, let's keep using LN_STATUS static

@arkanoider
Copy link
Collaborator

arkanoider commented Feb 27, 2025

@Catrya as inspiration you could remove all modifications and just add this getter in nip33.rs:

use crate::LN_STATUS;

...

pub fn order_to_tags(order: &Order, reputation_data: Option<(f64, i64, i64)>) -> Tags {
    let ln_net_string = match LN_STATUS.get() {
        Some(status) => status.networks.join(","),
        None => "unknown".to_string(),
    };

    let mut tags: Vec<Tag> = vec![
        Tag::custom(
            TagKind::Custom(Cow::Borrowed("k")),
            vec![order.kind.to_string()],
        ),
        Tag::custom(
            TagKind::Custom(Cow::Borrowed("f")),
            vec![order.fiat_code.to_string()],
        ),
        Tag::custom(
            TagKind::Custom(Cow::Borrowed("s")),
            vec![order.status.to_string()],
        ),
        Tag::custom(
            TagKind::Custom(Cow::Borrowed("amt")),
            vec![order.amount.to_string()],
        ),
        Tag::custom(
            TagKind::Custom(Cow::Borrowed("fa")),
            create_fiat_amt_array(order),
        ),
        Tag::custom(
            TagKind::Custom(Cow::Borrowed("pm")),
            vec![order.payment_method.to_string()],
        ),
        Tag::custom(
            TagKind::Custom(Cow::Borrowed("premium")),
            vec![order.premium.to_string()],
        ),
        Tag::custom(
            TagKind::Custom(Cow::Borrowed("network")),
            vec![ln_net_string],
        ),
        Tag::custom(
            TagKind::Custom(Cow::Borrowed("layer")),
            vec!["lightning".to_string()],
        ),
        Tag::custom(
            TagKind::Custom(Cow::Borrowed("expiration")),
            vec![(order.expires_at + Duration::hours(12).num_seconds()).to_string()],
        ),
        Tag::custom(
            TagKind::Custom(Cow::Borrowed("y")),
            vec!["mostro".to_string()],
        ),
        Tag::custom(
            TagKind::Custom(Cow::Borrowed("z")),
            vec!["order".to_string()],
        ),
    ];

    // Add reputation data if available
    if reputation_data.is_some() {
        tags.insert(
            7,
            Tag::custom(
                TagKind::Custom(Cow::Borrowed("rating")),
                vec![create_rating_tag(reputation_data)],
            ),
        );
    }

    Tags::new(tags)
}

So you have just one central point to touch, I let you the tests! 😄

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.

3 participants