Skip to content

Commit

Permalink
better logs
Browse files Browse the repository at this point in the history
  • Loading branch information
boufni95 committed Jul 27, 2024
1 parent 6133baf commit fd3f836
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/services/lnd/lnd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ export default class {
this.utils.stateBundler.AddBalancePoint('channelBalance', totalLightningBalance)
const totalLndBalance = confirmedWalletBalance + totalLightningBalance
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
Expand Down
15 changes: 9 additions & 6 deletions src/services/main/watchdog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@ export class Watchdog {
await this.getTracker()
const totalUsersBalance = await this.storage.paymentStorage.GetTotalUsersBalance()
this.utils.stateBundler.AddBalancePoint('usersBalance', totalUsersBalance)
const { totalExternal } = await this.getAggregatedExternalBalance()
const { totalExternal, otherExternal } = await this.getAggregatedExternalBalance()
this.initialLndBalance = totalExternal
this.initialUsersBalance = totalUsersBalance
const fwEvents = await this.lnd.GetForwardingHistory(0, this.startedAtUnix)
this.latestIndexOffset = fwEvents.lastOffsetIndex
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(() => {
if (this.latestCheckStart + (1000 * 58) < Date.now()) {
this.PaymentRequested()
Expand All @@ -93,11 +94,12 @@ export class Watchdog {
}

getAggregatedExternalBalance = async () => {
const totalLndBalance = await this.lnd.GetTotalBalace()
const { totalLndBalance, othersFromLnd } = await this.lnd.GetTotalBalace()
const feesPaidForLiquidity = this.liquidityManager.GetPaidFees()
const pb = await this.rugPullTracker.CheckProviderBalance()
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) => {
Expand Down Expand Up @@ -173,11 +175,12 @@ export class Watchdog {
await this.updateAccumulatedHtlcFees()
const totalUsersBalance = await this.storage.paymentStorage.GetTotalUsersBalance()
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)
const deltaLnd = totalExternal - (this.initialLndBalance + this.accumulatedHtlcFees)
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)
if (deny) {
this.log("Balance mismatch detected in absolute update, locking outgoing operations")
Expand Down

0 comments on commit fd3f836

Please sign in to comment.