Skip to content

Fix on some full privacy cases#446

Merged
grunch merged 1 commit into
developfrom
fixes-trade-index
Feb 19, 2025
Merged

Fix on some full privacy cases#446
grunch merged 1 commit into
developfrom
fixes-trade-index

Conversation

@grunch

@grunch grunch commented Feb 19, 2025

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Chores

    • Updated a core dependency to version 0.6.27 for improved compatibility.
  • Bug Fixes

    • Enhanced order processing by streamlining validations and error handling.
    • Introduced default handling for missing trade indices under specific conditions, improving overall order reliability.

@coderabbitai

coderabbitai Bot commented Feb 19, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request updates the version of the mostro-core dependency in the Cargo.toml file and refines trade index handling across multiple modules. In src/app.rs, the validation condition for the trade index is simplified and the user creation check is adjusted. In src/app/order.rs, src/app/take_buy.rs, and src/app/take_sell.rs, the control flow is updated so that when the trade index is absent, a default of 0 is assigned if the sender matches the rumor’s public key; otherwise, an error is returned. There are no changes to public entity declarations.

Changes

File(s) Change Summary
Cargo.toml Updated mostro-core dependency version from 0.6.26 to 0.6.27.
src/app.rs Simplified trade index validation by directly checking for an index ≥ 1 and refined logic for new user creation based on a comparison of event sender and rumor public key.
src/app/order.rs, src/app/take_buy.rs, src/app/take_sell.rs Modified trade index handling: if absent, check if event sender equals rumor’s public key to assign a default value of 0; otherwise, return an error. Also updated calls to update the trade index.

Sequence Diagram(s)

sequenceDiagram
    participant M as MessageKind
    participant A as check_trade_index
    participant E as Event
    M->>A: Call trade_index()
    alt trade_index is >= 1
        A->>E: Proceed with trade validation
    else
        A->>A: Check if event.sender != event.rumor.pubkey
        alt Condition met
            A->>E: Initiate new user creation
        else
            A->>E: Return validation error
        end
    end
Loading
sequenceDiagram
    participant M as Message
    participant F as Order/Action Function
    participant U as update_user_trade_index
    M->>F: Send order with trade_index (or None)
    alt trade_index is present
        F->>U: Update trade_index using provided value
    else
        F->>F: Check if event.sender == event.rumor.pubkey
        alt Sender matches
            F->>U: Update using default trade_index (0)
        else
            F->>F: Return InvalidPayload error
        end
    end
Loading

Possibly related PRs

Poem

I'm a rabbit with a clever twist,
Hop-ping through the code in a joyful mist.
Trade indexes now validated with care,
Defaulting to zero when the sender is there.
With codes aligned and features tight,
I celebrate these changes day and night! 🐰✨
Hop on, code wizards, let’s get it right!


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🔭 Outside diff range comments (1)
src/app/order.rs (1)

93-95: 🛠️ Refactor suggestion

Consider logging database errors instead of propagating them.

Align with the established pattern of logging rather than propagating errors from update_user_trade_index.

Apply this diff:

-    update_user_trade_index(pool, event.sender.to_string(), trade_index)
-        .await
-        .map_err(|e| MostroInternalErr(ServiceError::DbAccessError(e.to_string())))?;
+    if let Err(e) = update_user_trade_index(pool, event.sender.to_string(), trade_index).await {
+        tracing::error!("Failed to update user trade index: {}", e);
+    }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 825ba61 and 67638b9.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • Cargo.toml (1 hunks)
  • src/app.rs (2 hunks)
  • src/app/order.rs (1 hunks)
  • src/app/take_buy.rs (1 hunks)
  • src/app/take_sell.rs (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Cargo.toml
🧰 Additional context used
🧠 Learnings (1)
src/app.rs (1)
Learnt from: arkanoider
PR: MostroP2P/mostro#431
File: src/app.rs:115-118
Timestamp: 2025-02-09T11:32:27.570Z
Learning: In the `check_trade_index` function, errors from `update_user_trade_index` should only be logged and not propagated, as decided by the maintainer. This is to prevent disruption of the main flow for non-critical database updates.
🔇 Additional comments (5)
src/app/take_buy.rs (1)

66-76: LGTM! Improved trade index validation.

The new validation logic enhances robustness by properly handling cases where the trade index is missing, with a sensible default of 0 for self-trades.

src/app/order.rs (1)

81-90: LGTM! Consistent trade index validation.

The implementation follows the same robust pattern used in other handlers, ensuring consistent behavior across the codebase.

src/app/take_sell.rs (1)

85-94: LGTM! Consistent trade index validation.

The implementation maintains consistency with other handlers, ensuring uniform behavior across different trade actions.

src/app.rs (2)

109-109: LGTM! Simplified trade index validation.

The new pattern matching syntax index @ 1.. elegantly combines the existence check and value validation into a single condition.


157-157: LGTM! Improved user creation logic.

The refined condition ensures that new users are only created when necessary (trade index present and not a self-trade), making the logic more precise.

Comment thread src/app/take_buy.rs
Comment on lines +82 to +84
update_user_trade_index(pool, event.sender.to_string(), trade_index)
.await
.map_err(|e| MostroInternalErr(ServiceError::DbAccessError(e.to_string())))?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider logging database errors instead of propagating them.

Based on previous feedback, errors from update_user_trade_index should only be logged and not propagated to prevent disruption of the main flow.

Apply this diff to align with the established pattern:

-    update_user_trade_index(pool, event.sender.to_string(), trade_index)
-        .await
-        .map_err(|e| MostroInternalErr(ServiceError::DbAccessError(e.to_string())))?;
+    if let Err(e) = update_user_trade_index(pool, event.sender.to_string(), trade_index).await {
+        tracing::error!("Failed to update user trade index: {}", e);
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
update_user_trade_index(pool, event.sender.to_string(), trade_index)
.await
.map_err(|e| MostroInternalErr(ServiceError::DbAccessError(e.to_string())))?;
if let Err(e) = update_user_trade_index(pool, event.sender.to_string(), trade_index).await {
tracing::error!("Failed to update user trade index: {}", e);
}

Comment thread src/app/take_sell.rs
Comment on lines +112 to +114
update_user_trade_index(pool, event.sender.to_string(), trade_index)
.await
.map_err(|e| MostroInternalErr(ServiceError::DbAccessError(e.to_string())))?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider logging database errors instead of propagating them.

Align with the established pattern of logging rather than propagating errors from update_user_trade_index.

Apply this diff:

-    update_user_trade_index(pool, event.sender.to_string(), trade_index)
-        .await
-        .map_err(|e| MostroInternalErr(ServiceError::DbAccessError(e.to_string())))?;
+    if let Err(e) = update_user_trade_index(pool, event.sender.to_string(), trade_index).await {
+        tracing::error!("Failed to update user trade index: {}", e);
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
update_user_trade_index(pool, event.sender.to_string(), trade_index)
.await
.map_err(|e| MostroInternalErr(ServiceError::DbAccessError(e.to_string())))?;
if let Err(e) = update_user_trade_index(pool, event.sender.to_string(), trade_index).await {
tracing::error!("Failed to update user trade index: {}", e);
}

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.

1 participant