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) {
|
||||
if (paymentIndex === 0) {
|
||||
throw new Error("payment index starts from 1")
|
||||
}
|
||||
const indexOffset = BigInt(paymentIndex - 1)
|
||||
const res = await this.lightning.listPayments({
|
||||
countTotalPayments: false, includeIncomplete: true, indexOffset, maxPayments: 1n, reversed: false
|
||||
|
|
|
|||
|
|
@ -72,8 +72,8 @@ export const initMainHandler = async (log: PubLogger, mainSettings: MainSettings
|
|||
if (stop) {
|
||||
return
|
||||
}
|
||||
mainHandler.paymentManager.checkPendingPayments()
|
||||
mainHandler.paymentManager.watchDog.Start()
|
||||
await mainHandler.paymentManager.checkPendingPayments()
|
||||
await mainHandler.paymentManager.watchDog.Start()
|
||||
return { mainHandler, apps, liquidityProviderInfo, liquidityProviderApp, wizard, adminManager }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -123,17 +123,19 @@ export default class {
|
|||
}
|
||||
|
||||
checkPendingLndPayment = async (log: PubLogger, p: UserInvoicePayment) => {
|
||||
if (p.paymentIndex === 0) {
|
||||
const fullAmount = p.paid_amount + p.service_fees + p.routing_fees
|
||||
log("found a pending payment with no payment index, refunding", fullAmount, "sats to user", p.user.user_id)
|
||||
await this.storage.txQueue.PushToQueue({
|
||||
dbTx: true, description: "refund failed pending payment", exec: async tx => {
|
||||
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)
|
||||
}
|
||||
})
|
||||
if (p.paymentIndex === 0 || p.paymentIndex === -1) {
|
||||
log("found a pending payment with no payment index, skipping", p.serial_id)
|
||||
//const fullAmount = p.paid_amount + p.service_fees + p.routing_fees
|
||||
//log("found a pending payment with no payment index, refunding", fullAmount, "sats to user", p.user.user_id)
|
||||
//await this.storage.txQueue.PushToQueue({
|
||||
// dbTx: true, description: "refund failed pending payment", exec: async tx => {
|
||||
// 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
|
||||
}
|
||||
console.log({p})
|
||||
const paymentRes = await this.lnd.GetPayment(p.paymentIndex)
|
||||
const payment = paymentRes.payments[0]
|
||||
if (!payment || Number(payment.paymentIndex) !== p.paymentIndex) {
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ export class Watchdog {
|
|||
this.latestHtlcIndexOffset = fwEvents.lastOffsetIndex
|
||||
this.accumulatedHtlcFees = 0
|
||||
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)
|
||||
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 }))
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ export class UserInvoicePayment {
|
|||
liquidityProvider?: string
|
||||
|
||||
@Column({
|
||||
default: 0,
|
||||
default: -1,
|
||||
})
|
||||
paymentIndex: number
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue