Fix missing user invoice timeout (#1379)
* Wait max 10 seconds for user wallet to create invoice * Add timeout in error message
This commit is contained in:
parent
2ad2cabb03
commit
8c56904094
|
@ -133,7 +133,7 @@ function timeoutPromise (timeout) {
|
||||||
// if no timeout is specified, never settle
|
// if no timeout is specified, never settle
|
||||||
if (!timeout) return
|
if (!timeout) return
|
||||||
|
|
||||||
setTimeout(() => reject(new Error('timeout')), timeout)
|
setTimeout(() => reject(new Error(`timeout after ${timeout / 1000}s`)), timeout)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import walletDefs from 'wallets/server'
|
||||||
import { parsePaymentRequest } from 'ln-service'
|
import { parsePaymentRequest } from 'ln-service'
|
||||||
import { toPositiveNumber } from '@/lib/validate'
|
import { toPositiveNumber } from '@/lib/validate'
|
||||||
import { PAID_ACTION_TERMINAL_STATES } from '@/lib/constants'
|
import { PAID_ACTION_TERMINAL_STATES } from '@/lib/constants'
|
||||||
|
import { withTimeout } from '@/lib/time'
|
||||||
export default [lnd, cln, lnAddr, lnbits, nwc, phoenixd]
|
export default [lnd, cln, lnAddr, lnbits, nwc, phoenixd]
|
||||||
|
|
||||||
const MAX_PENDING_INVOICES_PER_WALLET = 25
|
const MAX_PENDING_INVOICES_PER_WALLET = 25
|
||||||
|
@ -73,12 +74,13 @@ export async function createInvoice (userId, { msats, description, descriptionHa
|
||||||
throw new Error('wallet has too many pending invoices')
|
throw new Error('wallet has too many pending invoices')
|
||||||
}
|
}
|
||||||
|
|
||||||
const invoice = await createInvoice({
|
const invoice = await withTimeout(
|
||||||
msats,
|
createInvoice({
|
||||||
description: wallet.user.hideInvoiceDesc ? undefined : description,
|
msats,
|
||||||
descriptionHash,
|
description: wallet.user.hideInvoiceDesc ? undefined : description,
|
||||||
expiry
|
descriptionHash,
|
||||||
}, walletFull[walletField])
|
expiry
|
||||||
|
}, walletFull[walletField]), 10_000)
|
||||||
|
|
||||||
const bolt11 = await parsePaymentRequest({ request: invoice })
|
const bolt11 = await parsePaymentRequest({ request: invoice })
|
||||||
if (BigInt(bolt11.mtokens) !== BigInt(msats)) {
|
if (BigInt(bolt11.mtokens) !== BigInt(msats)) {
|
||||||
|
|
Loading…
Reference in New Issue