feat: cashu escrow DB helpers — Cashu foundation CF-4#797
Conversation
Cashu foundation CF-4 (docs/cashu/01-fundamentals.md, section 6): - update_order_cashu_escrow: atomic compare-and-set that persists the three cashu_* columns AND advances the status in one UPDATE guarded by 'WHERE id = ? AND status = ? AND cashu_escrow_locked_at IS NULL' — no lock-without-advance window, replay/race safe; returns whether a row matched. - find_locked_cashu_orders: WHERE cashu_escrow_locked_at IS NOT NULL, deliberately without a status predicate (the CAS advances status in the same write as the lock, so a status filter would skip legitimately locked rows that moved on). Columns already exist on main (20260530120000_cashu_escrow_fields.sql); no schema change. New, unreferenced functions — no behaviour change. Tests: CAS locks once + replay is a no-op preserving the original lock; status mismatch matches zero rows leaving columns untouched; the finder includes locked orders regardless of status (e.g. FiatSent) and excludes unlocked ones. 506 tests pass (503 pre-existing + 3 new).
|
Warning Review limit reached
Next review available in: 53 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
codaMW
left a comment
There was a problem hiding this comment.
Reviewed against mostro-core 0.14. Clean additive DB-helper PR verified the two correctness-critical claims (atomic replay-safe CAS + deliberately status-agnostic finder), not just that it compiles.
Mechanics
• Builds clean (Rust 1.94); cargo clippy --all-targets --all-features -- -D warnings clean.
• cargo test: 506 pass (503 pre-existing + 3 new). The one failure is test_lnurl_validation_with_test_server (AddrInUse) the pre-existing port-bind flake, unrelated.
update_order_cashu_escrow atomic CAS verified
• Single UPDATE … WHERE id = ? AND status = ? AND cashu_escrow_locked_at IS NULL one statement, no read-then-write window. The locked_at IS NULL guard makes a replay/concurrent submit match zero rows instead of double-writing; the cashu_escrow_cas_locks_once_and_replay_is_noop test confirms the original lock survives an attempted overwrite with a different mint/token.
• Persists the three cashu_* columns and the status transition in the same write (no lock-without-advance window), returns rows_affected() > 0 so the caller knows if it won.
• Status is bound via to_string(), which is kebab-case (Status has #[serde(rename_all = "kebab-case")] + a matching Display), consistent with how status is persisted/queried elsewhere (e.g. the 'settled-hold-invoice' literal in db.rs) so the status = ? guard matches real rows. Checked this specifically since a format divergence would silently no-op the CAS; it's consistent.
find_locked_cashu_orders status-agnostic by design, verified
• WHERE cashu_escrow_locked_at IS NOT NULL with no status predicate. Correct per the M-1 note: since the CAS advances status in the same write as the lock, a status filter would skip legitimately locked rows that already moved on. The test proves a locked -> FiatSent order is still returned.
Scope: columns pre-exist (20260530120000_cashu_escrow_fields.sql on main), helpers are unreferenced, zero behavior change so build/clippy + the 3-unit tests against a real pool are the right level; no migration or trade E2E needed here.
ACK: the CAS is the load-bearing bit and it's genuinely race-safe.
Summary
CF-4 of the Cashu foundation (
docs/cashu/01-fundamentals.md§6). Additive query helpers over the already-migratedcashu_*columns; new, unreferenced functions — zero behaviour change. Frozen-contract signatures from §10 of the spec.update_order_cashu_escrow(pool, order_id, mint_url, token, locked_at, expected_status, new_status) -> Result<bool>— atomic compare-and-set: persists the three columns and transitions the status in oneUPDATE … WHERE id = ? AND status = ? AND cashu_escrow_locked_at IS NULL. No lock-without-advance window; a replayed or concurrent submission matches zero rows instead of double-writing.find_locked_cashu_orders(pool)—WHERE cashu_escrow_locked_at IS NOT NULL, deliberately without a status predicate: the CAS advances the status in the same write as the lock, so filtering on a status would skip legitimately locked rows that already moved on (per the spec's design note, incl. the M-1 review fix).No migration ships here — the columns landed on
mainin20260530120000_cashu_escrow_fields.sql.Test plan
cargo fmt --allcargo clippy --all-targets --all-features -- -D warningscargo test— 506 passed (503 pre-existing unmodified + 3 new):NULLFiatSent→ still found) and excludes unlocked onesIndependent Wave-1 PR of the CF-0…CF-5 series (CF-0 #795, CF-1 #796). Remaining: CF-2 (CashuClient/cdk), CF-3 (mint harness), CF-5 (integration, last).