Merge pull request #665 from shocknet/log-channel-state

log channel state
This commit is contained in:
Justin (shocknet) 2024-04-05 13:54:46 -04:00 committed by GitHub
commit 51987d2a3c
5 changed files with 15 additions and 22 deletions

View file

@ -14,7 +14,7 @@ export default (serverMethods: Types.ServerMethods, mainHandler: Main, nostrSett
return { user_id: nostrUser.user.user_id, app_user_id: nostrUser.identifier, app_id: appId || "" } return { user_id: nostrUser.user.user_id, app_user_id: nostrUser.identifier, app_id: appId || "" }
}, },
metricsCallback: metrics => mainHandler.settings.recordPerformance ? mainHandler.metricsManager.AddMetrics(metrics) : null, metricsCallback: metrics => mainHandler.settings.recordPerformance ? mainHandler.metricsManager.AddMetrics(metrics) : null,
logger: { log, error: err => log("ERROR", err) } logger: { log: console.log, error: err => log("ERROR", err) }
}) })
const nostr = new Nostr(nostrSettings, event => { const nostr = new Nostr(nostrSettings, event => {
let j: NostrRequest let j: NostrRequest

View file

@ -17,16 +17,17 @@ type TxOutput = {
hash: string hash: string
index: number index: number
} }
export type ChannelBalance = {
channelId: string;
localBalanceSats: number;
remoteBalanceSats: number;
htlcs: { incoming: boolean, amount: number }[]
}
export type BalanceInfo = { export type BalanceInfo = {
confirmedBalance: number; confirmedBalance: number;
unconfirmedBalance: number; unconfirmedBalance: number;
totalBalance: number; totalBalance: number;
channelsBalance: { channelsBalance: ChannelBalance[];
channelId: string;
localBalanceSats: number;
remoteBalanceSats: number;
htlcs: { incoming: boolean, amount: number }[]
}[];
} }
export type AddressPaidCb = (txOutput: TxOutput, address: string, amount: number, internal: boolean) => void export type AddressPaidCb = (txOutput: TxOutput, address: string, amount: number, internal: boolean) => void

View file

@ -1,6 +1,7 @@
import { EnvCanBeInteger } from "../helpers/envParser.js"; import { EnvCanBeInteger } from "../helpers/envParser.js";
import { getLogger } from "../helpers/logger.js"; import { getLogger } from "../helpers/logger.js";
import { LightningHandler } from "../lnd/index.js"; import { LightningHandler } from "../lnd/index.js";
import { ChannelBalance } from "../lnd/settings.js";
import Storage from '../storage/index.js' import Storage from '../storage/index.js'
export type WatchdogSettings = { export type WatchdogSettings = {
maxDiffSats: number maxDiffSats: number
@ -48,20 +49,13 @@ export class Watchdog {
} }
getTotalLndBalance = async () => { getTotalLndBalance = async () => {
const localLog = getLogger({ appName: "debugLndBalance" })
const { confirmedBalance, channelsBalance } = await this.lnd.GetBalance() const { confirmedBalance, channelsBalance } = await this.lnd.GetBalance()
this.log(confirmedBalance, "sats in chain wallet") this.log(confirmedBalance, "sats in chain wallet")
let total = confirmedBalance localLog(channelsBalance)
channelsBalance.forEach(c => { return channelsBalance.reduce((acc, c) => {
let outgoingSats = 0 return acc + c.localBalanceSats + c.htlcs.reduce((acc2, htlc) => acc2 + (htlc.incoming ? htlc.amount : -htlc.amount), 0)
c.htlcs.forEach(htlc => { }, 0)
if (!htlc.incoming) {
outgoingSats += Number(htlc.amount)
}
})
total += Number(c.localBalanceSats) - outgoingSats
this.log(c.localBalanceSats, "sats in channel", c.channelId, "with", outgoingSats, "sats in pending outgoing htlcs")
})
return total
} }
checkBalanceUpdate = (deltaLnd: number, deltaUsers: number) => { checkBalanceUpdate = (deltaLnd: number, deltaUsers: number) => {

View file

@ -194,8 +194,6 @@ export default class Handler {
})) }))
if (!sent) { if (!sent) {
log("failed to send event") log("failed to send event")
} else {
log("event sent ok")
} }
} }

View file

@ -33,7 +33,7 @@ export default (mainHandler: Main): Types.ServerMethods => {
if (err != null) throw new Error(err.message) if (err != null) throw new Error(err.message)
await mainHandler.paymentManager.SetMockInvoiceAsPaid(req) await mainHandler.paymentManager.SetMockInvoiceAsPaid(req)
}, },
UserHealth: async () => { getLogger({})("got health request") }, UserHealth: async () => { },
GetUserInfo: ({ ctx }) => mainHandler.appUserManager.GetUserInfo(ctx), GetUserInfo: ({ ctx }) => mainHandler.appUserManager.GetUserInfo(ctx),
GetUserOperations: async ({ ctx, req }) => { GetUserOperations: async ({ ctx, req }) => {
return mainHandler.paymentManager.GetUserOperations(ctx.user_id, req) return mainHandler.paymentManager.GetUserOperations(ctx.user_id, req)