From b21c24ae6e0236bad99b02a811badf524f875da6 Mon Sep 17 00:00:00 2001 From: boufni95 Date: Sat, 26 Oct 2024 22:11:23 +0000 Subject: [PATCH 1/2] dont log on abort --- src/services/lnd/lnd.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/services/lnd/lnd.ts b/src/services/lnd/lnd.ts index 0cf25ba9..ed4f7c62 100644 --- a/src/services/lnd/lnd.ts +++ b/src/services/lnd/lnd.ts @@ -472,12 +472,14 @@ export default class { }, { abort: abortController.signal }) return new Promise((res, rej) => { stream.responses.onError(error => { - this.log(ERROR, "error with trackPaymentV2", error.message) - rej(null) + if (abortController.signal.aborted) { + this.log(ERROR, "error with trackPaymentV2", error.message) + rej(null) + } }) stream.responses.onMessage(payment => { - abortController.abort() res(payment) + abortController.abort() }) }) From 1b05a0e6483dd2098b9b4641fe181ac26edd02d8 Mon Sep 17 00:00:00 2001 From: boufni95 Date: Mon, 28 Oct 2024 16:20:59 +0000 Subject: [PATCH 2/2] fix tx in tx --- src/services/main/paymentManager.ts | 17 +++++++---------- src/services/storage/paymentStorage.ts | 11 +++++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/services/main/paymentManager.ts b/src/services/main/paymentManager.ts index 91f27554..1bc5ded1 100644 --- a/src/services/main/paymentManager.ts +++ b/src/services/main/paymentManager.ts @@ -71,13 +71,12 @@ export default class { const log = getLogger({ component: 'pendingPaymentsOnStart' }) const pendingPayments = await this.storage.paymentStorage.GetPendingPayments() for (const p of pendingPayments) { + log("checking state of payment: ", p.invoice) if (p.internal) { log("found pending internal payment", p.serial_id) - return } else if (p.liquidityProvider) { log("found pending liquidity provider payment", p.serial_id) await this.checkPendingProviderPayment(log, p) - return } else { log("found pending external payment", p.serial_id) await this.checkPendingLndPayment(log, p) @@ -93,7 +92,7 @@ export default class { await this.storage.txQueue.PushToQueue({ dbTx: true, description: "refund failed provider 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) + await this.storage.paymentStorage.UpdateExternalPayment(p.serial_id, 0, 0, false, undefined, tx) } }) return @@ -106,9 +105,9 @@ export default class { dbTx: true, description: "pending provider payment success after restart", exec: async tx => { if (routingFeeLimit - actualFee > 0) { this.log("refund pending provider payment routing fee", routingFeeLimit, actualFee, "sats") - await this.storage.userStorage.IncrementUserBalance(p.user.user_id, routingFeeLimit - actualFee, "routing_fee_refund:" + p.invoice) + await this.storage.userStorage.IncrementUserBalance(p.user.user_id, routingFeeLimit - actualFee, "routing_fee_refund:" + p.invoice, tx) } - await this.storage.paymentStorage.UpdateExternalPayment(p.serial_id, actualFee, p.service_fees, true) + await this.storage.paymentStorage.UpdateExternalPayment(p.serial_id, actualFee, p.service_fees, true, undefined, tx) } }) if (p.linkedApplication && p.user.user_id !== p.linkedApplication.owner.user_id && serviceFee > 0) { @@ -119,8 +118,6 @@ export default class { return } log("provider payment still pending", p.serial_id, "no action will be performed") - - } checkPendingLndPayment = async (log: PubLogger, p: UserInvoicePayment) => { @@ -147,9 +144,9 @@ export default class { dbTx: true, description: "pending payment success after restart", exec: async tx => { if (routingFeeLimit - actualFee > 0) { this.log("refund pending payment routing fee", routingFeeLimit, actualFee, "sats") - await this.storage.userStorage.IncrementUserBalance(p.user.user_id, routingFeeLimit - actualFee, "routing_fee_refund:" + p.invoice) + await this.storage.userStorage.IncrementUserBalance(p.user.user_id, routingFeeLimit - actualFee, "routing_fee_refund:" + p.invoice, tx) } - await this.storage.paymentStorage.UpdateExternalPayment(p.serial_id, actualFee, p.service_fees, true) + await this.storage.paymentStorage.UpdateExternalPayment(p.serial_id, actualFee, p.service_fees, true, undefined, tx) } }) if (p.linkedApplication && p.user.user_id !== p.linkedApplication.owner.user_id && serviceFee > 0) { @@ -164,7 +161,7 @@ export default class { 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) + await this.storage.paymentStorage.UpdateExternalPayment(p.serial_id, 0, 0, false, undefined, tx) } }) default: diff --git a/src/services/storage/paymentStorage.ts b/src/services/storage/paymentStorage.ts index d5e3e7c1..06e3043a 100644 --- a/src/services/storage/paymentStorage.ts +++ b/src/services/storage/paymentStorage.ts @@ -177,13 +177,16 @@ export default class { async SetExternalPaymentIndex(invoicePaymentSerialId: number, index: number, entityManager = this.DB) { return entityManager.getRepository(UserInvoicePayment).update(invoicePaymentSerialId, { paymentIndex: index }) } - async UpdateExternalPayment(invoicePaymentSerialId: number, routingFees: number, serviceFees: number, success: boolean, providerDestination?: string) { - return this.DB.getRepository(UserInvoicePayment).update(invoicePaymentSerialId, { + async UpdateExternalPayment(invoicePaymentSerialId: number, routingFees: number, serviceFees: number, success: boolean, providerDestination?: string, entityManager = this.DB) { + const up: Partial = { routing_fees: routingFees, service_fees: serviceFees, paid_at_unix: success ? Math.floor(Date.now() / 1000) : -1, - liquidityProvider: providerDestination - }) + } + if (providerDestination) { + up.liquidityProvider = providerDestination + } + return entityManager.getRepository(UserInvoicePayment).update(invoicePaymentSerialId, up) } async AddInternalPayment(userId: string, invoice: string, amount: number, serviceFees: number, linkedApplication: Application, debitNpub?: string): Promise {