Develop branch merge to main#480
Conversation
* add feature to check correctly if order is full privacy or normal * 📝 Add docstrings to `feature-full-privacy-mode-checks` Docstrings generation was requested by @arkanoider. * #454 (comment) The following files were modified: * `src/app/order.rs` * `src/util.rs` --------- Co-authored-by: arkanoider <github.913zc@simplelogin.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: arkanoider <113362043+arkanoider@users.noreply.github.com>
Now in orers event 38383 the network that comes out is the correct one
* remove of anyhow dependency start * removed anyhow dependecy * remove patch from cargo.toml * Update mostro-core version --------- Co-authored-by: Francisco Calderón <fjcalderon@gmail.com>
* Feature: dispute fix for new logic * fix for coop cancel case * Add logic for info message about dispute for solver * first working dispute info message for admin after taking disputes * added fields to dispute info message for solver * removed some probably useless and refactored a bit admin-take-dispute function * clippy suggestion * other cosmetics to admin take file * some other cosmetics on admin-take-dispute file * fix on admin-take * Update admin_take_dispute.rs * fixed a wrong search of order id in admin take file@ * Fix: added correct check to add solver from admin cli * fix: wrong check on admin cancel * Fix initiator pubkey: now is the trade key of initiator not identity * quick fix for full privacy orders * new logic with mixed full privacy - regular reputation mode * Update cargo toml to compile with version 0.6.32 of mostro-core - this is in preparation for migrating to nostr-sdk 0.40 * rollback sdk to 0.38 version to merge disputes - we will come back to 0.40 when we will fix signature issue * Update mostro-core dependency --------- Co-authored-by: Francisco Calderón <fjcalderon@gmail.com>
…r payment failure (#462)
* testing sdk 40 * fix for sdk 40 * cleaned cargo.toml * Bump mostro core version --------- Co-authored-by: Francisco Calderón <fjcalderon@gmail.com>
…nvoice when there is a preimage (#464)
* feature: align to nip69 order status in nostr event * Improved in progress nip69 logic * refined event states of the order with nip69 request * add another check to avoid multiple events with in-progress state
* add optional field for users in full privacy inside solver message * To be tested - privacy range child order fix * fix cargo.toml * bumped mostro-core version to 6.35
* new user or privacy order send same user info with zeros * fix days field and removed some println! macro with nicer tracing messages * bumped mostro-core version to 6.36 and added requested fix to compile
* add previous state in database for solver message * bumped mostro-core version to 6.36
I think that could be modifies in a more generic UserInfo. (#473) * added logic to send infos to maker when an order is taken * Add takers info message for maker * fix cargo.toml * set peer pubkey to empty string when notifying taker reputation to maker * moved user info message to the right point of the order flow * fix cargo.toml * changed message struct from UserDisputeInfo to UserInfo * fix: get master keys for user infos * Bumped mostro-core to version 6.38
WalkthroughThis pull request introduces a comprehensive refactor and enhancement of error handling, dependency management, and control flow across the codebase. The generic Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant App
participant DB
participant Nostr
participant LN
User->>App: Sends message (e.g., add invoice, dispute)
App->>DB: Query/update order/dispute/user
App->>LN: (If needed) Interact with Lightning node
App->>Nostr: Publish event or send DM (with tags)
App->>App: Notify taker reputation (if applicable)
App->>User: Respond/acknowledge via Nostr
Possibly related PRs
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 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: 8
🔭 Outside diff range comments (4)
src/app.rs (1)
316-334: 🛠️ Refactor suggestionSignature is skipped when sender == rumor pubkey – verify anyway
Current logic only verifiessigwhensender ≠ rumor. An attacker controlling the relay could still forge aGiftWrapwithsender == rumorbut an invalid signature. Verifying wheneverSome(sig)is present (regardless of pubkey equality) closes that gap with negligible cost:-if let Some(sig) = sig { - // Verify signature only if sender and rumor pubkey are different - if !sender_matches_rumor - && !Message::verify_signature(message_json, event.rumor.pubkey, sig) - { +if let Some(sig) = sig { + if !Message::verify_signature(message_json, event.rumor.pubkey, sig) {src/cli/settings.rs (1)
173-222: 🛠️ Refactor suggestionRobustness: surface FS errors when default dir already exists
File::create_new(...)will error ifsettings.tomlexists, which is correct, but the surroundingif create_dir(...).is_ok()swallows directory creation failures (e.g., permissions). If the directory wasn’t created, subsequent file operations will also fail, but with a less helpful message. Suggest early-returning onErr:- if std::fs::create_dir(settings_dir_default.clone()).is_ok() { + std::fs::create_dir(&settings_dir_default) + .map_err(|e| MostroInternalErr(ServiceError::IOError(e.to_string())))?;This preserves the explicit IO error context.
src/app/admin_take_dispute.rs (1)
218-233:⚠️ Potential issue
map_errusage produces type mismatch
map_errexpects a closure (FnOnce(E) -> F) butMostroInternalErris a variant, not a function.
Use an explicit closure so the compiler can construct theMostroError:- order.get_buyer_pubkey().map_err(MostroInternalErr)?, + order + .get_buyer_pubkey() + .map_err(|_| MostroInternalErr(ServiceError::InvalidPubkey))?,Apply the same change for the seller branch below.
src/db.rs (1)
404-419: 🛠️ Refactor suggestion
is_user_presentreturns aUserbut the name suggests a booleanCalling code will assume an existence-check returning
bool, yet we return the wholeUser, andsqlx::fetch_onewill raise an error for “not found”. Either:
- Keep the current return type but rename the function (e.g.
get_user_by_pubkey)- Keep the name and change to
Result<Option<User>, MostroError>usingfetch_optional.Returning
Option<User>is usually the most ergonomic for callers.
🧹 Nitpick comments (18)
src/app/admin_cancel.rs (2)
35-45: Avoid extra heap allocation when checking solver-assignment
event.senderis already aPublicKey; converting it toStringforces an allocation for every call.
is_assigned_solvercan accept&PublicKey(or&strderived on demand) to eliminate the allocation.-match is_assigned_solver(pool, &event.sender.to_string(), order.id).await { +match is_assigned_solver(pool, &event.sender, order.id).await {If the helper currently expects a string slice, consider adding an overload or changing its signature; the public key’s hex can be produced inside the helper only when strictly necessary.
86-99: Minor:Tags::from_listcall could be expressed withinto()Very small nit –
Tags::from_list(vec![ … ])allocates a temporaryVec. The API also accepts an iterator (impl IntoIterator). You can save one allocation:-let tags: Tags = Tags::from_list(vec![ +let tags = Tags::from_list([No functional difference, just a micro-optimisation.
src/bitcoin_price.rs (2)
36-40: Store rates with uppercase currency codes for case-insensitive lookup
get_price("usd")currently fails unless the caller uses the exact case found in the API (usually upper-case). Normalising keys once avoids surprises and additional allocations during every lookup.-*prices_write = yadio_response.btc; +*prices_write = yadio_response + .btc + .into_iter() + .map(|(k, v)| (k.to_uppercase(), v)) + .collect();Remember to apply the same normalisation in
get_price.
43-51: Provide case-insensitive lookup and clearer errorFollowing the previous suggestion, you can avoid forcing callers to worry about case:
-let prices_read = BITCOIN_PRICES.read() ...?; -prices_read.get(currency).cloned() +let prices_read = BITCOIN_PRICES.read() ...?; +prices_read.get(¤cy.to_uppercase()).cloned()Optionally introduce a dedicated
ServiceError::CurrencyNotFoundfor better diagnostics rather than re-usingNoAPIResponse.src/app/add_invoice.rs (1)
16-36: Persist changes without cloning & reuse existing order instance
order.clone().update(pool)allocates a full copy just to persist one field. You already mutatedpayment_attempts; simply callorder.update(pool)(if the trait takes&self). If an owned value is required, move the original.-order - .clone() - .update(pool) +order.update(pool)Avoiding the clone removes an extra heap allocation and keeps intent clear.
src/app.rs (2)
282-286: Log the actual unwrap error for easier troubleshooting
tracing::warn!("Error unwrapping gift");hides the concrete failure reason captured in theErr(e)branch. Exposing theewill greatly shorten incident-resolution time.- Err(_) => { - tracing::warn!("Error unwrapping gift"); + Err(e) => { + tracing::warn!("Error unwrapping gift: {e}");
309-315: Avoid serialise-then-deserialise churn
message.clone().as_json()is performed here and again later incheck_trade_index. Consider caching the JSON string once and passing a reference to downstream helpers to shave a few µs and an extra allocation per event.src/app/dispute.rs (3)
31-47: Hard-coded custom tag keys – consider constants
"s","y", and"z"appear multiple times across modules. Extracting them intoconstvalues (or an enum) will avoid typos and ease future schema changes.
83-89: Return type ofget_counterpart_infois no longer self-describing
Changing the function to return only aboolloses clarity at the call-site (is_buyer_dispute). A small enum conveys intent without needing comments:enum DisputeRole { Buyer, Seller } fn get_counterpart_info(...) -> Result<DisputeRole, CantDoReason> { ... }This also prevents accidental misuse of the truth-value.
209-227:get_*_pubkey()called twice – reuse references
The nested match clones and dereferences several times. A minor tidy-up:let (initiator_pubkey, counterpart_pubkey) = if is_buyer_dispute { (order.get_buyer_pubkey()?, order.get_seller_pubkey()?) } else { (order.get_seller_pubkey()?, order.get_buyer_pubkey()?) };reduces cloning and indirection.
src/app/admin_take_dispute.rs (1)
216-236: Reduce duplication when sending DMs to both partiesThe two
send_dmcalls differ only by the destination key. Iterating over a slice of keys improves readability and reduces copy-paste risk.src/nip33.rs (1)
166-167: Hard-coded 12-hour extension violates settingsThe expiration tag is extended by a fixed
12h, ignoringmostro_settings.expiration_hours.
Using the configured value keeps behaviour consistent with users’ expectations.src/util.rs (3)
175-188: Potential overflow when computingexpires_at_max
Timestamp::now().as_u64() + Duration::days(...).num_seconds()can overflowi64on very long uptimes or largemax_expiration_days.
Usesaturating_addor check the sum withchecked_add.
224-240: Zero-value reputation tag leaks into first-time ordersWhen no user record is found,
get_tags_for_new_orderinjects a rating tag with zeros, which may mislead takers.
Skip the rating tag instead:- order_to_tags(new_order_db, Some((0.0, 0, 0))) + order_to_tags(new_order_db, None)
526-529: Swallowing send errors hides relay outages
send_event(&event).await.is_err()only logs a warning.
Consider retrying or propagating the error so callers can react.src/db.rs (3)
42-56: Error message does not correspond to the failure pathIn this block we’re handling a migration failure, but the log says “Failed to create database connection”, which is misleading and will complicate troubleshooting.
- "Failed to create database connection" + "Failed to run database migrations"A precise log message is vital for operators triaging startup problems.
421-447: Lack of duplicate-key handling inadd_new_userAttempting to insert an already-existing pubkey will bubble up a raw SQLite error. If this situation is expected (e.g. idempotent user creation on first contact), consider:
.matching(|e| e.sqlite_error_code() == Some(sqlite3::ErrorCode::ConstraintViolation)) .then(|| MostroCantDo(CantDoReason::UserAlreadyExists))or switch to
INSERT OR IGNORE / INSERT … ON CONFLICT. This gives the caller a domain-specific error instead of a generic DB failure.
455-461: Public-key validation logic scattered & duplicatedThe 64-hex-char check appears in several functions (
update_user_trade_index, rating updates, pending-order checks). Extract it into a singlevalidate_pubkey(&str) -> Result<(), MostroError>helper to avoid divergence and ensure future format changes propagate consistently.
📜 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 (26)
Cargo.toml(3 hunks)migrations/20230928145530_disputes.sql(1 hunks)src/app.rs(5 hunks)src/app/add_invoice.rs(4 hunks)src/app/admin_add_solver.rs(1 hunks)src/app/admin_cancel.rs(4 hunks)src/app/admin_settle.rs(4 hunks)src/app/admin_take_dispute.rs(5 hunks)src/app/dispute.rs(6 hunks)src/app/fiat_sent.rs(2 hunks)src/app/order.rs(1 hunks)src/app/rate_user.rs(0 hunks)src/app/release.rs(3 hunks)src/app/take_buy.rs(0 hunks)src/app/take_sell.rs(0 hunks)src/bitcoin_price.rs(2 hunks)src/cli.rs(2 hunks)src/cli/settings.rs(8 hunks)src/db.rs(33 hunks)src/flow.rs(2 hunks)src/lightning/mod.rs(0 hunks)src/main.rs(2 hunks)src/messages.rs(1 hunks)src/nip33.rs(5 hunks)src/scheduler.rs(6 hunks)src/util.rs(12 hunks)
💤 Files with no reviewable changes (4)
- src/lightning/mod.rs
- src/app/take_buy.rs
- src/app/take_sell.rs
- src/app/rate_user.rs
🧰 Additional context used
🧬 Code Graph Analysis (8)
src/main.rs (1)
src/db.rs (1)
find_held_invoices(354-367)
src/flow.rs (1)
src/util.rs (2)
enqueue_order_msg(837-854)notify_taker_reputation(949-1025)
src/cli.rs (1)
src/cli/settings.rs (1)
init_default_dir(173-222)
src/scheduler.rs (3)
src/db.rs (1)
connect(22-75)src/app.rs (1)
e(355-355)src/util.rs (1)
get_keys(458-468)
src/app/add_invoice.rs (1)
src/util.rs (6)
enqueue_order_msg(837-854)get_order(910-923)notify_taker_reputation(949-1025)show_hold_invoice(568-646)update_order_event(506-539)validate_invoice(925-947)
src/bitcoin_price.rs (2)
src/util.rs (1)
reqwest(48-51)src/app.rs (1)
e(355-355)
src/app/release.rs (2)
src/nip33.rs (2)
new_event(26-40)order_to_tags(115-192)src/db.rs (1)
is_user_present(404-419)
src/db.rs (1)
src/app.rs (1)
e(355-355)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: tests
🔇 Additional comments (37)
Cargo.toml (3)
19-19: Dependency version update for nostr-sdk looks good.The version upgrade from 0.38.0 to 0.40.0 appears appropriate as part of the broader refactoring to use custom error types instead of anyhow.
40-40: Verify compatibility with this significant mostro-core version upgrade.The mostro-core version has been updated from 0.6.28 to 0.6.38, which is a substantial jump of 10 minor versions.
Please ensure all tests pass with this updated dependency version. This upgrade likely introduces new functionality and possibly API changes that should be verified.
51-51: LGTM - Dev dependency formatting change.This appears to be a minor formatting change in the dev dependencies section.
src/app/fiat_sent.rs (2)
56-59: Improved explicitness in Peer initialization.Direct struct initialization makes the code more explicit about which fields are being set, improving readability and maintainability compared to using the
Peer::new()constructor.
72-75: Consistent Peer initialization approach.This change follows the same pattern as the earlier peer initialization, maintaining consistency in the codebase.
src/main.rs (3)
17-17: Improved import structure with crate-relative path.Using
crate::db::find_held_invoicesmakes the import hierarchy clearer and aligns with Rust best practices.
19-19: Consistent import pattern.Using
crate::lightning::LndConnectormaintains consistency with the import style in the rest of the file.
93-93: Simplified client subscription call.Changed from passing
vec![subscription]to directly passingsubscription, which is a cleaner approach if the API now supports accepting a single filter directly.src/messages.rs (2)
1-1: Appropriate error handling import.Replacing the generic
anyhow::Resultwith the domain-specificMostroErroraligns with the broader refactoring effort to use more explicit error types throughout the codebase.
7-7: Improved error type specificity.Changing the return type from
Result<String>toResult<String, MostroError>makes the error handling more explicit, following Rust best practices of clearly communicating possible error conditions.src/app/admin_add_solver.rs (1)
38-39: Security check update aligns with codebase standardizationThe change from checking
event.rumor.pubkeytoevent.senderfor authentication is consistent with the broader refactoring across admin modules. This establishesevent.senderas the authoritative source for public key verification in admin actions.migrations/20230928145530_disputes.sql (1)
5-5:Details
❓ Verification inconclusive
Migration adds required column but lacks default value for existing records
The addition of the non-nullable
order_previous_statuscolumn will enhance dispute tracking by storing the previous order status. However, this migration might fail on databases with existing records since it doesn't specify a default value for existing rows.Consider validating this migration against a database with existing records or modifying it to include a default value:
- order_previous_status varchar(10) not null, + order_previous_status varchar(10) not null DEFAULT 'unknown',
🏁 Script executed:
#!/bin/bash # Check if there are existing disputes records that would be affected echo "Checking for existing disputes records" sqlite3 mostro.db "SELECT COUNT(*) FROM disputes;"Length of output: 237
Ensure non-nullable column won’t break on existing data
In migrations/20230928145530_disputes.sql at line 5, you’ve added:
order_previous_status varchar(10) NOT NULL,If the disputes table already contains rows, this migration will fail because there’s no value for existing records. Please verify and update the migration by either:
- Adding a default value:
- order_previous_status varchar(10) NOT NULL, + order_previous_status varchar(10) NOT NULL DEFAULT 'unknown',- Or backfilling before enforcing NOT NULL, for example:
ALTER TABLE disputes ADD COLUMN order_previous_status varchar(10); UPDATE disputes SET order_previous_status = 'unknown' WHERE order_previous_status IS NULL; ALTER TABLE disputes ALTER COLUMN order_previous_status SET NOT NULL;Request you to confirm whether there are existing dispute records in your environments and adjust the migration accordingly.
src/flow.rs (2)
1-1: Import updated to support new reputation notification functionalityThe import statement has been updated to include the new
notify_taker_reputationfunction that will be used later in the file.
108-112: Enhanced user experience with reputation notificationsAdding reputation notifications for takers provides valuable transparency about counterparty reliability, which helps users make more informed decisions. This implementation correctly calls the new utility function after sending messages to both parties.
src/app/order.rs (1)
50-89: Excellent documentation improvementThe added documentation for
order_actionthoroughly explains the function's purpose, behavior, parameters, error conditions, and includes a helpful usage example. This significantly improves code maintainability and developer onboarding.src/cli.rs (3)
5-5: Import change aligns with error handling refactoringThe import of
MostroErrorfrommostro_core::errorreplaces the previously usedanyhow::Result, supporting the codebase-wide shift to custom error types.
32-32: Function return signature updated for consistent error handlingThe return type has been changed from
anyhow::Result<PathBuf>toResult<PathBuf, MostroError>, making the error type explicit and consistent with the rest of the codebase.
35-39: Updated error propagation with explicit Ok wrappingThe function now wraps the result of
init_default_dirwithOk(...)and uses the?operator to propagate errors properly, matching the new return type signature.src/app/admin_settle.rs (4)
34-34: Fixed solver verification to use correct event sender fieldChanged from using
event.rumor.pubkeytoevent.senderfor solver verification, ensuring consistent access to the sender's public key throughout the codebase.
49-61: Improved control flow for cooperative cancellationThe logic for handling cooperative cancellation has been restructured to enqueue a message and return early if the order status is
CooperativelyCanceled. This improves readability and makes the control flow more explicit.
86-87: Updated tag creation methodChanged from
Tags::newtoTags::from_listfor creating Tags, consistent with tag construction changes elsewhere in the codebase.
107-107: Changed event passing to use referenceNow passing a reference to the event (
&event) rather than moving it, which is more efficient and aligns with similar changes across other modules.src/scheduler.rs (5)
12-13: Added custom error imports to replace anyhowImported
MostroErrorandServiceErrorfrommostro_core::errorto support the codebase-wide shift from generalanyhowerror handling to custom error types.
127-127: Changed event sending to use referencesNow passing references to events (
&event) inclient.send_eventcalls rather than moving them, which is more efficient and consistent with the pattern used elsewhere in the codebase.Also applies to: 157-157, 214-214
235-235: Updated function return type for consistent error handlingChanged the return type of
job_cancel_ordersfromanyhow::Result<()>toResult<(), MostroError>, aligning with the broader project-wide removal ofanyhowin favor ofMostroError.
238-253: Improved error handling with specific error typesUpdated error handling in the database connection and key retrieval code to use specific
MostroErrorvariants with contextual information, rather than generic anyhow errors.
402-406: Enhanced logging with tracing instead of printlnReplaced
println!withtracing::info!for logging expired orders, which is a better practice for structured logging in a production application.src/app/release.rs (3)
5-5: Added imports for Nostr event handlingImported
new_eventandorder_to_tagsfrom thenip33module to support the refactoredcreate_order_eventfunction.
117-117: Changed event sending to use referenceNow passing a reference to the event (
&event) in theclient.send_eventcall rather than moving it, which aligns with similar changes across the codebase.
406-428: Enhanced order event creation with privacy awarenessSignificantly improved the
create_order_eventfunction to respect privacy settings:
- Now checks if the order is a full privacy order for both buyer and seller
- For non-private orders, fetches user reputation data and passes it to tag generation
- For private orders, omits reputation data in tags
- Adds validation to ensure tags are generated before creating an event
- Returns a specific error if tag creation fails
This approach properly respects user privacy settings while still providing reputation information when appropriate.
src/app/admin_cancel.rs (2)
48-60: Early-return branch never persists any state changeWhen the order is already
CooperativelyCanceledyou enqueueCooperativeCancelAcceptedand immediately return, but no DB or event update is performed.
Is that intentional? If the goal is merely to acknowledge the request it’s fine, otherwise you may want to callupdate_order_event(or at least persistCooperativeCancelAccepted) before returning.
136-139: Inconsistent use ofevent.sendervsevent.rumor.pubkeyAbove, the solver (and DM recipients inside
enqueue_order_msg) are identified withevent.sender, yet for the admin DM you fall back toevent.rumor.pubkey.Please double-check that this is the intended recipient. If the new convention is “always trust
sender”, the line below should be updated:-send_dm(event.rumor.pubkey, sender_keys, message.clone(), None) +send_dm(event.sender, sender_keys, message.clone(), None)Mixing the two may DM the wrong key in multi-proxy scenarios.
src/app/add_invoice.rs (1)
27-35: Potentially wrong notification recipient
enqueue_order_msgsendsInvoiceUpdatedtoorder.get_buyer_pubkey(), yet the buyer is the one who just updated the invoice. Shouldn’t the seller be informed instead?Please verify the business rule; if notification should go to the counter-party, switch to
order.get_seller_pubkey().- order.get_buyer_pubkey().map_err(MostroInternalErr)?, + order.get_seller_pubkey().map_err(MostroInternalErr)?,src/app.rs (2)
234-236: Admin-take dispute call correctly forwardsmy_keysnow – nice catch
Passingmy_keyskeeps the handler signature consistent with the recent refactor, preventing compile-time breakage.
298-306: Good move: deserialize directly intoMessageto avoid double parsing
The switch to(Message, Option<Signature>)removes the previousValue → Messagedetour and saves one allocation / traversal.src/app/dispute.rs (1)
109-145: Queue operations ignore failures – bubble them up or log
enqueue_order_msg(...).await;returns()today, but if it ever evolves toResult, silent failures would break UX. Even now, theawaitmay panic in case of channel closure. Consider:if let Err(e) = enqueue_order_msg(...).await { tracing::error!("Unable to enqueue dispute notification: {e}"); }or change the helper signature to propagate errors.
src/nip33.rs (1)
94-107: Boolean logic may skip events for valid states
create_status_tagssetscreate_eventusingis_sell_order().is_ok()/is_buy_order().is_ok().
Those calls returntrueeven when the order is not of the expected kind but the check merely succeeded.
Useorder.is_sell_order()?(or compareorder.kind) to avoid false negatives.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/app/admin_take_dispute.rs (1)
117-121: Inconsistent public key access patternThere's an inconsistency in how the public key is accessed. Line 119 uses direct field access
my_keys.public_keywhile line 122 uses the method callmy_keys.public_key().According to previous discussions, both approaches work since the
Keysstruct has a publicpublic_keyfield. For consistency, consider using the same approach throughout the codebase:- my_keys.public_key.to_string(), + my_keys.public_key().to_string(),or:
- if ev_pubkey.to_string() == my_keys.public_key().to_string() + if ev_pubkey.to_string() == my_keys.public_key.to_string()
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/app/add_invoice.rs(4 hunks)src/app/admin_take_dispute.rs(5 hunks)src/db.rs(33 hunks)src/nip33.rs(5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: tests
🔇 Additional comments (25)
src/app/add_invoice.rs (6)
16-36: Function name change clarifies purposeThe function has been renamed from
check_order_statustopay_new_invoice, which better reflects its actual purpose. The implementation also consistently uses the MostroError type for better error handling.
48-48: Improved control flow with separate status checkExtracting the order status into a variable before processing makes the code more readable and maintainable.
60-69: Better status handling with explicit matchThe match statement provides clearer handling for different order statuses, making the control flow easier to understand.
71-73: Added reputation notification improves user experienceNotifying the taker about the counterparty's reputation is a good enhancement that helps users make informed decisions.
81-90: Improved error handling for order event updatesThis change properly handles errors from
update_order_eventby using a match statement with explicit error handling. The early return on error prevents proceeding with inconsistent order data.This implementation addresses a previous review comment about ensuring DB consistency when
update_order_eventfails - now the operation is properly aborted on error.
92-111: Use of updated order data in messagingUsing the updated order data from
active_orderfor subsequent messaging ensures consistency throughout the operation.src/app/admin_take_dispute.rs (7)
20-108: Good extraction of dispute info preparation logicThe new helper function
prepare_solver_info_messageencapsulates the complex logic of constructing aSolverDisputeInfoobject. It properly handles privacy modes, retrieves master pubkeys, and conditionally fetches user presence data.The conditional logic for determining which party is the initiator and counterpart is well-structured, and the proper error handling throughout the function ensures robustness.
149-169: Improved dispute and order retrieval with better error handlingUsing the utility function
get_disputeand retrieving the order directly by ID simplifies the code and provides consistent error handling.
173-174: Updated dispute solver attributionNow using
event.senderinstead ofrumor.pubkeyfor setting the solver's public key, which correctly attributes the dispute to the event sender.
185-186: Use of dedicated helper for solver info messageUsing the extracted helper function
prepare_solver_info_messagemakes the code more modular and readable.
206-215: Improved message structure with solver peer infoUsing
Payload::Peerwith the solver's public key provides a cleaner interface for communicating solver information to users.
217-238: Use of passed mostro_keys parameterUsing the passed
mostro_keysparameter instead of fetching keys internally reduces duplication and improves consistency.
277-278: Proper reference passing for event sendingUsing
&eventinstead of passing by value ensures efficient event passing to the send_event method.src/nip33.rs (7)
35-35: Consistent tag list buildingUsing
Tags::from_listinstead ofTags::newmaintains consistency in tag construction throughout the codebase.
50-68: Fixed rating tag creation with proper JSON formattingThe updated function now correctly handles missing reputation data by returning an empty JSON object
"{}"instead of a sentinel string. It also properly handles the case where the reputation timestamp is zero.This change addresses a previous review comment about returning valid JSON when reputation data is missing, which prevents downstream JSON parsing errors.
93-107: Well-structured status tag mapping functionThe new helper function
create_status_tagsencapsulates the logic for mapping order statuses to NIP69-compatible statuses and determining whether to create event tags. This improves code organization and reusability.
115-118: Improved function signature with Result and Optional returnChanging the return type to
Result<Option<Tags>, MostroError>properly handles both errors and the case when no tags should be created.
119-129: Proper handling of Lightning network dataUsing
LN_STATUS.get()to retrieve the current Lightning network status ensures accurate network information in the tags.
179-191: Conditional reputation tag insertionConditionally inserting the reputation tag at a specific index only when data is available improves the handling of optional data.
203-203: Consistent tag list constructionUsing
Tags::from_listfor info tags maintains consistency with the tag creation pattern used elsewhere in the file.src/db.rs (5)
23-37: Improved database file creation with OpenOptionsThe code now uses
OpenOptionswithcreate_new(true)instead ofstd::fs::File::create_new, making it compatible with stable Rust while maintaining the same functionality.This change addresses a previous review comment about using stable Rust APIs instead of nightly-only features.
55-57: Consistent error handling patternThe consistent use of
MostroInternalErr(ServiceError::DbAccessError(e.to_string()))for database errors improves error specificity and consistency.
135-146: Standardized error handling in database queriesAll database query functions now consistently return
Result<_, MostroError>with appropriate error mapping, which aligns with the broader codebase changes to remove anyhow in favor of custom error types.
570-572: Added cross-field consistency check for ratingsThe added check ensures that
min_rating <= last_rating <= max_rating, which preserves important data integrity constraints.This change addresses a previous review comment about ensuring cross-field consistency in rating data, preventing contradictory data such as having min_rating > last_rating.
597-601: Improved logging for solver assignmentUsing
tracing::info!instead of debug prints provides better visibility into solver assignments for troubleshooting and monitoring.
@grunch
opening this pr to fix a point to start working on from here with main trunk
Summary by CodeRabbit