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 { 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 { 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 { 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({ export default new DataSource({
type: "sqlite", type: "sqlite",
database: "db.sqlite", database: "db.sqlite",
// logging: true, // logging: true,
migrations: [Initial1703170309875, LspOrder1718387847693, LiquidityProvider1719335699480, LndNodeInfo1720187506189, CreateInviteTokenTable1721751414878], migrations: [Initial1703170309875, LspOrder1718387847693, LiquidityProvider1719335699480, LndNodeInfo1720187506189, CreateInviteTokenTable1721751414878, PaymentIndex1721760297610],
entities: [User, UserReceivingInvoice, UserReceivingAddress, AddressReceivingTransaction, UserInvoicePayment, UserTransactionPayment, entities: [User, UserReceivingInvoice, UserReceivingAddress, AddressReceivingTransaction, UserInvoicePayment, UserTransactionPayment,
UserBasicAuth, UserEphemeralKey, Product, UserToUserPayment, Application, ApplicationUser, UserToUserPayment, LspOrder, LndNodeInfo, TrackedProvider, InviteToken], UserBasicAuth, UserEphemeralKey, Product, UserToUserPayment, Application, ApplicationUser, UserToUserPayment, LspOrder, LndNodeInfo, TrackedProvider, InviteToken],
// synchronize: true, // synchronize: true,

View file

@ -1,10 +1,15 @@
import { DataSource } from "typeorm" 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({ export default new DataSource({
type: "sqlite", type: "sqlite",
database: "db.sqlite", database: "metrics.sqlite",
entities: [LspOrder], 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__: - __GuestWithPub__:
- expected context content - expected context content
- __app_id__: _string_
- __pub__: _string_ - __pub__: _string_
- __app_id__: _string_
## HTTP Methods ## HTTP Methods
### These are the http methods the client implements to communicate with the API ### 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_ - __user_identifier__: _string_
- __nostr_pub__: _string_ - __nostr_pub__: _string_
### Product ### Application
- __id__: _string_ - __id__: _string_
- __balance__: _number_
- __npub__: _string_
- __name__: _string_ - __name__: _string_
- __price_sats__: _number_
### GetInviteTokenStateResponse ### GetInviteTokenStateResponse
- __used__: _boolean_ - __used__: _boolean_

View file

@ -28,7 +28,7 @@
}), }),
serverStream: (bool) false serverStream: (bool) false
}), }),
(*main.Method)(0xc000274a50)({ (*main.Method)(0xc0002e4a50)({
in: (main.MethodMessage) { in: (main.MethodMessage) {
name: (string) (len=13) "AddAppRequest", name: (string) (len=13) "AddAppRequest",
hasZeroFields: (bool) false hasZeroFields: (bool) false
@ -57,7 +57,7 @@
}), }),
serverStream: (bool) false serverStream: (bool) false
}), }),
(*main.Method)(0xc000274af0)({ (*main.Method)(0xc0002e4af0)({
in: (main.MethodMessage) { in: (main.MethodMessage) {
name: (string) (len=14) "AuthAppRequest", name: (string) (len=14) "AuthAppRequest",
hasZeroFields: (bool) false hasZeroFields: (bool) false
@ -86,7 +86,7 @@
}), }),
serverStream: (bool) false serverStream: (bool) false
}), }),
(*main.Method)(0xc000274b90)({ (*main.Method)(0xc0002e4b90)({
in: (main.MethodMessage) { in: (main.MethodMessage) {
name: (string) (len=14) "BanUserRequest", name: (string) (len=14) "BanUserRequest",
hasZeroFields: (bool) false hasZeroFields: (bool) false
@ -115,7 +115,7 @@
}), }),
serverStream: (bool) false serverStream: (bool) false
}), }),
(*main.Method)(0xc000274be0)({ (*main.Method)(0xc0002e4be0)({
in: (main.MethodMessage) { in: (main.MethodMessage) {
name: (string) (len=5) "Empty", name: (string) (len=5) "Empty",
hasZeroFields: (bool) true hasZeroFields: (bool) true
@ -144,7 +144,7 @@
}), }),
serverStream: (bool) false serverStream: (bool) false
}), }),
(*main.Method)(0xc000274c30)({ (*main.Method)(0xc0002e4c30)({
in: (main.MethodMessage) { in: (main.MethodMessage) {
name: (string) (len=5) "Empty", name: (string) (len=5) "Empty",
hasZeroFields: (bool) true hasZeroFields: (bool) true
@ -571,9 +571,9 @@
id: (string) (len=4) "user", id: (string) (len=4) "user",
name: (string) (len=4) "User", name: (string) (len=4) "User",
context: (map[string]string) (len=3) { 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=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", method: (string) (len=4) "post",
@ -602,8 +602,8 @@
id: (string) (len=8) "guestPub", id: (string) (len=8) "guestPub",
name: (string) (len=12) "GuestWithPub", name: (string) (len=12) "GuestWithPub",
context: (map[string]string) (len=2) { 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", method: (string) (len=4) "post",
@ -1382,9 +1382,9 @@
id: (string) (len=4) "user", id: (string) (len=4) "user",
name: (string) (len=4) "User", name: (string) (len=4) "User",
context: (map[string]string) (len=3) { 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=7) "user_id": (string) (len=6) "string",
(string) (len=6) "app_id": (string) (len=6) "string", (string) (len=6) "app_id": (string) (len=6) "string"
(string) (len=11) "app_user_id": (string) (len=6) "string"
} }
}), }),
method: (string) (len=4) "post", method: (string) (len=4) "post",
@ -2063,9 +2063,9 @@
name: (string) (len=7) "invoice", name: (string) (len=7) "invoice",
kind: (string) (len=6) "string", kind: (string) (len=6) "string",
isMap: (bool) false, isMap: (bool) false,
isArray: (bool) false, isArray: (bool) true,
isEnum: (bool) false, isEnum: (bool) false,
isMessage: (bool) false, isMessage: (bool) true,
isOptional: (bool) false, isOptional: (bool) false,
oneOfName: (string) "" oneOfName: (string) ""
}) })
@ -2137,7 +2137,7 @@
isMap: (bool) false, isMap: (bool) false,
isArray: (bool) false, isArray: (bool) false,
isEnum: (bool) false, isEnum: (bool) false,
isMessage: (bool) false, isMessage: (bool) true,
isOptional: (bool) false, isOptional: (bool) false,
oneOfName: (string) "" oneOfName: (string) ""
}), }),
@ -2155,9 +2155,9 @@
name: (string) (len=15) "minWithdrawable", name: (string) (len=15) "minWithdrawable",
kind: (string) (len=5) "int64", kind: (string) (len=5) "int64",
isMap: (bool) false, isMap: (bool) false,
isArray: (bool) false, isArray: (bool) true,
isEnum: (bool) false, isEnum: (bool) false,
isMessage: (bool) false, isMessage: (bool) true,
isOptional: (bool) false, isOptional: (bool) false,
oneOfName: (string) "" oneOfName: (string) ""
}), }),
@ -2261,8 +2261,8 @@
isMap: (bool) false, isMap: (bool) false,
isArray: (bool) false, isArray: (bool) false,
isEnum: (bool) false, isEnum: (bool) false,
isMessage: (bool) false, isMessage: (bool) true,
isOptional: (bool) false, isOptional: (bool) true,
oneOfName: (string) "" oneOfName: (string) ""
}), }),
(string) (len=3) "url": (*main.Field)(0xc0000b0cc0)({ (string) (len=3) "url": (*main.Field)(0xc0000b0cc0)({
@ -2271,8 +2271,8 @@
isMap: (bool) false, isMap: (bool) false,
isArray: (bool) false, isArray: (bool) false,
isEnum: (bool) false, isEnum: (bool) false,
isMessage: (bool) false, isMessage: (bool) true,
isOptional: (bool) false, isOptional: (bool) true,
oneOfName: (string) "" oneOfName: (string) ""
}) })
} }
@ -2455,9 +2455,9 @@
name: (string) (len=5) "nodes", name: (string) (len=5) "nodes",
kind: (string) (len=14) "LndNodeMetrics", kind: (string) (len=14) "LndNodeMetrics",
isMap: (bool) false, isMap: (bool) false,
isArray: (bool) true, isArray: (bool) false,
isEnum: (bool) false, isEnum: (bool) false,
isMessage: (bool) true, isMessage: (bool) false,
isOptional: (bool) false, isOptional: (bool) false,
oneOfName: (string) "" oneOfName: (string) ""
}) })
@ -2626,6 +2626,16 @@
isMessage: (bool) true, isMessage: (bool) true,
isOptional: (bool) false, isOptional: (bool) false,
oneOfName: (string) "" 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, isArray: (bool) false,
isEnum: (bool) false, isEnum: (bool) false,
isMessage: (bool) false, isMessage: (bool) false,
isOptional: (bool) false, isOptional: (bool) true,
oneOfName: (string) "" oneOfName: (string) ""
}), }),
(string) (len=8) "max_size": (*main.Field)(0xc000315cc0)({ (string) (len=8) "max_size": (*main.Field)(0xc000315cc0)({
@ -2670,7 +2680,7 @@
isArray: (bool) false, isArray: (bool) false,
isEnum: (bool) false, isEnum: (bool) false,
isMessage: (bool) false, isMessage: (bool) false,
isOptional: (bool) false, isOptional: (bool) true,
oneOfName: (string) "" oneOfName: (string) ""
}), }),
(string) (len=21) "latestIncomingInvoice": (*main.Field)(0xc000315b40)({ (string) (len=21) "latestIncomingInvoice": (*main.Field)(0xc000315b40)({
@ -2700,7 +2710,7 @@
isArray: (bool) false, isArray: (bool) false,
isEnum: (bool) false, isEnum: (bool) false,
isMessage: (bool) false, isMessage: (bool) false,
isOptional: (bool) false, isOptional: (bool) true,
oneOfName: (string) "" oneOfName: (string) ""
}) })
} }
@ -2971,9 +2981,9 @@
name: (string) (len=12) "operation_id", name: (string) (len=12) "operation_id",
kind: (string) (len=6) "string", kind: (string) (len=6) "string",
isMap: (bool) false, isMap: (bool) false,
isArray: (bool) false, isArray: (bool) true,
isEnum: (bool) false, isEnum: (bool) false,
isMessage: (bool) false, isMessage: (bool) true,
isOptional: (bool) false, isOptional: (bool) false,
oneOfName: (string) "" oneOfName: (string) ""
}), }),
@ -3185,7 +3195,7 @@
name: (string) (len=4) "info", name: (string) (len=4) "info",
kind: (string) (len=8) "UserInfo", kind: (string) (len=8) "UserInfo",
isMap: (bool) false, isMap: (bool) false,
isArray: (bool) false, isArray: (bool) true,
isEnum: (bool) false, isEnum: (bool) false,
isMessage: (bool) true, isMessage: (bool) true,
isOptional: (bool) false, isOptional: (bool) false,
@ -3471,7 +3481,7 @@
name: (string) (len=10) "operations", name: (string) (len=10) "operations",
kind: (string) (len=13) "UserOperation", kind: (string) (len=13) "UserOperation",
isMap: (bool) false, isMap: (bool) false,
isArray: (bool) true, isArray: (bool) false,
isEnum: (bool) false, isEnum: (bool) false,
isMessage: (bool) true, isMessage: (bool) true,
isOptional: (bool) false, isOptional: (bool) false,
@ -3560,7 +3570,7 @@
isArray: (bool) false, isArray: (bool) false,
isEnum: (bool) false, isEnum: (bool) false,
isMessage: (bool) false, isMessage: (bool) false,
isOptional: (bool) false, isOptional: (bool) true,
oneOfName: (string) "" oneOfName: (string) ""
}), }),
(string) (len=19) "outgoing_channel_id": (*main.Field)(0xc00048b200)({ (string) (len=19) "outgoing_channel_id": (*main.Field)(0xc00048b200)({
@ -3885,7 +3895,23 @@
isMap: (bool) false, isMap: (bool) false,
isArray: (bool) false, isArray: (bool) false,
isEnum: (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, isOptional: (bool) false,
oneOfName: (string) "" oneOfName: (string) ""
}), }),
@ -3895,7 +3921,7 @@
isMap: (bool) false, isMap: (bool) false,
isArray: (bool) false, isArray: (bool) false,
isEnum: (bool) false, isEnum: (bool) false,
isMessage: (bool) true, isMessage: (bool) false,
isOptional: (bool) false, isOptional: (bool) false,
oneOfName: (string) "" oneOfName: (string) ""
}), }),
@ -4067,7 +4093,7 @@
name: (string) (len=16) "pending_channels", name: (string) (len=16) "pending_channels",
kind: (string) (len=5) "int64", kind: (string) (len=5) "int64",
isMap: (bool) false, isMap: (bool) false,
isArray: (bool) false, isArray: (bool) true,
isEnum: (bool) false, isEnum: (bool) false,
isMessage: (bool) false, isMessage: (bool) false,
isOptional: (bool) false, isOptional: (bool) false,
@ -4189,9 +4215,9 @@
name: (string) (len=4) "name", name: (string) (len=4) "name",
kind: (string) (len=6) "string", kind: (string) (len=6) "string",
isMap: (bool) false, isMap: (bool) false,
isArray: (bool) false, isArray: (bool) true,
isEnum: (bool) false, isEnum: (bool) false,
isMessage: (bool) false, isMessage: (bool) true,
isOptional: (bool) false, isOptional: (bool) false,
oneOfName: (string) "" oneOfName: (string) ""
}) })
@ -4208,7 +4234,7 @@
isArray: (bool) false, isArray: (bool) false,
isEnum: (bool) false, isEnum: (bool) false,
isMessage: (bool) false, isMessage: (bool) false,
isOptional: (bool) false, isOptional: (bool) true,
oneOfName: (string) "" oneOfName: (string) ""
}), }),
(string) (len=16) "payer_identifier": (*main.Field)(0xc0003148c0)({ (string) (len=16) "payer_identifier": (*main.Field)(0xc0003148c0)({
@ -4253,7 +4279,7 @@
isMap: (bool) false, isMap: (bool) false,
isArray: (bool) false, isArray: (bool) false,
isEnum: (bool) false, isEnum: (bool) false,
isMessage: (bool) false, isMessage: (bool) true,
isOptional: (bool) false, isOptional: (bool) false,
oneOfName: (string) "" oneOfName: (string) ""
}) })
@ -4453,9 +4479,9 @@
name: (string) (len=9) "confirmed", name: (string) (len=9) "confirmed",
kind: (string) (len=4) "bool", kind: (string) (len=4) "bool",
isMap: (bool) false, isMap: (bool) false,
isArray: (bool) false, isArray: (bool) true,
isEnum: (bool) false, isEnum: (bool) false,
isMessage: (bool) false, isMessage: (bool) true,
isOptional: (bool) false, isOptional: (bool) false,
oneOfName: (string) "" oneOfName: (string) ""
}), }),
@ -4536,6 +4562,60 @@
oneOfName: (string) "" 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 = { export type NostrClientParams = {
pubDestination: string pubDestination: string
retrieveNostrMetricsAuth: () => Promise<string | null>
retrieveNostrUserAuth: () => Promise<string | null> retrieveNostrUserAuth: () => Promise<string | null>
retrieveNostrGuestWithPubAuth: () => Promise<string | null> retrieveNostrGuestWithPubAuth: () => Promise<string | null>
retrieveNostrAdminAuth: () => Promise<string | null> retrieveNostrAdminAuth: () => Promise<string | null>
retrieveNostrMetricsAuth: () => Promise<string | null>
checkResult?: true checkResult?: true
} }
export default (params: NostrClientParams, send: (to:string, message: NostrRequest) => Promise<any>, subscribe: (to:string, message: NostrRequest, cb:(res:any)=> void) => void) => ({ export default (params: NostrClientParams, send: (to:string, message: NostrRequest) => Promise<any>, subscribe: (to:string, message: NostrRequest, cb:(res:any)=> void) => void) => ({

File diff suppressed because it is too large Load diff

View file

@ -87,19 +87,6 @@ message RoutingEvent {
bool offchain = 11; bool offchain = 11;
bool forward_fail_event = 12; 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 { message OpenChannel {
string channel_id = 1; string channel_id = 1;
@ -116,29 +103,22 @@ message ClosedChannel {
int64 closed_height =4; int64 closed_height =4;
} }
message ChannelRouting { message GraphPoint {
string channel_id = 1; int64 x = 1;
int64 send_errors = 2; int64 y = 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 LndNodeMetrics { message LndNodeMetrics {
repeated ChannelBalanceEvent channels_balance_events = 1; repeated GraphPoint chain_balance = 1;
repeated ChainBalanceEvent chain_balance_events = 2; repeated GraphPoint channel_balance = 2;
int64 offline_channels = 4; int64 offline_channels = 4;
int64 online_channels = 5; int64 online_channels = 5;
int64 pending_channels = 6; int64 pending_channels = 6;
int64 closing_channels = 7; int64 closing_channels = 7;
repeated OpenChannel open_channels = 8; repeated OpenChannel open_channels = 8;
repeated ClosedChannel closed_channels = 9; repeated ClosedChannel closed_channels = 9;
repeated ChannelRouting channel_routing = 10; int64 forwarding_events = 11;
int64 forwarding_fees = 12;
} }
message LndMetrics { message LndMetrics {

View file

@ -18,7 +18,7 @@ export default class HtlcTracker {
} }
log = getLogger({ component: 'htlcTracker' }) log = getLogger({ component: 'htlcTracker' })
onHtlcEvent = async (htlc: HtlcEvent) => { onHtlcEvent = async (htlc: HtlcEvent) => {
//getLogger({ component: 'debugHtlcs' })(htlc) /* //getLogger({ component: 'debugHtlcs' })(htlc)
const htlcEvent = htlc.event const htlcEvent = htlc.event
if (htlcEvent.oneofKind === 'subscribedEvent') { if (htlcEvent.oneofKind === 'subscribedEvent') {
return return
@ -45,10 +45,10 @@ export default class HtlcTracker {
return this.handleSuccess(info) return this.handleSuccess(info)
default: default:
//this.log("unknown htlc event type") //this.log("unknown htlc event type")
} } */
} }
handleForward = (fwe: ForwardEvent, { eventType, outgoingHtlcId, incomingHtlcId }: EventInfo) => { /* handleForward = (fwe: ForwardEvent, { eventType, outgoingHtlcId, incomingHtlcId }: EventInfo) => {
const { info } = fwe const { info } = fwe
const incomingAmtMsat = info ? Number(info.incomingAmtMsat) : 0 const incomingAmtMsat = info ? Number(info.incomingAmtMsat) : 0
const outgoingAmtMsat = info ? Number(info.outgoingAmtMsat) : 0 const outgoingAmtMsat = info ? Number(info.outgoingAmtMsat) : 0
@ -59,9 +59,9 @@ export default class HtlcTracker {
} else if (eventType === HtlcEvent_EventType.FORWARD) { } else if (eventType === HtlcEvent_EventType.FORWARD) {
this.pendingForwardHtlcs.set(outgoingHtlcId, outgoingAmtMsat - incomingAmtMsat) 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) { if (eventType === HtlcEvent_EventType.SEND && this.deleteMapEntry(outgoingHtlcId, this.pendingSendHtlcs) !== null) {
return this.incrementSendFailures(outgoingChannelId) return this.incrementSendFailures(outgoingChannelId)
} }
@ -86,9 +86,9 @@ export default class HtlcTracker {
return this.incrementReceiveFailures(incomingChannelId) return this.incrementReceiveFailures(incomingChannelId)
} }
} }
} } */
handleSuccess = ({ eventType, outgoingHtlcId, incomingHtlcId }: EventInfo) => { /* handleSuccess = ({ eventType, outgoingHtlcId, incomingHtlcId }: EventInfo) => {
if (eventType === HtlcEvent_EventType.SEND) { if (eventType === HtlcEvent_EventType.SEND) {
this.deleteMapEntry(outgoingHtlcId, this.pendingSendHtlcs) this.deleteMapEntry(outgoingHtlcId, this.pendingSendHtlcs)
} else if (eventType === HtlcEvent_EventType.RECEIVE) { } 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(incomingHtlcId, this.pendingReceiveHtlcs) !== null) return
if (this.deleteMapEntry(outgoingHtlcId, this.pendingForwardHtlcs) !== null) return if (this.deleteMapEntry(outgoingHtlcId, this.pendingForwardHtlcs) !== null) return
} }
} } */
/*
deleteMapEntry = (key: number, map: Map<number, number>) => { deleteMapEntry = (key: number, map: Map<number, number>) => {
if (!map.has(key)) { if (!map.has(key)) {
return null return null
@ -109,9 +109,9 @@ export default class HtlcTracker {
const v = map.get(key) const v = map.get(key)
map.delete(key) map.delete(key)
return v || null return v || null
} } */
incrementSendFailures = async (outgoingChannelId: number) => { /* incrementSendFailures = async (outgoingChannelId: number) => {
await this.storage.metricsStorage.IncrementChannelRouting(outgoingChannelId.toString(), { send_errors: 1 }) await this.storage.metricsStorage.IncrementChannelRouting(outgoingChannelId.toString(), { send_errors: 1 })
} }
incrementReceiveFailures = async (incomingChannelId: number) => { incrementReceiveFailures = async (incomingChannelId: number) => {
@ -120,6 +120,6 @@ export default class HtlcTracker {
incrementForwardFailures = async (incomingChannelId: number, outgoingChannelId: number, amt: number) => { 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(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 }) 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, remote_balance_sats: c.remoteBalanceSats,
})) }))
await this.storage.metricsStorage.SaveBalanceEvents(balanceEvent, channelsEvents) await this.storage.metricsStorage.SaveBalanceEvents(balanceEvent, channelsEvents)
await this.FetchLatestForwardingEvents()
} }
async FetchLatestForwardingEvents() { async FetchLatestForwardingEvents() {
@ -43,8 +44,8 @@ export default class Handler {
const res = await this.lnd.GetForwardingHistory(latestIndex) 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 })) 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 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.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 }) await this.storage.metricsStorage.IncrementChannelRouting(f.chanIdOut, { forward_fee_as_output: f.fee, latest_index_offset: f.offset, events_as_output: 1 })
})) }))
} }
@ -176,7 +177,7 @@ export default class Handler {
total_fees: totalFees, total_fees: totalFees,
invoices: receivingInvoices.length, invoices: receivingInvoices.length,
operations:[] operations: []
} }
} }
@ -207,54 +208,60 @@ export default class Handler {
const { totalPendingOpen, totalPendingClose } = await this.GetPendingChannelsInfo() const { totalPendingOpen, totalPendingClose } = await this.GetPendingChannelsInfo()
const { channels: closedChannels } = await this.lnd.ListClosedChannels() const { channels: closedChannels } = await this.lnd.ListClosedChannels()
const rawRouting = await this.storage.metricsStorage.GetChannelRouting({ from: req.from_unix, to: req.to_unix }) 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 => { rawRouting.forEach(r => {
if (!routingMap[r.channel_id]) { totalEvents += r.events_as_input
routingMap[r.channel_id] = { totalFees += r.forward_fee_as_input
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++
}) })
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 })
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 { return {
nodes: [{ nodes: [{
chain_balance_events: []/*chainBalanceEvents.map(e => ({ chain_balance: chainBalance,
block_height: e.block_height, channel_balance: chansBalance,
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
}))*/,
closing_channels: totalPendingClose, closing_channels: totalPendingClose,
pending_channels: totalPendingOpen, pending_channels: totalPendingOpen,
offline_channels: totalInactive, offline_channels: totalInactive,
online_channels: totalActive, online_channels: totalActive,
closed_channels: closedChannels.map(c => ({ capacity: Number(c.capacity), channel_id: c.chanId, closed_height: c.closeHeight })), 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) })), 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 }) @Column({ default: 0 })
forward_fee_as_output: number forward_fee_as_output: number
@Column({ default: 0 })
events_as_output: number
@Column({ default: 0 })
events_as_input: number
@Column({ default: 0 }) @Column({ default: 0 })
latest_index_offset: number 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 { BalanceEvent } from "./entity/BalanceEvent.js"
import { ChannelBalanceEvent } from "./entity/ChannelsBalanceEvent.js" import { ChannelBalanceEvent } from "./entity/ChannelsBalanceEvent.js"
import TransactionsQueue, { TX } from "./transactionsQueue.js"; import TransactionsQueue, { TX } from "./transactionsQueue.js";
@ -89,21 +89,25 @@ export default class {
if (event.forward_fee_as_output) { if (event.forward_fee_as_output) {
await repo.increment({ day_unix: dayUnix, channel_id: channelId }, "forward_fee_as_output", 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) { if (event.latest_index_offset) {
await repo.update(existing.serial_id, { latest_index_offset: 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) { 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) { } 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) { } 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 {} 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 { TrackedProvider1720814323679 } from './1720814323679-tracked_provider.js'
import { CreateInviteTokenTable1721751414878 } from "./1721751414878-create_invite_token_table.js" import { CreateInviteTokenTable1721751414878 } from "./1721751414878-create_invite_token_table.js"
import { PaymentIndex1721760297610 } from './1721760297610-payment_index.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 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> => { export const TypeOrmMigrationRunner = async (log: PubLogger, storageManager: Storage, settings: DbSettings, arg: string | undefined): Promise<boolean> => {
if (arg === 'fake_initial_migration') { if (arg === 'fake_initial_migration') {
runFakeMigration(settings.databaseFile, [Initial1703170309875]) runFakeMigration(settings.databaseFile, [Initial1703170309875])