Merge branch 'fix-metrics-data' into channels-rpc

This commit is contained in:
boufni95 2024-08-23 20:22:29 +02:00
commit 4fd8f44e82
13 changed files with 1682 additions and 1436 deletions

View file

@ -21,11 +21,12 @@ import { LspOrder1718387847693 } from './build/src/services/storage/migrations/1
import { LndNodeInfo1720187506189 } from './build/src/services/storage/migrations/1720187506189-lnd_node_info.js'
import { LiquidityProvider1719335699480 } from './build/src/services/storage/migrations/1719335699480-liquidity_provider.js'
import { CreateInviteTokenTable1721751414878 } from './build/src/services/storage/migrations/1721751414878-create_invite_token_table.js'
import { PaymentIndex1721760297610 } from './build/src/services/storage/migrations/1721760297610-payment_index.js'
export default new DataSource({
type: "sqlite",
database: "db.sqlite",
// logging: true,
migrations: [Initial1703170309875, LspOrder1718387847693, LiquidityProvider1719335699480, LndNodeInfo1720187506189, CreateInviteTokenTable1721751414878],
migrations: [Initial1703170309875, LspOrder1718387847693, LiquidityProvider1719335699480, LndNodeInfo1720187506189, CreateInviteTokenTable1721751414878, PaymentIndex1721760297610],
entities: [User, UserReceivingInvoice, UserReceivingAddress, AddressReceivingTransaction, UserInvoicePayment, UserTransactionPayment,
UserBasicAuth, UserEphemeralKey, Product, UserToUserPayment, Application, ApplicationUser, UserToUserPayment, LspOrder, LndNodeInfo, TrackedProvider, InviteToken],
// synchronize: true,

View file

@ -1,10 +1,15 @@
import { DataSource } from "typeorm"
import { LspOrder } from "./build/src/services/storage/entity/LspOrder.js"
import { BalanceEvent } from "./build/src/services/storage/entity/BalanceEvent.js"
import { ChannelBalanceEvent } from "./build/src/services/storage/entity/ChannelsBalanceEvent.js"
import { ChannelRouting } from "./build/src/services/storage/entity/ChannelRouting.js"
import { LndMetrics1703170330183 } from './build/src/services/storage/migrations/1703170330183-lnd_metrics.js'
import { ChannelRouting1709316653538 } from './build/src/services/storage/migrations/1709316653538-channel_routing.js'
export default new DataSource({
type: "sqlite",
database: "db.sqlite",
entities: [LspOrder],
database: "metrics.sqlite",
entities: [BalanceEvent, ChannelBalanceEvent, ChannelRouting],
migrations: [LndMetrics1703170330183, ChannelRouting1709316653538]
});
//npx typeorm migration:generate ./src/services/storage/migrations/htlc_count -d ./metricsDatasource.js

View file

@ -208,8 +208,8 @@ The nostr server will send back a message response, and inside the body there wi
- __GuestWithPub__:
- expected context content
- __app_id__: _string_
- __pub__: _string_
- __app_id__: _string_
## HTTP Methods
### These are the http methods the client implements to communicate with the API
@ -763,10 +763,11 @@ The nostr server will send back a message response, and inside the body there wi
- __user_identifier__: _string_
- __nostr_pub__: _string_
### Product
### Application
- __id__: _string_
- __balance__: _number_
- __npub__: _string_
- __name__: _string_
- __price_sats__: _number_
### GetInviteTokenStateResponse
- __used__: _boolean_

View file

@ -28,7 +28,7 @@
}),
serverStream: (bool) false
}),
(*main.Method)(0xc000274a50)({
(*main.Method)(0xc0002e4a50)({
in: (main.MethodMessage) {
name: (string) (len=13) "AddAppRequest",
hasZeroFields: (bool) false
@ -57,7 +57,7 @@
}),
serverStream: (bool) false
}),
(*main.Method)(0xc000274af0)({
(*main.Method)(0xc0002e4af0)({
in: (main.MethodMessage) {
name: (string) (len=14) "AuthAppRequest",
hasZeroFields: (bool) false
@ -86,7 +86,7 @@
}),
serverStream: (bool) false
}),
(*main.Method)(0xc000274b90)({
(*main.Method)(0xc0002e4b90)({
in: (main.MethodMessage) {
name: (string) (len=14) "BanUserRequest",
hasZeroFields: (bool) false
@ -115,7 +115,7 @@
}),
serverStream: (bool) false
}),
(*main.Method)(0xc000274be0)({
(*main.Method)(0xc0002e4be0)({
in: (main.MethodMessage) {
name: (string) (len=5) "Empty",
hasZeroFields: (bool) true
@ -144,7 +144,7 @@
}),
serverStream: (bool) false
}),
(*main.Method)(0xc000274c30)({
(*main.Method)(0xc0002e4c30)({
in: (main.MethodMessage) {
name: (string) (len=5) "Empty",
hasZeroFields: (bool) true
@ -571,9 +571,9 @@
id: (string) (len=4) "user",
name: (string) (len=4) "User",
context: (map[string]string) (len=3) {
(string) (len=7) "user_id": (string) (len=6) "string",
(string) (len=6) "app_id": (string) (len=6) "string",
(string) (len=11) "app_user_id": (string) (len=6) "string"
(string) (len=11) "app_user_id": (string) (len=6) "string",
(string) (len=7) "user_id": (string) (len=6) "string"
}
}),
method: (string) (len=4) "post",
@ -602,8 +602,8 @@
id: (string) (len=8) "guestPub",
name: (string) (len=12) "GuestWithPub",
context: (map[string]string) (len=2) {
(string) (len=6) "app_id": (string) (len=6) "string",
(string) (len=3) "pub": (string) (len=6) "string"
(string) (len=3) "pub": (string) (len=6) "string",
(string) (len=6) "app_id": (string) (len=6) "string"
}
}),
method: (string) (len=4) "post",
@ -1382,9 +1382,9 @@
id: (string) (len=4) "user",
name: (string) (len=4) "User",
context: (map[string]string) (len=3) {
(string) (len=11) "app_user_id": (string) (len=6) "string",
(string) (len=7) "user_id": (string) (len=6) "string",
(string) (len=6) "app_id": (string) (len=6) "string",
(string) (len=11) "app_user_id": (string) (len=6) "string"
(string) (len=6) "app_id": (string) (len=6) "string"
}
}),
method: (string) (len=4) "post",
@ -2063,9 +2063,9 @@
name: (string) (len=7) "invoice",
kind: (string) (len=6) "string",
isMap: (bool) false,
isArray: (bool) false,
isArray: (bool) true,
isEnum: (bool) false,
isMessage: (bool) false,
isMessage: (bool) true,
isOptional: (bool) false,
oneOfName: (string) ""
})
@ -2137,7 +2137,7 @@
isMap: (bool) false,
isArray: (bool) false,
isEnum: (bool) false,
isMessage: (bool) false,
isMessage: (bool) true,
isOptional: (bool) false,
oneOfName: (string) ""
}),
@ -2155,9 +2155,9 @@
name: (string) (len=15) "minWithdrawable",
kind: (string) (len=5) "int64",
isMap: (bool) false,
isArray: (bool) false,
isArray: (bool) true,
isEnum: (bool) false,
isMessage: (bool) false,
isMessage: (bool) true,
isOptional: (bool) false,
oneOfName: (string) ""
}),
@ -2261,8 +2261,8 @@
isMap: (bool) false,
isArray: (bool) false,
isEnum: (bool) false,
isMessage: (bool) false,
isOptional: (bool) false,
isMessage: (bool) true,
isOptional: (bool) true,
oneOfName: (string) ""
}),
(string) (len=3) "url": (*main.Field)(0xc0000b0cc0)({
@ -2271,8 +2271,8 @@
isMap: (bool) false,
isArray: (bool) false,
isEnum: (bool) false,
isMessage: (bool) false,
isOptional: (bool) false,
isMessage: (bool) true,
isOptional: (bool) true,
oneOfName: (string) ""
})
}
@ -2455,9 +2455,9 @@
name: (string) (len=5) "nodes",
kind: (string) (len=14) "LndNodeMetrics",
isMap: (bool) false,
isArray: (bool) true,
isArray: (bool) false,
isEnum: (bool) false,
isMessage: (bool) true,
isMessage: (bool) false,
isOptional: (bool) false,
oneOfName: (string) ""
})
@ -2626,6 +2626,16 @@
isMessage: (bool) true,
isOptional: (bool) false,
oneOfName: (string) ""
}),
(string) (len=10) "price_sats": (*main.Field)(0xc0001b8bc0)({
name: (string) (len=10) "price_sats",
kind: (string) (len=5) "int64",
isMap: (bool) false,
isArray: (bool) false,
isEnum: (bool) false,
isMessage: (bool) false,
isOptional: (bool) false,
oneOfName: (string) ""
})
}
}),
@ -2660,7 +2670,7 @@
isArray: (bool) false,
isEnum: (bool) false,
isMessage: (bool) false,
isOptional: (bool) false,
isOptional: (bool) true,
oneOfName: (string) ""
}),
(string) (len=8) "max_size": (*main.Field)(0xc000315cc0)({
@ -2670,7 +2680,7 @@
isArray: (bool) false,
isEnum: (bool) false,
isMessage: (bool) false,
isOptional: (bool) false,
isOptional: (bool) true,
oneOfName: (string) ""
}),
(string) (len=21) "latestIncomingInvoice": (*main.Field)(0xc000315b40)({
@ -2700,7 +2710,7 @@
isArray: (bool) false,
isEnum: (bool) false,
isMessage: (bool) false,
isOptional: (bool) false,
isOptional: (bool) true,
oneOfName: (string) ""
})
}
@ -2971,9 +2981,9 @@
name: (string) (len=12) "operation_id",
kind: (string) (len=6) "string",
isMap: (bool) false,
isArray: (bool) false,
isArray: (bool) true,
isEnum: (bool) false,
isMessage: (bool) false,
isMessage: (bool) true,
isOptional: (bool) false,
oneOfName: (string) ""
}),
@ -3185,7 +3195,7 @@
name: (string) (len=4) "info",
kind: (string) (len=8) "UserInfo",
isMap: (bool) false,
isArray: (bool) false,
isArray: (bool) true,
isEnum: (bool) false,
isMessage: (bool) true,
isOptional: (bool) false,
@ -3471,7 +3481,7 @@
name: (string) (len=10) "operations",
kind: (string) (len=13) "UserOperation",
isMap: (bool) false,
isArray: (bool) true,
isArray: (bool) false,
isEnum: (bool) false,
isMessage: (bool) true,
isOptional: (bool) false,
@ -3560,7 +3570,7 @@
isArray: (bool) false,
isEnum: (bool) false,
isMessage: (bool) false,
isOptional: (bool) false,
isOptional: (bool) true,
oneOfName: (string) ""
}),
(string) (len=19) "outgoing_channel_id": (*main.Field)(0xc00048b200)({
@ -3885,7 +3895,23 @@
isMap: (bool) false,
isArray: (bool) false,
isEnum: (bool) false,
isMessage: (bool) true,
isMessage: (bool) false,
isOptional: (bool) false,
oneOfName: (string) ""
})
}
}),
(string) (len=30) "SendAppUserToAppPaymentRequest": (*main.Message)(0xc000563530)({
fullName: (string) (len=30) "SendAppUserToAppPaymentRequest",
name: (string) (len=30) "SendAppUserToAppPaymentRequest",
fields: (map[string]*main.Field) (len=2) {
(string) (len=20) "from_user_identifier": (*main.Field)(0xc000120b80)({
name: (string) (len=20) "from_user_identifier",
kind: (string) (len=6) "string",
isMap: (bool) false,
isArray: (bool) false,
isEnum: (bool) false,
isMessage: (bool) false,
isOptional: (bool) false,
oneOfName: (string) ""
}),
@ -3895,7 +3921,7 @@
isMap: (bool) false,
isArray: (bool) false,
isEnum: (bool) false,
isMessage: (bool) true,
isMessage: (bool) false,
isOptional: (bool) false,
oneOfName: (string) ""
}),
@ -4067,7 +4093,7 @@
name: (string) (len=16) "pending_channels",
kind: (string) (len=5) "int64",
isMap: (bool) false,
isArray: (bool) false,
isArray: (bool) true,
isEnum: (bool) false,
isMessage: (bool) false,
isOptional: (bool) false,
@ -4189,9 +4215,9 @@
name: (string) (len=4) "name",
kind: (string) (len=6) "string",
isMap: (bool) false,
isArray: (bool) false,
isArray: (bool) true,
isEnum: (bool) false,
isMessage: (bool) false,
isMessage: (bool) true,
isOptional: (bool) false,
oneOfName: (string) ""
})
@ -4208,7 +4234,7 @@
isArray: (bool) false,
isEnum: (bool) false,
isMessage: (bool) false,
isOptional: (bool) false,
isOptional: (bool) true,
oneOfName: (string) ""
}),
(string) (len=16) "payer_identifier": (*main.Field)(0xc0003148c0)({
@ -4253,7 +4279,7 @@
isMap: (bool) false,
isArray: (bool) false,
isEnum: (bool) false,
isMessage: (bool) false,
isMessage: (bool) true,
isOptional: (bool) false,
oneOfName: (string) ""
})
@ -4453,9 +4479,9 @@
name: (string) (len=9) "confirmed",
kind: (string) (len=4) "bool",
isMap: (bool) false,
isArray: (bool) false,
isArray: (bool) true,
isEnum: (bool) false,
isMessage: (bool) false,
isMessage: (bool) true,
isOptional: (bool) false,
oneOfName: (string) ""
}),
@ -4536,6 +4562,60 @@
oneOfName: (string) ""
})
}
}),
(string) (len=31) "CreateOneTimeInviteLinkResponse": (*main.Message)(0xc0001c6450)({
fullName: (string) (len=31) "CreateOneTimeInviteLinkResponse",
name: (string) (len=31) "CreateOneTimeInviteLinkResponse",
fields: (map[string]*main.Field) (len=1) {
(string) (len=15) "invitation_link": (*main.Field)(0xc0001b8f40)({
name: (string) (len=15) "invitation_link",
kind: (string) (len=6) "string",
isMap: (bool) false,
isArray: (bool) false,
isEnum: (bool) false,
isMessage: (bool) false,
isOptional: (bool) false,
oneOfName: (string) ""
})
}
}),
(string) (len=26) "GetInviteTokenStateRequest": (*main.Message)(0xc0001c6510)({
fullName: (string) (len=26) "GetInviteTokenStateRequest",
name: (string) (len=26) "GetInviteTokenStateRequest",
fields: (map[string]*main.Field) (len=1) {
(string) (len=12) "invite_token": (*main.Field)(0xc0001b8fc0)({
name: (string) (len=12) "invite_token",
kind: (string) (len=6) "string",
isMap: (bool) false,
isArray: (bool) false,
isEnum: (bool) false,
isMessage: (bool) false,
isOptional: (bool) false,
oneOfName: (string) ""
})
}
}),
(string) (len=27) "GetInviteTokenStateResponse": (*main.Message)(0xc0001c6570)({
fullName: (string) (len=27) "GetInviteTokenStateResponse",
name: (string) (len=27) "GetInviteTokenStateResponse",
fields: (map[string]*main.Field) (len=1) {
(string) (len=4) "used": (*main.Field)(0xc0001b9000)({
name: (string) (len=4) "used",
kind: (string) (len=4) "bool",
isMap: (bool) false,
isArray: (bool) false,
isEnum: (bool) false,
isMessage: (bool) false,
isOptional: (bool) false,
oneOfName: (string) ""
})
}
}),
(string) (len=5) "Empty": (*main.Message)(0xc0005628d0)({
fullName: (string) (len=5) "Empty",
name: (string) (len=5) "Empty",
fields: (map[string]*main.Field) {
}
})
}

View file

@ -5,10 +5,10 @@ export type ResultError = { status: 'ERROR', reason: string }
export type NostrClientParams = {
pubDestination: string
retrieveNostrMetricsAuth: () => Promise<string | null>
retrieveNostrUserAuth: () => Promise<string | null>
retrieveNostrGuestWithPubAuth: () => Promise<string | null>
retrieveNostrAdminAuth: () => Promise<string | null>
retrieveNostrMetricsAuth: () => Promise<string | null>
checkResult?: true
}
export default (params: NostrClientParams, send: (to:string, message: NostrRequest) => Promise<any>, subscribe: (to:string, message: NostrRequest, cb:(res:any)=> void) => void) => ({

View file

@ -1392,20 +1392,11 @@ export const RoutingEventValidate = (o?: RoutingEvent, opts: RoutingEventOptions
return null
}
export type GetAppUserRequest = {
user_identifier: string
}
export const GetAppUserRequestOptionalFields: [] = []
export type GetAppUserRequestOptions = OptionsBaseMessage & {
checkOptionalsAreSet?: []
user_identifier_CustomCheck?: (v: string) => boolean
}
export const GetAppUserRequestValidate = (o?: GetAppUserRequest, opts: GetAppUserRequestOptions = {}, path: string = 'GetAppUserRequest::root.'): Error | null => {
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
if (typeof o.satsPerVByte !== 'number') return new Error(`${path}.satsPerVByte: is not a number`)
if (opts.satsPerVByte_CustomCheck && !opts.satsPerVByte_CustomCheck(o.satsPerVByte)) return new Error(`${path}.satsPerVByte: custom check failed`)
if (typeof o.user_identifier !== 'string') return new Error(`${path}.user_identifier: is not a string`)
if (opts.user_identifier_CustomCheck && !opts.user_identifier_CustomCheck(o.user_identifier)) return new Error(`${path}.user_identifier: custom check failed`)
if (typeof o.address !== 'string') return new Error(`${path}.address: is not a string`)
if (opts.address_CustomCheck && !opts.address_CustomCheck(o.address)) return new Error(`${path}.address: custom check failed`)
return null
}
@ -1424,8 +1415,11 @@ export const PayInvoiceRequestValidate = (o?: PayInvoiceRequest, opts: PayInvoic
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
if (typeof o.invoice !== 'string') return new Error(`${path}.invoice: is not a string`)
if (opts.invoice_CustomCheck && !opts.invoice_CustomCheck(o.invoice)) return new Error(`${path}.invoice: custom check failed`)
if (typeof o.url !== 'string') return new Error(`${path}.url: is not a string`)
if (opts.url_CustomCheck && !opts.url_CustomCheck(o.url)) return new Error(`${path}.url: custom check failed`)
if (typeof o.token !== 'string') return new Error(`${path}.token: is not a string`)
if (opts.token_CustomCheck && !opts.token_CustomCheck(o.token)) return new Error(`${path}.token: custom check failed`)
if (typeof o.amount !== 'number') return new Error(`${path}.amount: is not a number`)
if (opts.amount_CustomCheck && !opts.amount_CustomCheck(o.amount)) return new Error(`${path}.amount: custom check failed`)
@ -1441,46 +1435,25 @@ export type GetUserOperationsResponse = {
latestIncomingTxOperations: UserOperations
latestOutgoingUserToUserPayemnts: UserOperations
}
export const GetUserOperationsResponseOptionalFields: [] = []
export type GetUserOperationsResponseOptions = OptionsBaseMessage & {
export const UsageMetricOptionalFields: [] = []
export type UsageMetricOptions = OptionsBaseMessage & {
checkOptionalsAreSet?: []
latestOutgoingInvoiceOperations_Options?: UserOperationsOptions
latestIncomingInvoiceOperations_Options?: UserOperationsOptions
latestOutgoingTxOperations_Options?: UserOperationsOptions
latestIncomingTxOperations_Options?: UserOperationsOptions
latestOutgoingUserToUserPayemnts_Options?: UserOperationsOptions
latestIncomingUserToUserPayemnts_Options?: UserOperationsOptions
rpc_name_CustomCheck?: (v: string) => boolean
batch_CustomCheck?: (v: boolean) => boolean
nostr_CustomCheck?: (v: boolean) => boolean
processed_at_ms_CustomCheck?: (v: number) => boolean
parsed_in_nano_CustomCheck?: (v: number) => boolean
auth_in_nano_CustomCheck?: (v: number) => boolean
validate_in_nano_CustomCheck?: (v: number) => boolean
handle_in_nano_CustomCheck?: (v: number) => boolean
batch_size_CustomCheck?: (v: number) => boolean
}
export const GetUserOperationsResponseValidate = (o?: GetUserOperationsResponse, opts: GetUserOperationsResponseOptions = {}, path: string = 'GetUserOperationsResponse::root.'): Error | null => {
export const UsageMetricValidate = (o?: UsageMetric, opts: UsageMetricOptions = {}, path: string = 'UsageMetric::root.'): Error | null => {
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
const latestOutgoingInvoiceOperationsErr = UserOperationsValidate(o.latestOutgoingInvoiceOperations, opts.latestOutgoingInvoiceOperations_Options, `${path}.latestOutgoingInvoiceOperations`)
if (latestOutgoingInvoiceOperationsErr !== null) return latestOutgoingInvoiceOperationsErr
const latestIncomingInvoiceOperationsErr = UserOperationsValidate(o.latestIncomingInvoiceOperations, opts.latestIncomingInvoiceOperations_Options, `${path}.latestIncomingInvoiceOperations`)
if (latestIncomingInvoiceOperationsErr !== null) return latestIncomingInvoiceOperationsErr
const latestOutgoingTxOperationsErr = UserOperationsValidate(o.latestOutgoingTxOperations, opts.latestOutgoingTxOperations_Options, `${path}.latestOutgoingTxOperations`)
if (latestOutgoingTxOperationsErr !== null) return latestOutgoingTxOperationsErr
const latestIncomingTxOperationsErr = UserOperationsValidate(o.latestIncomingTxOperations, opts.latestIncomingTxOperations_Options, `${path}.latestIncomingTxOperations`)
if (latestIncomingTxOperationsErr !== null) return latestIncomingTxOperationsErr
const latestOutgoingUserToUserPayemntsErr = UserOperationsValidate(o.latestOutgoingUserToUserPayemnts, opts.latestOutgoingUserToUserPayemnts_Options, `${path}.latestOutgoingUserToUserPayemnts`)
if (latestOutgoingUserToUserPayemntsErr !== null) return latestOutgoingUserToUserPayemntsErr
const latestIncomingUserToUserPayemntsErr = UserOperationsValidate(o.latestIncomingUserToUserPayemnts, opts.latestIncomingUserToUserPayemnts_Options, `${path}.latestIncomingUserToUserPayemnts`)
if (latestIncomingUserToUserPayemntsErr !== null) return latestIncomingUserToUserPayemntsErr
return null
}
if (typeof o.parsed_in_nano !== 'number') return new Error(`${path}.parsed_in_nano: is not a number`)
if (opts.parsed_in_nano_CustomCheck && !opts.parsed_in_nano_CustomCheck(o.parsed_in_nano)) return new Error(`${path}.parsed_in_nano: custom check failed`)
export type UsageMetrics = {
metrics: UsageMetric[]
@ -1652,25 +1625,71 @@ export const BanUserRequestValidate = (o?: BanUserRequest, opts: BanUserRequestO
return null
}
export type AddAppRequest = {
name: string
allow_user_creation: boolean
export type NewAddressRequest = {
addressType: AddressType
}
export const AddAppRequestOptionalFields: [] = []
export type AddAppRequestOptions = OptionsBaseMessage & {
export const NewAddressRequestOptionalFields: [] = []
export type NewAddressRequestOptions = OptionsBaseMessage & {
checkOptionalsAreSet?: []
name_CustomCheck?: (v: string) => boolean
allow_user_creation_CustomCheck?: (v: boolean) => boolean
addressType_CustomCheck?: (v: AddressType) => boolean
}
export const AddAppRequestValidate = (o?: AddAppRequest, opts: AddAppRequestOptions = {}, path: string = 'AddAppRequest::root.'): Error | null => {
export const NewAddressRequestValidate = (o?: NewAddressRequest, opts: NewAddressRequestOptions = {}, path: string = 'NewAddressRequest::root.'): Error | null => {
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
if (typeof o.name !== 'string') return new Error(`${path}.name: is not a string`)
if (opts.name_CustomCheck && !opts.name_CustomCheck(o.name)) return new Error(`${path}.name: custom check failed`)
if (!enumCheckAddressType(o.addressType)) return new Error(`${path}.addressType: is not a valid AddressType`)
if (opts.addressType_CustomCheck && !opts.addressType_CustomCheck(o.addressType)) return new Error(`${path}.addressType: custom check failed`)
if (typeof o.allow_user_creation !== 'boolean') return new Error(`${path}.allow_user_creation: is not a boolean`)
if (opts.allow_user_creation_CustomCheck && !opts.allow_user_creation_CustomCheck(o.allow_user_creation)) return new Error(`${path}.allow_user_creation: custom check failed`)
return null
}
export type PaymentState = {
paid_at_unix: number
amount: number
service_fee: number
network_fee: number
}
export const PaymentStateOptionalFields: [] = []
export type PaymentStateOptions = OptionsBaseMessage & {
checkOptionalsAreSet?: []
paid_at_unix_CustomCheck?: (v: number) => boolean
amount_CustomCheck?: (v: number) => boolean
service_fee_CustomCheck?: (v: number) => boolean
network_fee_CustomCheck?: (v: number) => boolean
}
export const PaymentStateValidate = (o?: PaymentState, opts: PaymentStateOptions = {}, path: string = 'PaymentState::root.'): Error | null => {
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
if (typeof o.paid_at_unix !== 'number') return new Error(`${path}.paid_at_unix: is not a number`)
if (opts.paid_at_unix_CustomCheck && !opts.paid_at_unix_CustomCheck(o.paid_at_unix)) return new Error(`${path}.paid_at_unix: custom check failed`)
if (typeof o.amount !== 'number') return new Error(`${path}.amount: is not a number`)
if (opts.amount_CustomCheck && !opts.amount_CustomCheck(o.amount)) return new Error(`${path}.amount: custom check failed`)
if (typeof o.service_fee !== 'number') return new Error(`${path}.service_fee: is not a number`)
if (opts.service_fee_CustomCheck && !opts.service_fee_CustomCheck(o.service_fee)) return new Error(`${path}.service_fee: custom check failed`)
if (typeof o.network_fee !== 'number') return new Error(`${path}.network_fee: is not a number`)
if (opts.network_fee_CustomCheck && !opts.network_fee_CustomCheck(o.network_fee)) return new Error(`${path}.network_fee: custom check failed`)
return null
}
export type BanUserRequest = {
user_id: string
}
export const BanUserRequestOptionalFields: [] = []
export type BanUserRequestOptions = OptionsBaseMessage & {
checkOptionalsAreSet?: []
user_id_CustomCheck?: (v: string) => boolean
}
export const BanUserRequestValidate = (o?: BanUserRequest, opts: BanUserRequestOptions = {}, path: string = 'BanUserRequest::root.'): Error | null => {
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
if (typeof o.user_id !== 'string') return new Error(`${path}.user_id: is not a string`)
if (opts.user_id_CustomCheck && !opts.user_id_CustomCheck(o.user_id)) return new Error(`${path}.user_id: custom check failed`)
return null
}
@ -1684,10 +1703,10 @@ export type AddAppUserInvoiceRequest = {
export const AddAppUserInvoiceRequestOptionalFields: [] = []
export type AddAppUserInvoiceRequestOptions = OptionsBaseMessage & {
checkOptionalsAreSet?: []
receiver_identifier_CustomCheck?: (v: string) => boolean
payer_identifier_CustomCheck?: (v: string) => boolean
http_callback_url_CustomCheck?: (v: string) => boolean
invoice_req_Options?: NewInvoiceRequestOptions
receiver_identifier_CustomCheck?: (v: string) => boolean
}
export const AddAppUserInvoiceRequestValidate = (o?: AddAppUserInvoiceRequest, opts: AddAppUserInvoiceRequestOptions = {}, path: string = 'AddAppUserInvoiceRequest::root.'): Error | null => {
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
@ -1815,20 +1834,23 @@ export const AppsMetricsValidate = (o?: AppsMetrics, opts: AppsMetricsOptions =
return null
}
export type ClosureMigration = {
closes_at_unix: number
export type RelaysMigration = {
relays: string[]
}
export const ClosureMigrationOptionalFields: [] = []
export type ClosureMigrationOptions = OptionsBaseMessage & {
export const RelaysMigrationOptionalFields: [] = []
export type RelaysMigrationOptions = OptionsBaseMessage & {
checkOptionalsAreSet?: []
closes_at_unix_CustomCheck?: (v: number) => boolean
relays_CustomCheck?: (v: string[]) => boolean
}
export const ClosureMigrationValidate = (o?: ClosureMigration, opts: ClosureMigrationOptions = {}, path: string = 'ClosureMigration::root.'): Error | null => {
export const RelaysMigrationValidate = (o?: RelaysMigration, opts: RelaysMigrationOptions = {}, path: string = 'RelaysMigration::root.'): Error | null => {
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
if (typeof o.closes_at_unix !== 'number') return new Error(`${path}.closes_at_unix: is not a number`)
if (opts.closes_at_unix_CustomCheck && !opts.closes_at_unix_CustomCheck(o.closes_at_unix)) return new Error(`${path}.closes_at_unix: custom check failed`)
if (!Array.isArray(o.relays)) return new Error(`${path}.relays: is not an array`)
for (let index = 0; index < o.relays.length; index++) {
if (typeof o.relays[index] !== 'string') return new Error(`${path}.relays[${index}]: is not a string`)
}
if (opts.relays_CustomCheck && !opts.relays_CustomCheck(o.relays)) return new Error(`${path}.relays: custom check failed`)
return null
}
@ -1910,8 +1932,118 @@ export type UserOperation = {
service_fee: number
inbound: boolean
}
export const UserOperationOptionalFields: [] = []
export type UserOperationOptions = OptionsBaseMessage & {
export const AuthAppOptionalFields: [] = []
export type AuthAppOptions = OptionsBaseMessage & {
checkOptionalsAreSet?: []
auth_token_CustomCheck?: (v: string) => boolean
app_Options?: ApplicationOptions
}
export const AuthAppValidate = (o?: AuthApp, opts: AuthAppOptions = {}, path: string = 'AuthApp::root.'): Error | null => {
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
const appErr = ApplicationValidate(o.app, opts.app_Options, `${path}.app`)
if (appErr !== null) return appErr
if (typeof o.auth_token !== 'string') return new Error(`${path}.auth_token: is not a string`)
if (opts.auth_token_CustomCheck && !opts.auth_token_CustomCheck(o.auth_token)) return new Error(`${path}.auth_token: custom check failed`)
return null
}
export type GetAppUserRequest = {
user_identifier: string
}
export const GetAppUserRequestOptionalFields: [] = []
export type GetAppUserRequestOptions = OptionsBaseMessage & {
checkOptionalsAreSet?: []
user_identifier_CustomCheck?: (v: string) => boolean
}
export const GetAppUserRequestValidate = (o?: GetAppUserRequest, opts: GetAppUserRequestOptions = {}, path: string = 'GetAppUserRequest::root.'): Error | null => {
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
if (typeof o.user_identifier !== 'string') return new Error(`${path}.user_identifier: is not a string`)
if (opts.user_identifier_CustomCheck && !opts.user_identifier_CustomCheck(o.user_identifier)) return new Error(`${path}.user_identifier: custom check failed`)
return null
}
export type UsersInfo = {
total: number
no_balance: number
negative_balance: number
always_been_inactive: number
balance_avg: number
balance_median: number
}
export const UsersInfoOptionalFields: [] = []
export type UsersInfoOptions = OptionsBaseMessage & {
checkOptionalsAreSet?: []
total_CustomCheck?: (v: number) => boolean
no_balance_CustomCheck?: (v: number) => boolean
negative_balance_CustomCheck?: (v: number) => boolean
always_been_inactive_CustomCheck?: (v: number) => boolean
balance_avg_CustomCheck?: (v: number) => boolean
balance_median_CustomCheck?: (v: number) => boolean
}
export const UsersInfoValidate = (o?: UsersInfo, opts: UsersInfoOptions = {}, path: string = 'UsersInfo::root.'): Error | null => {
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
if (typeof o.no_balance !== 'number') return new Error(`${path}.no_balance: is not a number`)
if (opts.no_balance_CustomCheck && !opts.no_balance_CustomCheck(o.no_balance)) return new Error(`${path}.no_balance: custom check failed`)
if (typeof o.negative_balance !== 'number') return new Error(`${path}.negative_balance: is not a number`)
if (opts.negative_balance_CustomCheck && !opts.negative_balance_CustomCheck(o.negative_balance)) return new Error(`${path}.negative_balance: custom check failed`)
if (typeof o.always_been_inactive !== 'number') return new Error(`${path}.always_been_inactive: is not a number`)
if (opts.always_been_inactive_CustomCheck && !opts.always_been_inactive_CustomCheck(o.always_been_inactive)) return new Error(`${path}.always_been_inactive: custom check failed`)
if (typeof o.balance_avg !== 'number') return new Error(`${path}.balance_avg: is not a number`)
if (opts.balance_avg_CustomCheck && !opts.balance_avg_CustomCheck(o.balance_avg)) return new Error(`${path}.balance_avg: custom check failed`)
if (typeof o.balance_median !== 'number') return new Error(`${path}.balance_median: is not a number`)
if (opts.balance_median_CustomCheck && !opts.balance_median_CustomCheck(o.balance_median)) return new Error(`${path}.balance_median: custom check failed`)
if (typeof o.total !== 'number') return new Error(`${path}.total: is not a number`)
if (opts.total_CustomCheck && !opts.total_CustomCheck(o.total)) return new Error(`${path}.total: custom check failed`)
return null
}
export type LndMetricsRequest = {
from_unix?: number
to_unix?: number
}
export type LndMetricsRequestOptionalField = 'from_unix' | 'to_unix'
export const LndMetricsRequestOptionalFields: LndMetricsRequestOptionalField[] = ['from_unix', 'to_unix']
export type LndMetricsRequestOptions = OptionsBaseMessage & {
checkOptionalsAreSet?: LndMetricsRequestOptionalField[]
from_unix_CustomCheck?: (v?: number) => boolean
to_unix_CustomCheck?: (v?: number) => boolean
}
export const LndMetricsRequestValidate = (o?: LndMetricsRequest, opts: LndMetricsRequestOptions = {}, path: string = 'LndMetricsRequest::root.'): Error | null => {
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
if ((o.from_unix || opts.allOptionalsAreSet || opts.checkOptionalsAreSet?.includes('from_unix')) && typeof o.from_unix !== 'number') return new Error(`${path}.from_unix: is not a number`)
if (opts.from_unix_CustomCheck && !opts.from_unix_CustomCheck(o.from_unix)) return new Error(`${path}.from_unix: custom check failed`)
if ((o.to_unix || opts.allOptionalsAreSet || opts.checkOptionalsAreSet?.includes('to_unix')) && typeof o.to_unix !== 'number') return new Error(`${path}.to_unix: is not a number`)
if (opts.to_unix_CustomCheck && !opts.to_unix_CustomCheck(o.to_unix)) return new Error(`${path}.to_unix: custom check failed`)
return null
}
export type UserOperations = {
toIndex: number
operations: UserOperation[]
fromIndex: number
}
export const UserOperationsOptionalFields: [] = []
export type UserOperationsOptions = OptionsBaseMessage & {
checkOptionalsAreSet?: []
amount_CustomCheck?: (v: number) => boolean
identifier_CustomCheck?: (v: string) => boolean
@ -1929,8 +2061,12 @@ export const UserOperationValidate = (o?: UserOperation, opts: UserOperationOpti
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')
if (typeof o.inbound !== 'boolean') return new Error(`${path}.inbound: is not a boolean`)
if (opts.inbound_CustomCheck && !opts.inbound_CustomCheck(o.inbound)) return new Error(`${path}.inbound: custom check failed`)
if (!Array.isArray(o.operations)) return new Error(`${path}.operations: is not an array`)
for (let index = 0; index < o.operations.length; index++) {
const operationsErr = UserOperationValidate(o.operations[index], opts.operations_ItemOptions, `${path}.operations[${index}]`)
if (operationsErr !== null) return operationsErr
}
if (opts.operations_CustomCheck && !opts.operations_CustomCheck(o.operations)) return new Error(`${path}.operations: custom check failed`)
if (typeof o.service_fee !== 'number') return new Error(`${path}.service_fee: is not a number`)
if (opts.service_fee_CustomCheck && !opts.service_fee_CustomCheck(o.service_fee)) return new Error(`${path}.service_fee: custom check failed`)
@ -1938,11 +2074,13 @@ export const UserOperationValidate = (o?: UserOperation, opts: UserOperationOpti
if (typeof o.network_fee !== 'number') return new Error(`${path}.network_fee: is not a number`)
if (opts.network_fee_CustomCheck && !opts.network_fee_CustomCheck(o.network_fee)) return new Error(`${path}.network_fee: custom check failed`)
if (typeof o.confirmed !== 'boolean') return new Error(`${path}.confirmed: is not a boolean`)
if (opts.confirmed_CustomCheck && !opts.confirmed_CustomCheck(o.confirmed)) return new Error(`${path}.confirmed: custom check failed`)
const latestOutgoingUserToUserPayemntsErr = UserOperationsValidate(o.latestOutgoingUserToUserPayemnts, opts.latestOutgoingUserToUserPayemnts_Options, `${path}.latestOutgoingUserToUserPayemnts`)
if (latestOutgoingUserToUserPayemntsErr !== null) return latestOutgoingUserToUserPayemntsErr
const latestIncomingUserToUserPayemntsErr = UserOperationsValidate(o.latestIncomingUserToUserPayemnts, opts.latestIncomingUserToUserPayemnts_Options, `${path}.latestIncomingUserToUserPayemnts`)
if (latestIncomingUserToUserPayemntsErr !== null) return latestIncomingUserToUserPayemntsErr
if (typeof o.tx_hash !== 'string') return new Error(`${path}.tx_hash: is not a string`)
if (opts.tx_hash_CustomCheck && !opts.tx_hash_CustomCheck(o.tx_hash)) return new Error(`${path}.tx_hash: custom check failed`)
if (typeof o.paidAtUnix !== 'number') return new Error(`${path}.paidAtUnix: is not a number`)
if (opts.paidAtUnix_CustomCheck && !opts.paidAtUnix_CustomCheck(o.paidAtUnix)) return new Error(`${path}.paidAtUnix: custom check failed`)
@ -2522,15 +2660,18 @@ export const NewInvoiceRequestValidate = (o?: NewInvoiceRequest, opts: NewInvoic
return null
}
export type DecodeInvoiceResponse = {
amount: number
export type MigrationUpdate = {
closure?: ClosureMigration
relays?: RelaysMigration
}
export const DecodeInvoiceResponseOptionalFields: [] = []
export type DecodeInvoiceResponseOptions = OptionsBaseMessage & {
checkOptionalsAreSet?: []
amount_CustomCheck?: (v: number) => boolean
export type MigrationUpdateOptionalField = 'closure' | 'relays'
export const MigrationUpdateOptionalFields: MigrationUpdateOptionalField[] = ['closure', 'relays']
export type MigrationUpdateOptions = OptionsBaseMessage & {
checkOptionalsAreSet?: MigrationUpdateOptionalField[]
closure_Options?: ClosureMigrationOptions
relays_Options?: RelaysMigrationOptions
}
export const DecodeInvoiceResponseValidate = (o?: DecodeInvoiceResponse, opts: DecodeInvoiceResponseOptions = {}, path: string = 'DecodeInvoiceResponse::root.'): Error | null => {
export const MigrationUpdateValidate = (o?: MigrationUpdate, opts: MigrationUpdateOptions = {}, path: string = 'MigrationUpdate::root.'): Error | null => {
if (opts.checkOptionalsAreSet && opts.allOptionalsAreSet) return new Error(path + ': only one of checkOptionalsAreSet or allOptionalNonDefault can be set for each message')
if (typeof o !== 'object' || o === null) return new Error(path + ': object is not an instance of an object or is null')

View file

@ -87,19 +87,6 @@ message RoutingEvent {
bool offchain = 11;
bool forward_fail_event = 12;
}
message ChannelBalanceEvent {
int64 block_height = 1;
string channel_id = 2;
int64 local_balance_sats = 3;
int64 remote_balance_sats = 4;
}
message ChainBalanceEvent {
int64 block_height = 1;
int64 confirmed_balance = 2;
int64 unconfirmed_balance = 3;
int64 total_balance = 4;
}
message OpenChannel {
string channel_id = 1;
@ -116,29 +103,22 @@ message ClosedChannel {
int64 closed_height =4;
}
message ChannelRouting {
string channel_id = 1;
int64 send_errors = 2;
int64 receive_errors = 3;
int64 forward_errors_as_input = 4;
int64 forward_errors_as_output = 5;
int64 missed_forward_fee_as_input = 6;
int64 missed_forward_fee_as_output = 7;
int64 forward_fee_as_input = 8;
int64 forward_fee_as_output = 9;
int64 events_number = 10;
message GraphPoint {
int64 x = 1;
int64 y = 2;
}
message LndNodeMetrics {
repeated ChannelBalanceEvent channels_balance_events = 1;
repeated ChainBalanceEvent chain_balance_events = 2;
repeated GraphPoint chain_balance = 1;
repeated GraphPoint channel_balance = 2;
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;
repeated ChannelRouting channel_routing = 10;
int64 forwarding_events = 11;
int64 forwarding_fees = 12;
}
message LndMetrics {

View file

@ -18,7 +18,7 @@ export default class HtlcTracker {
}
log = getLogger({ component: 'htlcTracker' })
onHtlcEvent = async (htlc: HtlcEvent) => {
//getLogger({ component: 'debugHtlcs' })(htlc)
/* //getLogger({ component: 'debugHtlcs' })(htlc)
const htlcEvent = htlc.event
if (htlcEvent.oneofKind === 'subscribedEvent') {
return
@ -45,10 +45,10 @@ export default class HtlcTracker {
return this.handleSuccess(info)
default:
//this.log("unknown htlc event type")
}
} */
}
handleForward = (fwe: ForwardEvent, { eventType, outgoingHtlcId, incomingHtlcId }: EventInfo) => {
/* handleForward = (fwe: ForwardEvent, { eventType, outgoingHtlcId, incomingHtlcId }: EventInfo) => {
const { info } = fwe
const incomingAmtMsat = info ? Number(info.incomingAmtMsat) : 0
const outgoingAmtMsat = info ? Number(info.outgoingAmtMsat) : 0
@ -59,9 +59,9 @@ export default class HtlcTracker {
} else if (eventType === HtlcEvent_EventType.FORWARD) {
this.pendingForwardHtlcs.set(outgoingHtlcId, outgoingAmtMsat - incomingAmtMsat)
}
}
} */
handleFailure = ({ eventType, outgoingHtlcId, incomingHtlcId, incomingChannelId, outgoingChannelId }: EventInfo) => {
/* handleFailure = ({ eventType, outgoingHtlcId, incomingHtlcId, incomingChannelId, outgoingChannelId }: EventInfo) => {
if (eventType === HtlcEvent_EventType.SEND && this.deleteMapEntry(outgoingHtlcId, this.pendingSendHtlcs) !== null) {
return this.incrementSendFailures(outgoingChannelId)
}
@ -86,9 +86,9 @@ export default class HtlcTracker {
return this.incrementReceiveFailures(incomingChannelId)
}
}
}
} */
handleSuccess = ({ eventType, outgoingHtlcId, incomingHtlcId }: EventInfo) => {
/* handleSuccess = ({ eventType, outgoingHtlcId, incomingHtlcId }: EventInfo) => {
if (eventType === HtlcEvent_EventType.SEND) {
this.deleteMapEntry(outgoingHtlcId, this.pendingSendHtlcs)
} else if (eventType === HtlcEvent_EventType.RECEIVE) {
@ -100,8 +100,8 @@ export default class HtlcTracker {
if (this.deleteMapEntry(incomingHtlcId, this.pendingReceiveHtlcs) !== null) return
if (this.deleteMapEntry(outgoingHtlcId, this.pendingForwardHtlcs) !== null) return
}
}
} */
/*
deleteMapEntry = (key: number, map: Map<number, number>) => {
if (!map.has(key)) {
return null
@ -109,9 +109,9 @@ export default class HtlcTracker {
const v = map.get(key)
map.delete(key)
return v || null
}
} */
incrementSendFailures = async (outgoingChannelId: number) => {
/* incrementSendFailures = async (outgoingChannelId: number) => {
await this.storage.metricsStorage.IncrementChannelRouting(outgoingChannelId.toString(), { send_errors: 1 })
}
incrementReceiveFailures = async (incomingChannelId: number) => {
@ -120,6 +120,6 @@ export default class HtlcTracker {
incrementForwardFailures = async (incomingChannelId: number, outgoingChannelId: number, amt: number) => {
await this.storage.metricsStorage.IncrementChannelRouting(incomingChannelId.toString(), { forward_errors_as_input: 1, missed_forward_fee_as_input: amt })
await this.storage.metricsStorage.IncrementChannelRouting(outgoingChannelId.toString(), { forward_errors_as_output: 1, missed_forward_fee_as_output: amt })
}
} */
}

View file

@ -36,6 +36,7 @@ export default class Handler {
remote_balance_sats: c.remoteBalanceSats,
}))
await this.storage.metricsStorage.SaveBalanceEvents(balanceEvent, channelsEvents)
await this.FetchLatestForwardingEvents()
}
async FetchLatestForwardingEvents() {
@ -43,8 +44,8 @@ export default class Handler {
const res = await this.lnd.GetForwardingHistory(latestIndex)
const forwards = res.forwardingEvents.map(e => ({ fee: Number(e.fee), chanIdIn: e.chanIdIn, chanIdOut: e.chanIdOut, timestampNs: e.timestampNs.toString(), offset: res.lastOffsetIndex }))
await Promise.all(forwards.map(async f => {
await this.storage.metricsStorage.IncrementChannelRouting(f.chanIdIn, { forward_fee_as_input: f.fee, latest_index_offset: f.offset })
await this.storage.metricsStorage.IncrementChannelRouting(f.chanIdOut, { forward_fee_as_output: f.fee, latest_index_offset: f.offset })
await this.storage.metricsStorage.IncrementChannelRouting(f.chanIdIn, { forward_fee_as_input: f.fee, latest_index_offset: f.offset, events_as_input: 1 })
await this.storage.metricsStorage.IncrementChannelRouting(f.chanIdOut, { forward_fee_as_output: f.fee, latest_index_offset: f.offset, events_as_output: 1 })
}))
}
@ -207,54 +208,60 @@ export default class Handler {
const { totalPendingOpen, totalPendingClose } = await this.GetPendingChannelsInfo()
const { channels: closedChannels } = await this.lnd.ListClosedChannels()
const rawRouting = await this.storage.metricsStorage.GetChannelRouting({ from: req.from_unix, to: req.to_unix })
const routingMap: Record<string, Types.ChannelRouting> = {}
let totalEvents = 0
let totalFees = 0
rawRouting.forEach(r => {
if (!routingMap[r.channel_id]) {
routingMap[r.channel_id] = {
channel_id: r.channel_id,
send_errors: 0,
receive_errors: 0,
forward_errors_as_input: 0,
forward_errors_as_output: 0,
missed_forward_fee_as_input: 0,
missed_forward_fee_as_output: 0,
forward_fee_as_input: 0,
forward_fee_as_output: 0,
events_number: 0
}
}
routingMap[r.channel_id].send_errors += r.send_errors
routingMap[r.channel_id].receive_errors += r.receive_errors
routingMap[r.channel_id].forward_errors_as_input += r.forward_errors_as_input
routingMap[r.channel_id].forward_errors_as_output += r.forward_errors_as_output
routingMap[r.channel_id].missed_forward_fee_as_input += r.missed_forward_fee_as_input
routingMap[r.channel_id].missed_forward_fee_as_output += r.missed_forward_fee_as_output
routingMap[r.channel_id].forward_fee_as_input += r.forward_fee_as_input
routingMap[r.channel_id].forward_fee_as_output += r.forward_fee_as_output
routingMap[r.channel_id].events_number++
totalEvents += r.events_as_input
totalFees += r.forward_fee_as_input
})
const { channelsBalanceEvents, chainBalanceEvents } = await this.storage.metricsStorage.GetBalanceEvents({ from: req.from_unix, to: req.to_unix })
const chainBalance: Types.GraphPoint[] = []
chainBalanceEvents.forEach(e => {
if (chainBalance.length === 0) {
chainBalance.push({ x: e.block_height, y: e.total_chain_balance })
return
}
const last = chainBalance[chainBalance.length - 1]
if (last.y !== e.total_chain_balance) {
chainBalance.push({ x: e.block_height, y: e.total_chain_balance })
}
})
const chansPerBlock = new Map()
channelsBalanceEvents.forEach(e => {
const height = e.balance_event.block_height
const local = e.local_balance_sats
const v = chansPerBlock.get(height)
if (!v) {
chansPerBlock.set(height, local)
return
}
chansPerBlock.set(height, local + v)
})
const chansBalance: Types.GraphPoint[] = []
chansPerBlock.forEach((v, k) => {
if (chansBalance.length === 0) {
chansBalance.push({ x: k, y: v })
return
}
const last = chansBalance[chansBalance.length - 1]
if (last.y !== v) {
chansBalance.push({ x: k, y: v })
}
})
return {
nodes: [{
chain_balance_events: []/*chainBalanceEvents.map(e => ({
block_height: e.block_height,
confirmed_balance: e.confirmed_chain_balance,
unconfirmed_balance: e.unconfirmed_chain_balance,
total_balance: e.total_chain_balance
}))*/,
channels_balance_events: []/*channelsBalanceEvents.map(e => ({
block_height: e.balance_event.block_height,
channel_id: e.channel_id,
local_balance_sats: e.local_balance_sats,
remote_balance_sats: e.remote_balance_sats
}))*/,
chain_balance: chainBalance,
channel_balance: chansBalance,
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) })),
channel_routing: Object.values(routingMap)
forwarding_events: totalEvents,
forwarding_fees: totalFees
}],
}
}

View file

@ -35,6 +35,12 @@ export class ChannelRouting {
@Column({ default: 0 })
forward_fee_as_output: number
@Column({ default: 0 })
events_as_output: number
@Column({ default: 0 })
events_as_input: number
@Column({ default: 0 })
latest_index_offset: number

View file

@ -1,4 +1,4 @@
import { Between, DataSource, EntityManager, FindOperator, LessThanOrEqual, MoreThanOrEqual } from "typeorm"
import { Between, DataSource, EntityManager, FindManyOptions, FindOperator, LessThanOrEqual, MoreThanOrEqual } from "typeorm"
import { BalanceEvent } from "./entity/BalanceEvent.js"
import { ChannelBalanceEvent } from "./entity/ChannelsBalanceEvent.js"
import TransactionsQueue, { TX } from "./transactionsQueue.js";
@ -89,21 +89,25 @@ export default class {
if (event.forward_fee_as_output) {
await repo.increment({ day_unix: dayUnix, channel_id: channelId }, "forward_fee_as_output", event.forward_fee_as_output)
}
if (event.events_as_input) {
await repo.increment({ day_unix: dayUnix, channel_id: channelId }, "events_as_input", event.events_as_input)
}
if (event.events_as_output) {
await repo.increment({ day_unix: dayUnix, channel_id: channelId }, "events_as_output", event.events_as_output)
}
if (event.latest_index_offset) {
await repo.update(existing.serial_id, { latest_index_offset: event.latest_index_offset })
}
}
}
const getTimeQuery = ({ from, to }: { from?: number, to?: number }) => {
const getTimeQuery = ({ from, to }: { from?: number, to?: number }): FindManyOptions<{ created_at: Date }> => {
if (!!from && !!to) {
return { where: { created_at: Between<Date>(new Date(from * 1000), new Date(to * 1000)) } }
return { where: { created_at: Between<Date>(new Date(from * 1000), new Date(to * 1000)) }, order: { created_at: 'ASC' } }
} else if (!!from) {
return { where: { created_at: MoreThanOrEqual<Date>(new Date(from * 1000)) } }
return { where: { created_at: MoreThanOrEqual<Date>(new Date(from * 1000)) }, order: { created_at: 'ASC' } }
} else if (!!to) {
return { where: { created_at: LessThanOrEqual<Date>(new Date(to * 1000)) } }
return { where: { created_at: LessThanOrEqual<Date>(new Date(to * 1000)) }, order: { created_at: 'ASC' } }
}
return {}
}

View file

@ -0,0 +1,20 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class HtlcCount1724266887195 implements MigrationInterface {
name = 'HtlcCount1724266887195'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "temporary_channel_routing" ("serial_id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "day_unix" integer NOT NULL, "channel_id" varchar NOT NULL, "send_errors" integer NOT NULL DEFAULT (0), "receive_errors" integer NOT NULL DEFAULT (0), "forward_errors_as_input" integer NOT NULL DEFAULT (0), "forward_errors_as_output" integer NOT NULL DEFAULT (0), "missed_forward_fee_as_input" integer NOT NULL DEFAULT (0), "missed_forward_fee_as_output" integer NOT NULL DEFAULT (0), "forward_fee_as_input" integer NOT NULL DEFAULT (0), "forward_fee_as_output" integer NOT NULL DEFAULT (0), "latest_index_offset" integer NOT NULL DEFAULT (0), "created_at" datetime NOT NULL DEFAULT (datetime('now')), "updated_at" datetime NOT NULL DEFAULT (datetime('now')), "events_as_output" integer NOT NULL DEFAULT (0), "events_as_input" integer NOT NULL DEFAULT (0))`);
await queryRunner.query(`INSERT INTO "temporary_channel_routing"("serial_id", "day_unix", "channel_id", "send_errors", "receive_errors", "forward_errors_as_input", "forward_errors_as_output", "missed_forward_fee_as_input", "missed_forward_fee_as_output", "forward_fee_as_input", "forward_fee_as_output", "latest_index_offset", "created_at", "updated_at") SELECT "serial_id", "day_unix", "channel_id", "send_errors", "receive_errors", "forward_errors_as_input", "forward_errors_as_output", "missed_forward_fee_as_input", "missed_forward_fee_as_output", "forward_fee_as_input", "forward_fee_as_output", "latest_index_offset", "created_at", "updated_at" FROM "channel_routing"`);
await queryRunner.query(`DROP TABLE "channel_routing"`);
await queryRunner.query(`ALTER TABLE "temporary_channel_routing" RENAME TO "channel_routing"`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "channel_routing" RENAME TO "temporary_channel_routing"`);
await queryRunner.query(`CREATE TABLE "channel_routing" ("serial_id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "day_unix" integer NOT NULL, "channel_id" varchar NOT NULL, "send_errors" integer NOT NULL DEFAULT (0), "receive_errors" integer NOT NULL DEFAULT (0), "forward_errors_as_input" integer NOT NULL DEFAULT (0), "forward_errors_as_output" integer NOT NULL DEFAULT (0), "missed_forward_fee_as_input" integer NOT NULL DEFAULT (0), "missed_forward_fee_as_output" integer NOT NULL DEFAULT (0), "forward_fee_as_input" integer NOT NULL DEFAULT (0), "forward_fee_as_output" integer NOT NULL DEFAULT (0), "latest_index_offset" integer NOT NULL DEFAULT (0), "created_at" datetime NOT NULL DEFAULT (datetime('now')), "updated_at" datetime NOT NULL DEFAULT (datetime('now')))`);
await queryRunner.query(`INSERT INTO "channel_routing"("serial_id", "day_unix", "channel_id", "send_errors", "receive_errors", "forward_errors_as_input", "forward_errors_as_output", "missed_forward_fee_as_input", "missed_forward_fee_as_output", "forward_fee_as_input", "forward_fee_as_output", "latest_index_offset", "created_at", "updated_at") SELECT "serial_id", "day_unix", "channel_id", "send_errors", "receive_errors", "forward_errors_as_input", "forward_errors_as_output", "missed_forward_fee_as_input", "missed_forward_fee_as_output", "forward_fee_as_input", "forward_fee_as_output", "latest_index_offset", "created_at", "updated_at" FROM "temporary_channel_routing"`);
await queryRunner.query(`DROP TABLE "temporary_channel_routing"`);
}
}

View file

@ -10,8 +10,9 @@ import { LndNodeInfo1720187506189 } from './1720187506189-lnd_node_info.js'
import { TrackedProvider1720814323679 } from './1720814323679-tracked_provider.js'
import { CreateInviteTokenTable1721751414878 } from "./1721751414878-create_invite_token_table.js"
import { PaymentIndex1721760297610 } from './1721760297610-payment_index.js'
import { HtlcCount1724266887195 } from './1724266887195-htlc_count.js'
const allMigrations = [Initial1703170309875, LspOrder1718387847693, LiquidityProvider1719335699480, LndNodeInfo1720187506189, TrackedProvider1720814323679, CreateInviteTokenTable1721751414878, PaymentIndex1721760297610]
const allMetricsMigrations = [LndMetrics1703170330183, ChannelRouting1709316653538]
const allMetricsMigrations = [LndMetrics1703170330183, ChannelRouting1709316653538, HtlcCount1724266887195]
export const TypeOrmMigrationRunner = async (log: PubLogger, storageManager: Storage, settings: DbSettings, arg: string | undefined): Promise<boolean> => {
if (arg === 'fake_initial_migration') {
runFakeMigration(settings.databaseFile, [Initial1703170309875])