Skip to content

Commit

Permalink
Fix notification indicator on retry timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzyis committed Feb 13, 2025
1 parent dea2e7a commit 804f58c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion worker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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))
Expand Down
14 changes: 12 additions & 2 deletions worker/paidAction.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions worker/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 804f58c

Please sign in to comment.