update watchdog strategy
This commit is contained in:
parent
1530f6b65e
commit
aa66e59fee
4 changed files with 15 additions and 20 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import * as Types from '../../../proto/autogenerated/ts/types.js'
|
import * as Types from '../../../proto/autogenerated/ts/types.js'
|
||||||
import { GetInfoResponse, NewAddressResponse, AddInvoiceResponse, PayReq, Payment, SendCoinsResponse, EstimateFeeResponse, TransactionDetails, ClosedChannelsResponse, ListChannelsResponse, PendingChannelsResponse, ListInvoiceResponse, ListPaymentsResponse, ChannelBalanceResponse } from '../../../proto/lnd/lightning.js'
|
import { GetInfoResponse, NewAddressResponse, AddInvoiceResponse, PayReq, Payment, SendCoinsResponse, EstimateFeeResponse, TransactionDetails, ClosedChannelsResponse, ListChannelsResponse, PendingChannelsResponse, ListInvoiceResponse, ListPaymentsResponse, ChannelBalanceResponse, WalletBalanceResponse } from '../../../proto/lnd/lightning.js'
|
||||||
import { EnvMustBeNonEmptyString, EnvMustBeInteger, EnvCanBeBoolean } from '../helpers/envParser.js'
|
import { EnvMustBeNonEmptyString, EnvMustBeInteger, EnvCanBeBoolean } from '../helpers/envParser.js'
|
||||||
import { AddressPaidCb, BalanceInfo, DecodedInvoice, HtlcCb, Invoice, InvoicePaidCb, LndSettings, NewBlockCb, NodeInfo, PaidInvoice } from './settings.js'
|
import { AddressPaidCb, BalanceInfo, DecodedInvoice, HtlcCb, Invoice, InvoicePaidCb, LndSettings, NewBlockCb, NodeInfo, PaidInvoice } from './settings.js'
|
||||||
import LND from './lnd.js'
|
import LND from './lnd.js'
|
||||||
|
|
@ -32,6 +32,7 @@ export interface LightningHandler {
|
||||||
ChannelBalance(): Promise<{ local: number, remote: number }>
|
ChannelBalance(): Promise<{ local: number, remote: number }>
|
||||||
GetTransactions(startHeight: number): Promise<TransactionDetails>
|
GetTransactions(startHeight: number): Promise<TransactionDetails>
|
||||||
GetBalance(): Promise<BalanceInfo>
|
GetBalance(): Promise<BalanceInfo>
|
||||||
|
GetWalletBalance(): Promise<WalletBalanceResponse>
|
||||||
GetChannelBalance(): Promise<ChannelBalanceResponse>
|
GetChannelBalance(): Promise<ChannelBalanceResponse>
|
||||||
ListClosedChannels(): Promise<ClosedChannelsResponse>
|
ListClosedChannels(): Promise<ClosedChannelsResponse>
|
||||||
ListChannels(): Promise<ListChannelsResponse>
|
ListChannels(): Promise<ListChannelsResponse>
|
||||||
|
|
|
||||||
|
|
@ -322,6 +322,11 @@ export default class {
|
||||||
return res.response
|
return res.response
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async GetWalletBalance() {
|
||||||
|
const res = await this.lightning.walletBalance({}, DeadLineMetadata())
|
||||||
|
return res.response
|
||||||
|
}
|
||||||
|
|
||||||
async GetBalance(): Promise<BalanceInfo> {
|
async GetBalance(): Promise<BalanceInfo> {
|
||||||
const wRes = await this.lightning.walletBalance({}, DeadLineMetadata())
|
const wRes = await this.lightning.walletBalance({}, DeadLineMetadata())
|
||||||
const { confirmedBalance, unconfirmedBalance, totalBalance } = wRes.response
|
const { confirmedBalance, unconfirmedBalance, totalBalance } = wRes.response
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import * as Types from '../../../proto/autogenerated/ts/types.js'
|
||||||
import { LightningClient } from '../../../proto/lnd/lightning.client.js'
|
import { LightningClient } from '../../../proto/lnd/lightning.client.js'
|
||||||
import { InvoicesClient } from '../../../proto/lnd/invoices.client.js'
|
import { InvoicesClient } from '../../../proto/lnd/invoices.client.js'
|
||||||
import { RouterClient } from '../../../proto/lnd/router.client.js'
|
import { RouterClient } from '../../../proto/lnd/router.client.js'
|
||||||
import { GetInfoResponse, AddressType, NewAddressResponse, AddInvoiceResponse, Invoice_InvoiceState, PayReq, Payment_PaymentStatus, Payment, PaymentFailureReason, SendCoinsResponse, EstimateFeeResponse, TransactionDetails, ClosedChannelsResponse, ListChannelsResponse, PendingChannelsResponse, ListInvoiceResponse, ListPaymentsResponse, ChannelBalanceResponse } from '../../../proto/lnd/lightning.js'
|
import { GetInfoResponse, AddressType, NewAddressResponse, AddInvoiceResponse, Invoice_InvoiceState, PayReq, Payment_PaymentStatus, Payment, PaymentFailureReason, SendCoinsResponse, EstimateFeeResponse, TransactionDetails, ClosedChannelsResponse, ListChannelsResponse, PendingChannelsResponse, ListInvoiceResponse, ListPaymentsResponse, ChannelBalanceResponse, WalletBalanceResponse } from '../../../proto/lnd/lightning.js'
|
||||||
import { OpenChannelReq } from './openChannelReq.js';
|
import { OpenChannelReq } from './openChannelReq.js';
|
||||||
import { AddInvoiceReq } from './addInvoiceReq.js';
|
import { AddInvoiceReq } from './addInvoiceReq.js';
|
||||||
import { PayInvoiceReq } from './payInvoiceReq.js';
|
import { PayInvoiceReq } from './payInvoiceReq.js';
|
||||||
|
|
@ -41,6 +41,7 @@ export default class {
|
||||||
Stop() { }
|
Stop() { }
|
||||||
async Warmup() { }
|
async Warmup() { }
|
||||||
|
|
||||||
|
async GetWalletBalance(): Promise<WalletBalanceResponse> { throw new Error("ListClosedChannels disabled in mock mode") }
|
||||||
async ListClosedChannels(): Promise<ClosedChannelsResponse> { throw new Error("ListClosedChannels disabled in mock mode") }
|
async ListClosedChannels(): Promise<ClosedChannelsResponse> { throw new Error("ListClosedChannels disabled in mock mode") }
|
||||||
async ListChannels(): Promise<ListChannelsResponse> { throw new Error("ListChannels disabled in mock mode") }
|
async ListChannels(): Promise<ListChannelsResponse> { throw new Error("ListChannels disabled in mock mode") }
|
||||||
async ListPendingChannels(): Promise<PendingChannelsResponse> { throw new Error("ListPendingChannels disabled in mock mode") }
|
async ListPendingChannels(): Promise<PendingChannelsResponse> { throw new Error("ListPendingChannels disabled in mock mode") }
|
||||||
|
|
|
||||||
|
|
@ -51,24 +51,12 @@ export class Watchdog {
|
||||||
|
|
||||||
|
|
||||||
getTotalLndBalance = async (usersTotal: number) => {
|
getTotalLndBalance = async (usersTotal: number) => {
|
||||||
const localLog = getLogger({ appName: "debugLndBalancev2" })
|
const walletBalance = await this.lnd.GetWalletBalance()
|
||||||
getLogger({ appName: "debugChannelBalanceRpc" })(await this.lnd.GetChannelBalance())
|
this.log(Number(walletBalance.confirmedBalance), "sats in chain wallet")
|
||||||
const { confirmedBalance, channelsBalance } = await this.lnd.GetBalance()
|
const channelsBalance = await this.lnd.GetChannelBalance()
|
||||||
this.log(confirmedBalance, "sats in chain wallet")
|
getLogger({ appName: "debugLndBalancev3" })({ w: walletBalance, c: channelsBalance, u: usersTotal })
|
||||||
localLog({ c: channelsBalance, u: usersTotal })
|
const localChannelsBalance = Number(channelsBalance.localBalance?.sat || 0)
|
||||||
let totalBalance = confirmedBalance
|
return Number(walletBalance.confirmedBalance) + localChannelsBalance
|
||||||
channelsBalance.forEach(c => {
|
|
||||||
let totalBalanceInHtlcs = 0
|
|
||||||
c.htlcs.forEach(htlc => {
|
|
||||||
if (htlc.incoming) {
|
|
||||||
totalBalanceInHtlcs += htlc.amount
|
|
||||||
} else {
|
|
||||||
//totalBalanceInHtlcs -= htlc.amount
|
|
||||||
}
|
|
||||||
})
|
|
||||||
totalBalance += c.localBalanceSats + totalBalanceInHtlcs
|
|
||||||
})
|
|
||||||
return totalBalance
|
|
||||||
}
|
}
|
||||||
|
|
||||||
checkBalanceUpdate = (deltaLnd: number, deltaUsers: number) => {
|
checkBalanceUpdate = (deltaLnd: number, deltaUsers: number) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue