Skip to content

Commit

Permalink
Don't retry too old invoices
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzyis committed Jan 6, 2025
1 parent fcad2ba commit 4c96c48
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions api/resolvers/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
USER_ID, INVOICE_RETENTION_DAYS,
PAID_ACTION_PAYMENT_METHODS,
WALLET_CREATE_INVOICE_TIMEOUT_MS,
WALLET_RETRY_AFTER_MS
WALLET_RETRY_AFTER_MS,
WALLET_RETRY_BEFORE_MS
} from '@/lib/constants'
import { amountSchema, validateSchema, withdrawlSchema, lnAddrSchema } from '@/lib/validate'
import assertGofacYourself from './ofac'
Expand Down Expand Up @@ -471,7 +472,10 @@ const resolvers = {
SELECT id FROM "Invoice"
WHERE "userId" = ${me.id}
AND "actionState" = 'FAILED'
AND "cancelledAt" < now() - interval '${WALLET_RETRY_AFTER_MS} milliseconds'
AND now()::timestamp <@ tsrange(
"cancelledAt" + interval '${WALLET_RETRY_AFTER_MS} milliseconds',
"cancelledAt" + interval '${WALLET_RETRY_BEFORE_MS} milliseconds'
)
AND "lockedAt" IS NULL
ORDER BY id DESC
FOR UPDATE SKIP LOCKED
Expand Down
1 change: 1 addition & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,4 @@ export const WALLET_CREATE_INVOICE_TIMEOUT_MS = 45_000
// This must be high enough such that intermediate failed invoices that will be retried
// by the client due to sender or receiver fallbacks are not returned to the client.
export const WALLET_RETRY_AFTER_MS = 60_000
export const WALLET_RETRY_BEFORE_MS = 86_400_000 // 24 hours

0 comments on commit 4c96c48

Please sign in to comment.