Fix on some full privacy cases#446
Conversation
WalkthroughThis pull request updates the version of the Changes
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
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
Possibly related PRs
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 2
🔭 Outside diff range comments (1)
src/app/order.rs (1)
93-95: 🛠️ Refactor suggestionConsider 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
⛔ Files ignored due to path filters (1)
Cargo.lockis 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.
| update_user_trade_index(pool, event.sender.to_string(), trade_index) | ||
| .await | ||
| .map_err(|e| MostroInternalErr(ServiceError::DbAccessError(e.to_string())))?; |
There was a problem hiding this comment.
🛠️ 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.
| 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); | |
| } |
| update_user_trade_index(pool, event.sender.to_string(), trade_index) | ||
| .await | ||
| .map_err(|e| MostroInternalErr(ServiceError::DbAccessError(e.to_string())))?; |
There was a problem hiding this comment.
🛠️ 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.
| 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); | |
| } |
Summary by CodeRabbit
Chores
Bug Fixes