fix broken migration
This commit is contained in:
parent
2cc4a3d0c7
commit
66ff456bf2
5 changed files with 18 additions and 13 deletions
|
|
@ -433,6 +433,9 @@ export default class {
|
||||||
}
|
}
|
||||||
|
|
||||||
async GetPayment(paymentIndex: number) {
|
async GetPayment(paymentIndex: number) {
|
||||||
|
if (paymentIndex === 0) {
|
||||||
|
throw new Error("payment index starts from 1")
|
||||||
|
}
|
||||||
const indexOffset = BigInt(paymentIndex - 1)
|
const indexOffset = BigInt(paymentIndex - 1)
|
||||||
const res = await this.lightning.listPayments({
|
const res = await this.lightning.listPayments({
|
||||||
countTotalPayments: false, includeIncomplete: true, indexOffset, maxPayments: 1n, reversed: false
|
countTotalPayments: false, includeIncomplete: true, indexOffset, maxPayments: 1n, reversed: false
|
||||||
|
|
|
||||||
|
|
@ -72,8 +72,8 @@ export const initMainHandler = async (log: PubLogger, mainSettings: MainSettings
|
||||||
if (stop) {
|
if (stop) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
mainHandler.paymentManager.checkPendingPayments()
|
await mainHandler.paymentManager.checkPendingPayments()
|
||||||
mainHandler.paymentManager.watchDog.Start()
|
await mainHandler.paymentManager.watchDog.Start()
|
||||||
return { mainHandler, apps, liquidityProviderInfo, liquidityProviderApp, wizard, adminManager }
|
return { mainHandler, apps, liquidityProviderInfo, liquidityProviderApp, wizard, adminManager }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -123,17 +123,19 @@ export default class {
|
||||||
}
|
}
|
||||||
|
|
||||||
checkPendingLndPayment = async (log: PubLogger, p: UserInvoicePayment) => {
|
checkPendingLndPayment = async (log: PubLogger, p: UserInvoicePayment) => {
|
||||||
if (p.paymentIndex === 0) {
|
if (p.paymentIndex === 0 || p.paymentIndex === -1) {
|
||||||
const fullAmount = p.paid_amount + p.service_fees + p.routing_fees
|
log("found a pending payment with no payment index, skipping", p.serial_id)
|
||||||
log("found a pending payment with no payment index, refunding", fullAmount, "sats to user", p.user.user_id)
|
//const fullAmount = p.paid_amount + p.service_fees + p.routing_fees
|
||||||
await this.storage.txQueue.PushToQueue({
|
//log("found a pending payment with no payment index, refunding", fullAmount, "sats to user", p.user.user_id)
|
||||||
dbTx: true, description: "refund failed pending payment", exec: async tx => {
|
//await this.storage.txQueue.PushToQueue({
|
||||||
await this.storage.userStorage.IncrementUserBalance(p.user.user_id, fullAmount, "payment_refund:" + p.invoice, tx)
|
// dbTx: true, description: "refund failed pending payment", exec: async tx => {
|
||||||
await this.storage.paymentStorage.UpdateExternalPayment(p.serial_id, 0, 0, false)
|
// await this.storage.userStorage.IncrementUserBalance(p.user.user_id, fullAmount, "payment_refund:" + p.invoice, tx)
|
||||||
}
|
// await this.storage.paymentStorage.UpdateExternalPayment(p.serial_id, 0, 0, false)
|
||||||
})
|
// }
|
||||||
|
//})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
console.log({p})
|
||||||
const paymentRes = await this.lnd.GetPayment(p.paymentIndex)
|
const paymentRes = await this.lnd.GetPayment(p.paymentIndex)
|
||||||
const payment = paymentRes.payments[0]
|
const payment = paymentRes.payments[0]
|
||||||
if (!payment || Number(payment.paymentIndex) !== p.paymentIndex) {
|
if (!payment || Number(payment.paymentIndex) !== p.paymentIndex) {
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ export class Watchdog {
|
||||||
this.latestHtlcIndexOffset = fwEvents.lastOffsetIndex
|
this.latestHtlcIndexOffset = fwEvents.lastOffsetIndex
|
||||||
this.accumulatedHtlcFees = 0
|
this.accumulatedHtlcFees = 0
|
||||||
const paymentFound = await this.storage.paymentStorage.GetMaxPaymentIndex()
|
const paymentFound = await this.storage.paymentStorage.GetMaxPaymentIndex()
|
||||||
const knownMaxIndex = paymentFound.length > 0 ? paymentFound[0].paymentIndex : 0
|
const knownMaxIndex = paymentFound.length > 0 ? Math.max(paymentFound[0].paymentIndex,0) : 0
|
||||||
this.latestPaymentIndexOffset = await this.lnd.GetLatestPaymentIndex(knownMaxIndex)
|
this.latestPaymentIndexOffset = await this.lnd.GetLatestPaymentIndex(knownMaxIndex)
|
||||||
const other = { ilnd: this.initialLndBalance, hf: this.accumulatedHtlcFees, iu: this.initialUsersBalance, tu: totalUsersBalance, oext: otherExternal }
|
const other = { ilnd: this.initialLndBalance, hf: this.accumulatedHtlcFees, iu: this.initialUsersBalance, tu: totalUsersBalance, oext: otherExternal }
|
||||||
getLogger({ component: 'watchdog_debug2' })(JSON.stringify({ deltaLnd: 0, deltaUsers: 0, totalExternal, latestIndex: this.latestPaymentIndexOffset, other }))
|
getLogger({ component: 'watchdog_debug2' })(JSON.stringify({ deltaLnd: 0, deltaUsers: 0, totalExternal, latestIndex: this.latestPaymentIndexOffset, other }))
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ export class UserInvoicePayment {
|
||||||
liquidityProvider?: string
|
liquidityProvider?: string
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
default: 0,
|
default: -1,
|
||||||
})
|
})
|
||||||
paymentIndex: number
|
paymentIndex: number
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue