Skip to content

Commit 073d4dc

Browse files
committed
paymentsdb: add note to RegisterAttempt
1 parent e9dcca8 commit 073d4dc

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

payments/db/interface.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ type PaymentControl interface {
6161
InitPayment(lntypes.Hash, *PaymentCreationInfo) error
6262

6363
// RegisterAttempt atomically records the provided HTLCAttemptInfo.
64+
//
65+
// IMPORTANT: Callers MUST serialize calls to RegisterAttempt for the
66+
// same payment hash. Concurrent calls will result in race conditions
67+
// where both calls read the same initial payment state, validate
68+
// against stale data, and could cause overpayment. For example:
69+
// - Both goroutines fetch payment with 400 sats sent
70+
// - Both validate sending 650 sats won't overpay (within limit)
71+
// - Both commit successfully
72+
// - Result: 1700 sats sent, exceeding the payment amount
73+
// The payment router/controller layer is responsible for ensuring
74+
// serialized access per payment hash.
6475
RegisterAttempt(lntypes.Hash, *HTLCAttemptInfo) (*MPPayment, error)
6576

6677
// SettleAttempt marks the given attempt settled with the preimage. If

0 commit comments

Comments
 (0)