diff --git a/src/services/lnd/liquidityProvider.ts b/src/services/lnd/liquidityProvider.ts index 78594c20..f14fd5bf 100644 --- a/src/services/lnd/liquidityProvider.ts +++ b/src/services/lnd/liquidityProvider.ts @@ -91,6 +91,9 @@ export class LiquidityProvider { } GetLatestMaxWithdrawable = async (fetch = false) => { + if (!this.pubDestination) { + return 0 + } if (this.latestMaxWithdrawable === null) { this.log("liquidity provider is not ready yet") return 0 @@ -102,6 +105,9 @@ export class LiquidityProvider { } GetLatestBalance = async (fetch = false) => { + if (!this.pubDestination) { + return 0 + } if (this.latestMaxWithdrawable === null) { this.log("liquidity provider is not ready yet") return 0 diff --git a/src/services/main/index.ts b/src/services/main/index.ts index 7a3c85d6..53bc2de5 100644 --- a/src/services/main/index.ts +++ b/src/services/main/index.ts @@ -191,7 +191,7 @@ export default class { this.sendOperationToNostr(userInvoice.linkedApplication, userInvoice.user.user_id, op) this.createZapReceipt(log, userInvoice) log("paid invoice processed successfully") - await this.liquidityManager.afterInInvoicePaid() + this.liquidityManager.afterInInvoicePaid() } catch (err: any) { log(ERROR, "cannot process paid invoice", err.message || "") } diff --git a/src/services/main/liquidityManager.ts b/src/services/main/liquidityManager.ts index 044517f1..6d81cf4b 100644 --- a/src/services/main/liquidityManager.ts +++ b/src/services/main/liquidityManager.ts @@ -72,6 +72,13 @@ export class LiquidityManager { return 'provider' } afterInInvoicePaid = async () => { + try { + await this.orderChannelIfNeeded() + } catch (e: any) { + this.log("error ordering channel", e) + } + } + orderChannelIfNeeded = async () => { const existingOrder = await this.storage.liquidityStorage.GetLatestLspOrder() if (existingOrder) { return diff --git a/src/services/main/sanityChecker.ts b/src/services/main/sanityChecker.ts index 0387036d..876c122e 100644 --- a/src/services/main/sanityChecker.ts +++ b/src/services/main/sanityChecker.ts @@ -104,10 +104,10 @@ export default class SanityChecker { } if (entry.paid_at_unix === -1) { this.decrementEvents[invoice] = { userId, refund: amt, failure: true } - } else { - const refund = amt - (entry.paid_amount + entry.routing_fees + entry.service_fees) - this.decrementEvents[invoice] = { userId, refund, failure: false } + return } + const refund = amt - (entry.paid_amount + entry.routing_fees + entry.service_fees) + this.decrementEvents[invoice] = { userId, refund, failure: false } if (!entry.internal && !entry.liquidityProvider) { const lndEntry = this.payments.find(i => i.paymentRequest === invoice) if (!lndEntry) { diff --git a/src/services/main/watchdog.ts b/src/services/main/watchdog.ts index 4e1b83dc..cb5432f0 100644 --- a/src/services/main/watchdog.ts +++ b/src/services/main/watchdog.ts @@ -102,7 +102,7 @@ export class Watchdog { const walletBalance = await this.lnd.GetWalletBalance() this.log(Number(walletBalance.confirmedBalance), "sats in chain wallet") const channelsBalance = await this.lnd.GetChannelBalance() - getLogger({ component: "debugLndBalancev3" })({ w: walletBalance, c: channelsBalance, u: usersTotal, f: this.accumulatedHtlcFees }) + // getLogger({ component: "debugLndBalancev3" })({ w: walletBalance, c: channelsBalance, u: usersTotal, f: this.accumulatedHtlcFees }) const totalLightningBalanceMsats = (channelsBalance.localBalance?.msat || 0n) + (channelsBalance.unsettledLocalBalance?.msat || 0n) const totalLightningBalance = Math.ceil(Number(totalLightningBalanceMsats) / 1000) const feesPaidForLiquidity = this.liquidityManager.GetPaidFees() diff --git a/src/services/nostr/handler.ts b/src/services/nostr/handler.ts index 1083f91c..b8a65633 100644 --- a/src/services/nostr/handler.ts +++ b/src/services/nostr/handler.ts @@ -99,18 +99,10 @@ export default class Handler { log = getLogger({ component: "nostrMiddleware" }) constructor(settings: NostrSettings, eventCallback: (event: NostrEvent) => void) { this.settings = settings - this.log( - { - ...settings, - apps: settings.apps.map(app => { - const { privateKey, ...rest } = app; - return { - ...rest, - nprofile: encodeNprofile({ pubkey: rest.publicKey, relays: settings.relays }) - } - }) - } - ) + this.log("connecting to relays:", settings.relays) + this.settings.apps.forEach(app => { + this.log("appId:", app.appId, "pubkey:", app.publicKey, "nprofile:", encodeNprofile({ pubkey: app.publicKey, relays: settings.relays })) + }) this.eventCallback = eventCallback this.settings.apps.forEach(app => { this.apps[app.publicKey] = app diff --git a/src/services/storage/transactionsQueue.ts b/src/services/storage/transactionsQueue.ts index 48e090e8..b9d5e322 100644 --- a/src/services/storage/transactionsQueue.ts +++ b/src/services/storage/transactionsQueue.ts @@ -20,21 +20,17 @@ export default class { PushToQueue(op: TxOperation) { if (!this.pendingTx) { - this.log("queue empty, starting transaction", this.transactionsQueue.length) return this.execQueueItem(op) } - this.log("queue not empty, possibly stuck") return new Promise((res, rej) => { this.transactionsQueue.push({ op, res, rej }) }) } async execNextInQueue() { - this.log("executing next in queue") this.pendingTx = false const next = this.transactionsQueue.pop() if (!next) { - this.log("queue is clear") return } try { @@ -51,7 +47,6 @@ export default class { throw new Error("cannot start DB transaction") } this.pendingTx = true - this.log("starting", op.dbTx ? "db transaction" : "operation", op.description || "") if (op.dbTx) { return this.doTransaction(op.exec) }