mirror of
https://github.com/getAlby/hub.git
synced 2026-08-13 12:33:39 +02:00
* fix: publish transaction events only after the database transaction commits markTransactionSettled and markPaymentFailed published nwc_payment_sent / nwc_payment_received / nwc_payment_failed (and checkBudgetUsage published nwc_budget_warning) while still inside the caller's database transaction, so connected apps and the Alby API could be notified of a payment whose row was never committed, and subscribers reading the database in response to an event could race with the commit. Every function that writes transaction state now owns its own database transaction and publishes its events only after the commit succeeds: - markTransactionSettled and markPaymentFailed open their own transaction; callers no longer wrap them in db.Transaction - new createSettledTransactionFromNotification inserts transactions reported by LNClient notifications for payments the hub has no record of (external payments, received keysends) directly in their settled state, removing the transient PENDING row and the zombie row left behind on duplicate events - markPaymentFailed now refuses to mark a settled transaction as failed, replacing CancelHoldInvoice's in-transaction ACCEPTED re-check and also protecting the SendPaymentSync error path from a racing settle - checkBudgetUsage returns the budget warning event instead of publishing it Closes #2506 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix: serialize payment failure with settlement and propagate lock errors Address review findings on the previous commit: - markPaymentFailed now takes the same payment-hash row lock as settlement (postgres), so the settled-state guard cannot be bypassed by a concurrent settle between the state check and the update; it also returns not-found instead of publishing an event when the transaction row no longer exists, and reports whether this call transitioned the row so CancelHoldInvoice only publishes nwc_hold_invoice_canceled when it performed the cancellation - findSettledTransaction propagates errors from the lock query and the settled-transaction lookup instead of treating a failed lookup as "no settled transaction exists", which could defeat the dedup guard - TestMarkSettled_Twice no longer shares one transaction struct between concurrent goroutines and collects errors instead of asserting inside them Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix: mark failed keysend payments via markPaymentFailed The SendKeysend failure path updated the transaction directly, which never zeroed the fee reserve, recorded no failure reason, published no nwc_payment_failed event, and had no guard against overwriting a concurrently settled payment. Route it through markPaymentFailed like SendPaymentSync, and allow MockLn keysends to fail so the path is testable. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| db | ||
| mocks | ||
| create_app.go | ||
| create_mock_relay.go | ||
| mock_event_consumer.go | ||
| mock_ln_client.go | ||
| test_service.go | ||