From 4b876e648d8eadca1316577d46cd2234fcaa5eed Mon Sep 17 00:00:00 2001 From: boufni95 Date: Fri, 9 Aug 2024 14:02:31 +0200 Subject: [PATCH] fix race cond --- src/services/main/paymentManager.ts | 2 +- src/services/storage/paymentStorage.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/services/main/paymentManager.ts b/src/services/main/paymentManager.ts index 7e74888a..9b7dbe60 100644 --- a/src/services/main/paymentManager.ts +++ b/src/services/main/paymentManager.ts @@ -337,7 +337,7 @@ export default class { const pendingPayment = await this.storage.txQueue.PushToQueue({ dbTx: true, description: "payment started", exec: async tx => { await this.storage.userStorage.DecrementUserBalance(userId, totalAmountToDecrement + routingFeeLimit, invoice, tx) - return await this.storage.paymentStorage.AddPendingExternalPayment(userId, invoice, { payAmount, serviceFee, networkFee: routingFeeLimit }, linkedApplication, provider) + return await this.storage.paymentStorage.AddPendingExternalPayment(userId, invoice, { payAmount, serviceFee, networkFee: routingFeeLimit }, linkedApplication, provider,tx) } }) this.log("ready to pay") diff --git a/src/services/storage/paymentStorage.ts b/src/services/storage/paymentStorage.ts index 14669ee6..fa8b8786 100644 --- a/src/services/storage/paymentStorage.ts +++ b/src/services/storage/paymentStorage.ts @@ -154,9 +154,9 @@ export default class { }) } - async AddPendingExternalPayment(userId: string, invoice: string, amounts: { payAmount: number, serviceFee: number, networkFee: number }, linkedApplication: Application, liquidityProvider: string | undefined): Promise { - const newPayment = this.DB.getRepository(UserInvoicePayment).create({ - user: await this.userStorage.GetUser(userId), + async AddPendingExternalPayment(userId: string, invoice: string, amounts: { payAmount: number, serviceFee: number, networkFee: number }, linkedApplication: Application, liquidityProvider: string | undefined,dbTx:DataSource|EntityManager): Promise { + const newPayment = dbTx.getRepository(UserInvoicePayment).create({ + user: await this.userStorage.GetUser(userId,dbTx), paid_amount: amounts.payAmount, invoice, routing_fees: amounts.networkFee, @@ -166,7 +166,7 @@ export default class { linkedApplication, liquidityProvider }) - return this.txQueue.PushToQueue({ exec: async db => db.getRepository(UserInvoicePayment).save(newPayment), dbTx: false, description: `add pending invoice payment for ${userId} linked to ${linkedApplication.app_id}: ${invoice}, amt: ${amounts.payAmount} ` }) + return dbTx.getRepository(UserInvoicePayment).save(newPayment) } async GetMaxPaymentIndex(entityManager = this.DB) {