diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 5f0889ce..9a3fe1e8 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -9,3 +9,4 @@ updates: directory: "/" # Location of package manifests schedule: interval: "weekly" + branch: "test" diff --git a/package-lock.json b/package-lock.json index d959cec0..c3c48fc1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -53,7 +53,7 @@ "@types/chai": "^4.3.4", "@types/chai-string": "^1.4.5", "@types/cors": "^2.8.17", - "@types/eccrypto": "^1.1.3", + "@types/eccrypto": "^1.1.6", "@types/jsonwebtoken": "^9.0.6", "@types/lodash": "^4.14.182", "@types/node": "^16.11.10", @@ -598,10 +598,11 @@ } }, "node_modules/@types/eccrypto": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/@types/eccrypto/-/eccrypto-1.1.3.tgz", - "integrity": "sha512-3O0qER6JMYReqVbcQTGmXeMHdw3O+rVps63tlo5g5zoB3altJS8yzSvboSivwVWeYO9o5jSATu7P0UIqYZPgow==", + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/@types/eccrypto/-/eccrypto-1.1.6.tgz", + "integrity": "sha512-rsmcX5LdDZ3xN2W3al6+YR+XNmiQWlXSwVhsU184QOwNQNJ83YpwvAt8a7cT7y3RpVWkKWmXoIFdanI/z38rNQ==", "dev": true, + "license": "MIT", "dependencies": { "@types/expect": "^1.20.4", "@types/node": "*" diff --git a/package.json b/package.json index 36e7c437..635e9b84 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "@types/chai": "^4.3.4", "@types/chai-string": "^1.4.5", "@types/cors": "^2.8.17", - "@types/eccrypto": "^1.1.3", + "@types/eccrypto": "^1.1.6", "@types/jsonwebtoken": "^9.0.6", "@types/lodash": "^4.14.182", "@types/node": "^16.11.10", diff --git a/src/services/lnd/lnd.ts b/src/services/lnd/lnd.ts index 2d445d07..0cf25ba9 100644 --- a/src/services/lnd/lnd.ts +++ b/src/services/lnd/lnd.ts @@ -14,7 +14,7 @@ import { AddInvoiceReq } from './addInvoiceReq.js'; import { PayInvoiceReq } from './payInvoiceReq.js'; import { SendCoinsReq } from './sendCoinsReq.js'; import { LndSettings, AddressPaidCb, InvoicePaidCb, NodeInfo, Invoice, DecodedInvoice, PaidInvoice, NewBlockCb, HtlcCb, BalanceInfo } from './settings.js'; -import { getLogger } from '../helpers/logger.js'; +import { ERROR, getLogger } from '../helpers/logger.js'; import { HtlcEvent_EventType } from '../../../proto/lnd/router.js'; import { LiquidityProvider, LiquidityRequest } from '../main/liquidityProvider.js'; import { Utils } from '../helpers/utilsWrapper.js'; @@ -464,6 +464,25 @@ export default class { return res.response } + async GetPaymentFromHash(paymentHash: string): Promise { + const abortController = new AbortController() + const stream = this.router.trackPaymentV2({ + paymentHash: Buffer.from(paymentHash, 'hex'), + noInflightUpdates: false + }, { abort: abortController.signal }) + return new Promise((res, rej) => { + stream.responses.onError(error => { + this.log(ERROR, "error with trackPaymentV2", error.message) + rej(null) + }) + stream.responses.onMessage(payment => { + abortController.abort() + res(payment) + }) + }) + + } + async ListPeers() { const res = await this.lightning.listPeers({ latestError: true }, DeadLineMetadata()) return res.response diff --git a/src/services/main/paymentManager.ts b/src/services/main/paymentManager.ts index 28c539e6..91f27554 100644 --- a/src/services/main/paymentManager.ts +++ b/src/services/main/paymentManager.ts @@ -6,7 +6,7 @@ import { MainSettings } from './settings.js' import { InboundOptionals, defaultInvoiceExpiry } from '../storage/paymentStorage.js' import LND from '../lnd/lnd.js' import { Application } from '../storage/entity/Application.js' -import { getLogger, PubLogger } from '../helpers/logger.js' +import { ERROR, getLogger, PubLogger } from '../helpers/logger.js' import { UserReceivingAddress } from '../storage/entity/UserReceivingAddress.js' import { AddressPaidCb, InvoicePaidCb, PaidInvoice } from '../lnd/settings.js' import { UserReceivingInvoice, ZapInfo } from '../storage/entity/UserReceivingInvoice.js' @@ -124,23 +124,10 @@ export default class { } checkPendingLndPayment = async (log: PubLogger, p: UserInvoicePayment) => { - 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) { - log("lnd payment not found for pending payment", p.serial_id, "with index", p.paymentIndex) + const decoded = await this.lnd.DecodeInvoice(p.invoice) + const payment = await this.lnd.GetPaymentFromHash(decoded.paymentHash) + if (!payment || payment.paymentHash !== decoded.paymentHash) { + log(ERROR, "lnd payment not found for pending payment hash ", decoded.paymentHash) return }