lnd metrics

This commit is contained in:
boufni95 2024-01-09 21:42:40 +01:00
parent 9b8e1c32c8
commit d1126940c3
9 changed files with 3752 additions and 3388 deletions

View file

@ -432,94 +432,44 @@ The nostr server will send back a message response, and inside the body there wi
## Messages ## Messages
### The content of requests and response from the methods ### The content of requests and response from the methods
### SetMockAppUserBalanceRequest ### ChannelBalanceEvent
- __user_identifier__: _string_ - __block_height__: _number_
- __channel_id__: _string_
- __local_balance_sats__: _number_
- __remote_balance_sats__: _number_
### SendAppUserToAppPaymentRequest
- __from_user_identifier__: _string_
- __amount__: _number_ - __amount__: _number_
### PayAddressRequest
- __address__: _string_
- __amoutSats__: _number_
- __satsPerVByte__: _number_
### OpenChannelRequest
- __destination__: _string_
- __fundingAmount__: _number_
- __pushAmount__: _number_
- __closeAddress__: _string_
### GetProductBuyLinkResponse
- __link__: _string_
### RelaysMigration
- __relays__: ARRAY of: _string_
### Empty
### AddAppUserRequest
- __identifier__: _string_
- __fail_if_exists__: _boolean_
- __balance__: _number_
### PayAddressResponse
- __txId__: _string_
- __operation_id__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
### NewAddressRequest ### NewAddressRequest
- __addressType__: _[AddressType](#AddressType)_ - __addressType__: _[AddressType](#AddressType)_
### DecodeInvoiceRequest ### OpenChannelResponse
- __invoice__: _string_ - __channelId__: _string_
### LnurlLinkResponse
- __lnurl__: _string_
- __k1__: _string_
### MigrationUpdate
- __closure__: _[ClosureMigration](#ClosureMigration)_ *this field is optional
- __relays__: _[RelaysMigration](#RelaysMigration)_ *this field is optional
### LndNodeMetrics
- __channels_balance_events__: ARRAY of: _[ChannelBalanceEvent](#ChannelBalanceEvent)_
- __chain_balance_events__: ARRAY of: _[ChainBalanceEvent](#ChainBalanceEvent)_
- __routing_events__: ARRAY of: _[RoutingEvent](#RoutingEvent)_
### AuthAppRequest
- __name__: _string_
- __allow_user_creation__: _boolean_ *this field is optional
### Application
- __name__: _string_
- __id__: _string_
- __balance__: _number_
- __npub__: _string_
### UsageMetric
- __processed_at_ms__: _number_
- __parsed_in_nano__: _number_
- __auth_in_nano__: _number_
- __validate_in_nano__: _number_
- __handle_in_nano__: _number_
- __rpc_name__: _string_
- __batch__: _boolean_
- __nostr__: _boolean_
- __batch_size__: _number_
### AppMetrics
- __app__: _[Application](#Application)_
- __users__: _[UsersInfo](#UsersInfo)_
- __total_received__: _number_
- __total_spent__: _number_
- __total_available__: _number_
- __unpaid_invoices__: _number_
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
### UserOperations ### UserOperations
- __fromIndex__: _number_ - __fromIndex__: _number_
- __toIndex__: _number_ - __toIndex__: _number_
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_ - __operations__: ARRAY of: _[UserOperation](#UserOperation)_
### AppsMetrics
- __apps__: ARRAY of: _[AppMetrics](#AppMetrics)_
### LndMetricsRequest
- __from_unix__: _number_ *this field is optional
- __to_unix__: _number_ *this field is optional
### AuthAppRequest
- __name__: _string_
- __allow_user_creation__: _boolean_ *this field is optional
### UsageMetrics
- __metrics__: ARRAY of: _[UsageMetric](#UsageMetric)_
### GetAppUserRequest
- __user_identifier__: _string_
### GetUserOperationsResponse ### GetUserOperationsResponse
- __latestOutgoingInvoiceOperations__: _[UserOperations](#UserOperations)_ - __latestOutgoingInvoiceOperations__: _[UserOperations](#UserOperations)_
- __latestIncomingInvoiceOperations__: _[UserOperations](#UserOperations)_ - __latestIncomingInvoiceOperations__: _[UserOperations](#UserOperations)_
@ -528,59 +478,84 @@ The nostr server will send back a message response, and inside the body there wi
- __latestOutgoingUserToUserPayemnts__: _[UserOperations](#UserOperations)_ - __latestOutgoingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
- __latestIncomingUserToUserPayemnts__: _[UserOperations](#UserOperations)_ - __latestIncomingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
### LndMetrics ### PayInvoiceResponse
- __nodes__: ARRAY of: _[LndNodeMetrics](#LndNodeMetrics)_ - __preimage__: _string_
- __amount_paid__: _number_
- __operation_id__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
### GetAppUserLNURLInfoRequest ### LnurlLinkResponse
- __user_identifier__: _string_ - __lnurl__: _string_
- __base_url_override__: _string_ - __k1__: _string_
### GetProductBuyLinkResponse
- __link__: _string_
### ClosureMigration
- __closes_at_unix__: _number_
### HandleLnurlPayResponse
- __pr__: _string_
- __routes__: ARRAY of: _[Empty](#Empty)_
### ClosedChannel
- __channel_id__: _string_
- __capacity__: _number_
- __closed_height__: _number_
### LndGetInfoRequest
- __nodeId__: _number_
### Application
- __name__: _string_
- __id__: _string_
- __balance__: _number_
- __npub__: _string_
### AddAppUserInvoiceRequest
- __receiver_identifier__: _string_
- __payer_identifier__: _string_
- __http_callback_url__: _string_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
### PayInvoiceRequest ### PayInvoiceRequest
- __invoice__: _string_ - __invoice__: _string_
- __amount__: _number_ - __amount__: _number_
### UserOperation ### OpenChannelRequest
- __paidAtUnix__: _number_ - __destination__: _string_
- __type__: _[UserOperationType](#UserOperationType)_ - __fundingAmount__: _number_
- __inbound__: _boolean_ - __pushAmount__: _number_
- __closeAddress__: _string_
### SetMockAppUserBalanceRequest
- __user_identifier__: _string_
- __amount__: _number_ - __amount__: _number_
- __identifier__: _string_
- __operationId__: _string_ ### Empty
### ChainBalanceEvent
- __block_height__: _number_
- __confirmed_balance__: _number_
- __unconfirmed_balance__: _number_
- __total_balance__: _number_
### SetMockInvoiceAsPaidRequest
- __invoice__: _string_
- __amount__: _number_
### NewAddressResponse
- __address__: _string_
### PayAddressResponse
- __txId__: _string_
- __operation_id__: _string_
- __service_fee__: _number_ - __service_fee__: _number_
- __network_fee__: _number_ - __network_fee__: _number_
- __confirmed__: _boolean_
### EncryptionExchangeRequest ### DecodeInvoiceRequest
- __publicKey__: _string_ - __invoice__: _string_
- __deviceId__: _string_
### AddAppInvoiceRequest
- __payer_identifier__: _string_
- __http_callback_url__: _string_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
### GetUserOperationsRequest
- __latestIncomingInvoice__: _number_
- __latestOutgoingInvoice__: _number_
- __latestIncomingTx__: _number_
- __latestOutgoingTx__: _number_
- __latestIncomingUserToUserPayment__: _number_
- __latestOutgoingUserToUserPayment__: _number_
### UsersInfo
- __total__: _number_
- __no_balance__: _number_
- __negative_balance__: _number_
- __always_been_inactive__: _number_
- __balance_avg__: _number_
- __balance_median__: _number_
### SendAppUserToAppPaymentRequest
- __from_user_identifier__: _string_
- __amount__: _number_
### DecodeInvoiceResponse
- __amount__: _number_
### RoutingEvent ### RoutingEvent
- __incoming_channel_id__: _number_ - __incoming_channel_id__: _number_
@ -596,117 +571,22 @@ The nostr server will send back a message response, and inside the body there wi
- __offchain__: _boolean_ - __offchain__: _boolean_
- __forward_fail_event__: _boolean_ - __forward_fail_event__: _boolean_
### LndGetInfoRequest ### LndNodeMetrics
- __nodeId__: _number_ - __channels_balance_events__: ARRAY of: _[ChannelBalanceEvent](#ChannelBalanceEvent)_
- __chain_balance_events__: ARRAY of: _[ChainBalanceEvent](#ChainBalanceEvent)_
### NewAddressResponse - __routing_events__: ARRAY of: _[RoutingEvent](#RoutingEvent)_
- __address__: _string_ - __offline_channels__: _number_
- __online_channels__: _number_
### LnurlPayInfoResponse - __pending_channels__: _number_
- __tag__: _string_ - __closing_channels__: _number_
- __callback__: _string_ - __open_channels__: ARRAY of: _[OpenChannel](#OpenChannel)_
- __maxSendable__: _number_ - __closed_channels__: ARRAY of: _[ClosedChannel](#ClosedChannel)_
- __minSendable__: _number_
- __metadata__: _string_
- __allowsNostr__: _boolean_
- __nostrPubkey__: _string_
### Product
- __id__: _string_
- __name__: _string_
- __price_sats__: _number_
### LndGetInfoResponse
- __alias__: _string_
### AppUser
- __identifier__: _string_
- __info__: _[UserInfo](#UserInfo)_
- __max_withdrawable__: _number_
### UserInfo
- __userId__: _string_
- __balance__: _number_
- __max_withdrawable__: _number_
### OpenChannelResponse
- __channelId__: _string_
### AddProductRequest
- __name__: _string_
- __price_sats__: _number_
### AppsMetricsRequest
- __from_unix__: _number_ *this field is optional
- __to_unix__: _number_ *this field is optional
- __include_operations__: _boolean_ *this field is optional
### SetMockInvoiceAsPaidRequest
- __invoice__: _string_
- __amount__: _number_
### NewInvoiceResponse
- __invoice__: _string_
### LiveUserOperation
- __operation__: _[UserOperation](#UserOperation)_
### ClosureMigration
- __closes_at_unix__: _number_
### UsageMetrics
- __metrics__: ARRAY of: _[UsageMetric](#UsageMetric)_
### ChainBalanceEvent
- __block_height__: _number_
- __confirmed_balance__: _number_
- __unconfirmed_balance__: _number_
- __total_balance__: _number_
### NewInvoiceRequest
- __amountSats__: _number_
- __memo__: _string_
### PayAppUserInvoiceRequest
- __user_identifier__: _string_
- __invoice__: _string_
- __amount__: _number_
### SendAppUserToAppUserPaymentRequest ### SendAppUserToAppUserPaymentRequest
- __from_user_identifier__: _string_ - __from_user_identifier__: _string_
- __to_user_identifier__: _string_ - __to_user_identifier__: _string_
- __amount__: _number_ - __amount__: _number_
### AddAppRequest
- __name__: _string_
- __allow_user_creation__: _boolean_
### AddAppUserInvoiceRequest
- __receiver_identifier__: _string_
- __payer_identifier__: _string_
- __http_callback_url__: _string_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
### GetAppUserRequest
- __user_identifier__: _string_
### AppsMetrics
- __apps__: ARRAY of: _[AppMetrics](#AppMetrics)_
### HandleLnurlPayResponse
- __pr__: _string_
- __routes__: ARRAY of: _[Empty](#Empty)_
### SetMockAppBalanceRequest
- __amount__: _number_
### PayInvoiceResponse
- __preimage__: _string_
- __amount_paid__: _number_
- __operation_id__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
### LnurlWithdrawInfoResponse ### LnurlWithdrawInfoResponse
- __tag__: _string_ - __tag__: _string_
- __callback__: _string_ - __callback__: _string_
@ -717,19 +597,158 @@ The nostr server will send back a message response, and inside the body there wi
- __balanceCheck__: _string_ - __balanceCheck__: _string_
- __payLink__: _string_ - __payLink__: _string_
### LndMetricsRequest ### AddProductRequest
- __from_unix__: _number_ *this field is optional - __name__: _string_
- __to_unix__: _number_ *this field is optional - __price_sats__: _number_
### ChannelBalanceEvent ### NewInvoiceResponse
- __block_height__: _number_ - __invoice__: _string_
- __channel_id__: _string_
- __local_balance_sats__: _number_ ### LndMetrics
- __remote_balance_sats__: _number_ - __nodes__: ARRAY of: _[LndNodeMetrics](#LndNodeMetrics)_
### AuthApp ### AuthApp
- __app__: _[Application](#Application)_ - __app__: _[Application](#Application)_
- __auth_token__: _string_ - __auth_token__: _string_
### AddAppInvoiceRequest
- __payer_identifier__: _string_
- __http_callback_url__: _string_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
### UsageMetric
- __processed_at_ms__: _number_
- __parsed_in_nano__: _number_
- __auth_in_nano__: _number_
- __validate_in_nano__: _number_
- __handle_in_nano__: _number_
- __rpc_name__: _string_
- __batch__: _boolean_
- __nostr__: _boolean_
- __batch_size__: _number_
### RelaysMigration
- __relays__: ARRAY of: _string_
### LiveUserOperation
- __operation__: _[UserOperation](#UserOperation)_
### AppsMetricsRequest
- __from_unix__: _number_ *this field is optional
- __to_unix__: _number_ *this field is optional
- __include_operations__: _boolean_ *this field is optional
### AddAppRequest
- __name__: _string_
- __allow_user_creation__: _boolean_
### SetMockAppBalanceRequest
- __amount__: _number_
### LnurlPayInfoResponse
- __tag__: _string_
- __callback__: _string_
- __maxSendable__: _number_
- __minSendable__: _number_
- __metadata__: _string_
- __allowsNostr__: _boolean_
- __nostrPubkey__: _string_
### UserOperation
- __paidAtUnix__: _number_
- __type__: _[UserOperationType](#UserOperationType)_
- __inbound__: _boolean_
- __amount__: _number_
- __identifier__: _string_
- __operationId__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
- __confirmed__: _boolean_
### Product
- __id__: _string_
- __name__: _string_
- __price_sats__: _number_
### UsersInfo
- __total__: _number_
- __no_balance__: _number_
- __negative_balance__: _number_
- __always_been_inactive__: _number_
- __balance_avg__: _number_
- __balance_median__: _number_
### OpenChannel
- __channel_id__: _string_
- __capacity__: _number_
- __active__: _boolean_
- __lifetime__: _number_
- __local_balance__: _number_
- __remote_balance__: _number_
### AppUser
- __identifier__: _string_
- __info__: _[UserInfo](#UserInfo)_
- __max_withdrawable__: _number_
### GetAppUserLNURLInfoRequest
- __user_identifier__: _string_
- __base_url_override__: _string_
### PayAppUserInvoiceRequest
- __user_identifier__: _string_
- __invoice__: _string_
- __amount__: _number_
### UserInfo
- __userId__: _string_
- __balance__: _number_
- __max_withdrawable__: _number_
### MigrationUpdate
- __closure__: _[ClosureMigration](#ClosureMigration)_ *this field is optional
- __relays__: _[RelaysMigration](#RelaysMigration)_ *this field is optional
### EncryptionExchangeRequest
- __publicKey__: _string_
- __deviceId__: _string_
### AppMetrics
- __app__: _[Application](#Application)_
- __users__: _[UsersInfo](#UsersInfo)_
- __total_received__: _number_
- __total_spent__: _number_
- __total_available__: _number_
- __unpaid_invoices__: _number_
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
### DecodeInvoiceResponse
- __amount__: _number_
### GetUserOperationsRequest
- __latestIncomingInvoice__: _number_
- __latestOutgoingInvoice__: _number_
- __latestIncomingTx__: _number_
- __latestOutgoingTx__: _number_
- __latestIncomingUserToUserPayment__: _number_
- __latestOutgoingUserToUserPayment__: _number_
### LndGetInfoResponse
- __alias__: _string_
### AddAppUserRequest
- __identifier__: _string_
- __fail_if_exists__: _boolean_
- __balance__: _number_
### PayAddressRequest
- __address__: _string_
- __amoutSats__: _number_
- __satsPerVByte__: _number_
### NewInvoiceRequest
- __amountSats__: _number_
- __memo__: _string_
## Enums ## Enums
### The enumerators used in the messages ### The enumerators used in the messages

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -96,14 +96,35 @@ message ChainBalanceEvent {
int64 total_balance = 4; int64 total_balance = 4;
} }
message OpenChannel {
string channel_id = 1;
int64 capacity = 2;
bool active = 3;
int64 lifetime =4 ;
int64 local_balance=5;
int64 remote_balance = 6;
}
message ClosedChannel {
string channel_id = 1;
int64 capacity = 2;
int64 closed_height =4;
}
message LndNodeMetrics { message LndNodeMetrics {
repeated ChannelBalanceEvent channels_balance_events = 1; repeated ChannelBalanceEvent channels_balance_events = 1;
repeated ChainBalanceEvent chain_balance_events = 2; repeated ChainBalanceEvent chain_balance_events = 2;
repeated RoutingEvent routing_events = 3; repeated RoutingEvent routing_events = 3;
int64 offline_channels = 4;
int64 online_channels = 5;
int64 pending_channels = 6;
int64 closing_channels = 7;
repeated OpenChannel open_channels = 8;
repeated ClosedChannel closed_channels = 9;
} }
message LndMetrics { message LndMetrics {
repeated LndNodeMetrics nodes = 1; repeated LndNodeMetrics nodes = 1;
} }
message LndGetInfoRequest { message LndGetInfoRequest {

View file

@ -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 } from '../../../proto/lnd/lightning.js' import { GetInfoResponse, NewAddressResponse, AddInvoiceResponse, PayReq, Payment, SendCoinsResponse, EstimateFeeResponse, TransactionDetails, ClosedChannelsResponse, ListChannelsResponse, PendingChannelsResponse } 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,9 @@ 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>
ListClosedChannels(): Promise<ClosedChannelsResponse>
ListChannels(): Promise<ListChannelsResponse>
ListPendingChannels(): Promise<PendingChannelsResponse>
} }
export default (settings: LndSettings, addressPaidCb: AddressPaidCb, invoicePaidCb: InvoicePaidCb, newBlockCb: NewBlockCb, htlcCb: HtlcCb): LightningHandler => { export default (settings: LndSettings, addressPaidCb: AddressPaidCb, invoicePaidCb: InvoicePaidCb, newBlockCb: NewBlockCb, htlcCb: HtlcCb): LightningHandler => {

View file

@ -8,7 +8,7 @@ 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 { ChainNotifierClient } from '../../../proto/lnd/chainnotifier.client.js' import { ChainNotifierClient } from '../../../proto/lnd/chainnotifier.client.js'
import { GetInfoResponse, AddressType, NewAddressResponse, AddInvoiceResponse, Invoice_InvoiceState, PayReq, Payment_PaymentStatus, Payment, PaymentFailureReason, SendCoinsResponse, EstimateFeeResponse, ChannelBalanceResponse, TransactionDetails } from '../../../proto/lnd/lightning.js' import { GetInfoResponse, AddressType, NewAddressResponse, AddInvoiceResponse, Invoice_InvoiceState, PayReq, Payment_PaymentStatus, Payment, PaymentFailureReason, SendCoinsResponse, EstimateFeeResponse, ChannelBalanceResponse, TransactionDetails, ListChannelsResponse, ClosedChannelsResponse, PendingChannelsResponse } 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';
@ -78,6 +78,27 @@ export default class {
const res = await this.lightning.getInfo({}, DeadLineMetadata()) const res = await this.lightning.getInfo({}, DeadLineMetadata())
return res.response return res.response
} }
async ListPendingChannels(): Promise<PendingChannelsResponse> {
const res = await this.lightning.pendingChannels({}, DeadLineMetadata())
return res.response
}
async ListChannels(): Promise<ListChannelsResponse> {
const res = await this.lightning.listChannels({
activeOnly: false, inactiveOnly: false, privateOnly: false, publicOnly: false, peer: Buffer.alloc(0)
}, DeadLineMetadata())
return res.response
}
async ListClosedChannels(): Promise<ClosedChannelsResponse> {
const res = await this.lightning.closedChannels({
abandoned: true,
breach: true,
cooperative: true,
fundingCanceled: true,
localForce: true,
remoteForce: true
}, DeadLineMetadata())
return res.response
}
async Health(): Promise<void> { async Health(): Promise<void> {
if (!this.ready) { if (!this.ready) {

View file

@ -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 } from '../../../proto/lnd/lightning.js' import { GetInfoResponse, AddressType, NewAddressResponse, AddInvoiceResponse, Invoice_InvoiceState, PayReq, Payment_PaymentStatus, Payment, PaymentFailureReason, SendCoinsResponse, EstimateFeeResponse, TransactionDetails, ClosedChannelsResponse, ListChannelsResponse, PendingChannelsResponse } 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';
@ -39,6 +39,10 @@ export default class {
Stop() { } Stop() { }
async Warmup() { } async Warmup() { }
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 ListPendingChannels(): Promise<PendingChannelsResponse> { throw new Error("ListPendingChannels disabled in mock mode") }
async GetInfo(): Promise<NodeInfo> { async GetInfo(): Promise<NodeInfo> {
return { alias: "mock", syncedToChain: true, syncedToGraph: true, blockHeight: 1, blockHash: "" } return { alias: "mock", syncedToChain: true, syncedToGraph: true, blockHeight: 1, blockHash: "" }
} }

View file

@ -8,7 +8,7 @@ import ApplicationManager from './applicationManager.js'
import PaymentManager, { PendingTx } from './paymentManager.js' import PaymentManager, { PendingTx } from './paymentManager.js'
import { MainSettings } from './settings.js' import { MainSettings } from './settings.js'
import NewLightningHandler, { LoadLndSettingsFromEnv, LightningHandler } from "../lnd/index.js" import NewLightningHandler, { LoadLndSettingsFromEnv, LightningHandler } from "../lnd/index.js"
import { AddressPaidCb, InvoicePaidCb, NewBlockCb } from "../lnd/settings.js" import { AddressPaidCb, HtlcCb, InvoicePaidCb, NewBlockCb } from "../lnd/settings.js"
import { getLogger, PubLogger } from "../helpers/logger.js" import { getLogger, PubLogger } from "../helpers/logger.js"
import AppUserManager from "./appUserManager.js" import AppUserManager from "./appUserManager.js"
import { Application } from '../storage/entity/Application.js' import { Application } from '../storage/entity/Application.js'
@ -58,8 +58,8 @@ export default class {
constructor(settings: MainSettings, storage: Storage) { constructor(settings: MainSettings, storage: Storage) {
this.settings = settings this.settings = settings
this.storage = storage this.storage = storage
this.metricsManager = new MetricsManager(this.storage) this.lnd = NewLightningHandler(settings.lndSettings, this.addressPaidCb, this.invoicePaidCb, this.newBlockCb, this.htlcCb)
this.lnd = NewLightningHandler(settings.lndSettings, this.addressPaidCb, this.invoicePaidCb, this.newBlockCb, e => this.metricsManager.HtlcCb) this.metricsManager = new MetricsManager(this.storage, this.lnd)
this.paymentManager = new PaymentManager(this.storage, this.lnd, this.settings, this.addressPaidCb, this.invoicePaidCb) this.paymentManager = new PaymentManager(this.storage, this.lnd, this.settings, this.addressPaidCb, this.invoicePaidCb)
this.productManager = new ProductManager(this.storage, this.paymentManager, this.settings) this.productManager = new ProductManager(this.storage, this.paymentManager, this.settings)
@ -71,6 +71,10 @@ export default class {
this.nostrSend = f this.nostrSend = f
} }
htlcCb: HtlcCb = (e) => {
this.metricsManager.HtlcCb(e)
}
newBlockCb: NewBlockCb = (height) => { newBlockCb: NewBlockCb = (height) => {
this.NewBlockHandler(height) this.NewBlockHandler(height)
} }

View file

@ -6,12 +6,15 @@ import { RoutingEvent } from '../storage/entity/RoutingEvent.js'
import { BalanceInfo } from '../lnd/settings.js' import { BalanceInfo } from '../lnd/settings.js'
import { BalanceEvent } from '../storage/entity/BalanceEvent.js' import { BalanceEvent } from '../storage/entity/BalanceEvent.js'
import { ChannelBalanceEvent } from '../storage/entity/ChannelsBalanceEvent.js' import { ChannelBalanceEvent } from '../storage/entity/ChannelsBalanceEvent.js'
import { LightningHandler } from '../lnd/index.js'
const maxEvents = 100_000 const maxEvents = 100_000
export default class Handler { export default class Handler {
storage: Storage storage: Storage
lnd: LightningHandler
metrics: Types.UsageMetric[] = [] metrics: Types.UsageMetric[] = []
constructor(storage: Storage) { constructor(storage: Storage, lnd: LightningHandler) {
this.storage = storage this.storage = storage
this.lnd = lnd
} }
async HtlcCb(htlc: HtlcEvent) { async HtlcCb(htlc: HtlcEvent) {
@ -181,7 +184,33 @@ export default class Handler {
} }
} }
async GetChannelsInfo() {
const { channels } = await this.lnd.ListChannels()
let totalActive = 0
let totalInactive = 0
channels.forEach(c => {
if (c.active) {
totalActive++
} else {
totalInactive++
}
})
return {
totalActive, totalInactive, openChannels: channels
}
}
async GetPendingChannelsInfo() {
const { pendingForceClosingChannels, pendingOpenChannels } = await this.lnd.ListPendingChannels()
return { totalPendingClose: pendingForceClosingChannels.length, totalPendingOpen: pendingOpenChannels.length }
}
async GetLndMetrics(req: Types.LndMetricsRequest): Promise<Types.LndMetrics> { async GetLndMetrics(req: Types.LndMetricsRequest): Promise<Types.LndMetrics> {
const { openChannels, totalActive, totalInactive } = await this.GetChannelsInfo()
const { totalPendingOpen, totalPendingClose } = await this.GetPendingChannelsInfo()
const { channels: closedChannels } = await this.lnd.ListClosedChannels()
const routingEvents = await this.storage.metricsStorage.GetRoutingEvents({ from: req.from_unix, to: req.to_unix }) const routingEvents = await this.storage.metricsStorage.GetRoutingEvents({ from: req.from_unix, to: req.to_unix })
const { channelsBalanceEvents, chainBalanceEvents } = await this.storage.metricsStorage.GetBalanceEvents({ from: req.from_unix, to: req.to_unix }) const { channelsBalanceEvents, chainBalanceEvents } = await this.storage.metricsStorage.GetBalanceEvents({ from: req.from_unix, to: req.to_unix })
return { return {
@ -211,10 +240,15 @@ export default class Handler {
outgoing_htlc_id: e.outgoing_htlc_id, outgoing_htlc_id: e.outgoing_htlc_id,
settled: e.settled || false, settled: e.settled || false,
timestamp_ns: e.timestamp_ns timestamp_ns: e.timestamp_ns
})),
closing_channels: totalPendingClose,
pending_channels: totalPendingOpen,
offline_channels: totalInactive,
online_channels: totalActive,
closed_channels: closedChannels.map(c => ({ capacity: Number(c.capacity), channel_id: c.chanId, closed_height: c.closeHeight })),
open_channels: openChannels.map(c => ({ active: c.active, capacity: Number(c.capacity), channel_id: c.chanId, lifetime: Number(c.lifetime), local_balance: Number(c.localBalance), remote_balance: Number(c.remoteBalance) }))
}],
}))
}]
} }
} }
} }