better logs

This commit is contained in:
boufni95 2024-07-27 19:43:33 +02:00
parent 5ab728bbc9
commit 421873a7de
2 changed files with 11 additions and 7 deletions

View file

@ -394,7 +394,8 @@ export default class {
this.utils.stateBundler.AddBalancePoint('channelBalance', totalLightningBalance) this.utils.stateBundler.AddBalancePoint('channelBalance', totalLightningBalance)
const totalLndBalance = confirmedWalletBalance + totalLightningBalance const totalLndBalance = confirmedWalletBalance + totalLightningBalance
this.utils.stateBundler.AddBalancePoint('totalLndBalance', totalLndBalance) this.utils.stateBundler.AddBalancePoint('totalLndBalance', totalLndBalance)
return totalLndBalance const othersFromLnd = { wc: Number(walletBalance.confirmedBalance), wu: Number(walletBalance.unconfirmedBalance), cl: Number(channelsBalance.localBalance?.msat), cul: Number(channelsBalance.unsettledLocalBalance?.msat), cr: Number(channelsBalance.remoteBalance?.msat), cur: Number(channelsBalance.unsettledRemoteBalance?.msat) }
return { totalLndBalance, othersFromLnd }
} }
async GetBalance(): Promise<BalanceInfo> { // TODO: remove this async GetBalance(): Promise<BalanceInfo> { // TODO: remove this

View file

@ -67,13 +67,14 @@ export class Watchdog {
await this.getTracker() await this.getTracker()
const totalUsersBalance = await this.storage.paymentStorage.GetTotalUsersBalance() const totalUsersBalance = await this.storage.paymentStorage.GetTotalUsersBalance()
this.utils.stateBundler.AddBalancePoint('usersBalance', totalUsersBalance) this.utils.stateBundler.AddBalancePoint('usersBalance', totalUsersBalance)
const { totalExternal } = await this.getAggregatedExternalBalance() const { totalExternal, otherExternal } = await this.getAggregatedExternalBalance()
this.initialLndBalance = totalExternal this.initialLndBalance = totalExternal
this.initialUsersBalance = totalUsersBalance this.initialUsersBalance = totalUsersBalance
const fwEvents = await this.lnd.GetForwardingHistory(0, this.startedAtUnix) const fwEvents = await this.lnd.GetForwardingHistory(0, this.startedAtUnix)
this.latestIndexOffset = fwEvents.lastOffsetIndex this.latestIndexOffset = fwEvents.lastOffsetIndex
this.accumulatedHtlcFees = 0 this.accumulatedHtlcFees = 0
const other = { ilnd: this.initialLndBalance, hf: this.accumulatedHtlcFees, iu: this.initialUsersBalance, tu: totalUsersBalance, oext: otherExternal }
getLogger({ component: 'watchdog_debug2' })(JSON.stringify({ deltaLnd: 0, deltaUsers: 0, totalExternal, other }))
this.interval = setInterval(() => { this.interval = setInterval(() => {
if (this.latestCheckStart + (1000 * 58) < Date.now()) { if (this.latestCheckStart + (1000 * 58) < Date.now()) {
this.PaymentRequested() this.PaymentRequested()
@ -93,11 +94,12 @@ export class Watchdog {
} }
getAggregatedExternalBalance = async () => { getAggregatedExternalBalance = async () => {
const totalLndBalance = await this.lnd.GetTotalBalace() const { totalLndBalance, othersFromLnd } = await this.lnd.GetTotalBalace()
const feesPaidForLiquidity = this.liquidityManager.GetPaidFees() const feesPaidForLiquidity = this.liquidityManager.GetPaidFees()
const pb = await this.rugPullTracker.CheckProviderBalance() const pb = await this.rugPullTracker.CheckProviderBalance()
const providerBalance = pb.prevBalance || pb.balance const providerBalance = pb.prevBalance || pb.balance
return { totalExternal: totalLndBalance + providerBalance + feesPaidForLiquidity, feesPaidForLiquidity, providerBalance, totalLndBalance } const otherExternal = { pb: providerBalance, f: feesPaidForLiquidity, lnd: totalLndBalance, olnd: othersFromLnd }
return { totalExternal: totalLndBalance + providerBalance + feesPaidForLiquidity, otherExternal }
} }
checkBalanceUpdate = async (deltaLnd: number, deltaUsers: number) => { checkBalanceUpdate = async (deltaLnd: number, deltaUsers: number) => {
@ -173,11 +175,12 @@ export class Watchdog {
await this.updateAccumulatedHtlcFees() await this.updateAccumulatedHtlcFees()
const totalUsersBalance = await this.storage.paymentStorage.GetTotalUsersBalance() const totalUsersBalance = await this.storage.paymentStorage.GetTotalUsersBalance()
this.utils.stateBundler.AddBalancePoint('usersBalance', totalUsersBalance) this.utils.stateBundler.AddBalancePoint('usersBalance', totalUsersBalance)
const { totalExternal, feesPaidForLiquidity, providerBalance, totalLndBalance } = await this.getAggregatedExternalBalance() const { totalExternal, otherExternal } = await this.getAggregatedExternalBalance()
this.utils.stateBundler.AddBalancePoint('accumulatedHtlcFees', this.accumulatedHtlcFees) this.utils.stateBundler.AddBalancePoint('accumulatedHtlcFees', this.accumulatedHtlcFees)
const deltaLnd = totalExternal - (this.initialLndBalance + this.accumulatedHtlcFees) const deltaLnd = totalExternal - (this.initialLndBalance + this.accumulatedHtlcFees)
const deltaUsers = totalUsersBalance - this.initialUsersBalance const deltaUsers = totalUsersBalance - this.initialUsersBalance
getLogger({ component: 'watchdog_debug' })(JSON.stringify({ deltaLnd, deltaUsers, totalExternal, initialLndBalance: this.initialLndBalance, accumulatedHtlcFees: this.accumulatedHtlcFees, initialUsersBalance: this.initialUsersBalance, totalUsersBalance, feesPaidForLiquidity, providerBalance, totalLndBalance })) const other = { ilnd: this.initialLndBalance, hf: this.accumulatedHtlcFees, iu: this.initialUsersBalance, tu: totalUsersBalance, oext: otherExternal }
getLogger({ component: 'watchdog_debug2' })(JSON.stringify({ deltaLnd, deltaUsers, totalExternal, other }))
const deny = await this.checkBalanceUpdate(deltaLnd, deltaUsers) const deny = await this.checkBalanceUpdate(deltaLnd, deltaUsers)
if (deny) { if (deny) {
this.log("Balance mismatch detected in absolute update, locking outgoing operations") this.log("Balance mismatch detected in absolute update, locking outgoing operations")