diff --git a/worker/index.js b/worker/index.js index dfb6c4f97..85019f8f7 100644 --- a/worker/index.js +++ b/worker/index.js @@ -5,7 +5,7 @@ import createPrisma from '@/lib/create-prisma' import { checkInvoice, checkPendingDeposits, checkPendingWithdrawals, checkWithdrawal, - finalizeHodlInvoice, subscribeToWallet + finalizeHodlInvoice, retryTimeout, subscribeToWallet } from './wallet' import { repin } from './repin' import { trust } from './trust' @@ -101,6 +101,7 @@ async function work () { await boss.work('autoDropBolt11s', jobWrapper(autoDropBolt11s)) await boss.work('autoWithdraw', jobWrapper(autoWithdraw)) await boss.work('checkInvoice', jobWrapper(checkInvoice)) + await boss.work('retryTimeout', jobWrapper(retryTimeout)) await boss.work('checkWithdrawal', jobWrapper(checkWithdrawal)) // paidAction jobs await boss.work('paidActionForwarding', jobWrapper(paidActionForwarding)) diff --git a/worker/paidAction.js b/worker/paidAction.js index 9b3ecb5a6..4723352de 100644 --- a/worker/paidAction.js +++ b/worker/paidAction.js @@ -1,7 +1,7 @@ import { getPaymentFailureStatus, hodlInvoiceCltvDetails, getPaymentOrNotSent } from '@/api/lnd' import { paidActions } from '@/api/paidAction' import { walletLogger } from '@/api/resolvers/wallet' -import { LND_PATHFINDING_TIME_PREF_PPM, LND_PATHFINDING_TIMEOUT_MS, PAID_ACTION_TERMINAL_STATES } from '@/lib/constants' +import { LND_PATHFINDING_TIME_PREF_PPM, LND_PATHFINDING_TIMEOUT_MS, PAID_ACTION_TERMINAL_STATES, WALLET_RETRY_BEFORE_MS } from '@/lib/constants' import { formatMsats, formatSats, msatsToSats, toPositiveNumber } from '@/lib/format' import { datePivot } from '@/lib/time' import { Prisma } from '@prisma/client' @@ -466,9 +466,19 @@ export async function paidActionFailed ({ data: { invoiceId, ...args }, models, await paidActions[dbInvoice.actionType].onFail?.({ invoice: dbInvoice }, { models, tx, lnd }) + const cancelledAt = new Date() + + // XXX update invoice after retry timeout for notification indicator + await models.$executeRaw` + INSERT INTO pgboss.job (name, data, retrylimit, retrybackoff, startafter, keepuntil, priority) + VALUES ('retryTimeout', + jsonb_build_object('hash', ${dbInvoice.hash}::TEXT), 21, true, + ${cancelledAt}::TIMESTAMP WITH TIME ZONE + ${`${WALLET_RETRY_BEFORE_MS} milliseconds`}::interval, + ${cancelledAt}::TIMESTAMP WITH TIME ZONE + ${`${2 * WALLET_RETRY_BEFORE_MS} milliseconds`}::interval, 100)` + return { cancelled: true, - cancelledAt: new Date() + cancelledAt } }, ...args diff --git a/worker/wallet.js b/worker/wallet.js index ac09c7ac4..f60581887 100644 --- a/worker/wallet.js +++ b/worker/wallet.js @@ -161,6 +161,10 @@ export async function checkInvoice ({ data: { hash, invoice }, boss, models, lnd } } +export async function retryTimeout ({ data: { hash }, models, lnd, boss }) { + await models.invoice.update({ where: { hash }, data: { updatedAt: new Date() } }) +} + async function subscribeToWithdrawals (args) { const { lnd } = args