better storage, track success

This commit is contained in:
boufni95 2024-03-01 19:35:00 +01:00
parent f50a638f75
commit d48a0fda22
19 changed files with 4241 additions and 4088 deletions

View file

@ -1,10 +1,10 @@
import { DataSource } from "typeorm" import { DataSource } from "typeorm"
import { HtlcFailures } from "./build/src/services/storage/entity/HtlcFailures.js" import { ChannelRouting } from "./build/src/services/storage/entity/ChannelRouting.js"
export default new DataSource({ export default new DataSource({
type: "sqlite", type: "sqlite",
database: "metrics.sqlite", database: "metrics.sqlite",
entities: [HtlcFailures], entities: [ChannelRouting],
}); });

View file

@ -110,9 +110,9 @@ The nostr server will send back a message response, and inside the body there wi
- __User__: - __User__:
- expected context content - expected context content
- __user_id__: _string_
- __app_id__: _string_ - __app_id__: _string_
- __app_user_id__: _string_ - __app_user_id__: _string_
- __user_id__: _string_
- __Admin__: - __Admin__:
- expected context content - expected context content
@ -444,30 +444,102 @@ The nostr server will send back a message response, and inside the body there wi
## Messages ## Messages
### The content of requests and response from the methods ### The content of requests and response from the methods
### AppUser ### EncryptionExchangeRequest
- __identifier__: _string_ - __publicKey__: _string_
- __info__: _[UserInfo](#UserInfo)_ - __deviceId__: _string_
- __max_withdrawable__: _number_
### SendAppUserToAppUserPaymentRequest ### DecodeInvoiceResponse
- __from_user_identifier__: _string_ - __amount__: _number_
- __to_user_identifier__: _string_
### SetMockAppUserBalanceRequest
- __user_identifier__: _string_
- __amount__: _number_ - __amount__: _number_
### NewAddressRequest ### NewAddressRequest
- __addressType__: _[AddressType](#AddressType)_ - __addressType__: _[AddressType](#AddressType)_
### LndMetrics ### NewInvoiceRequest
- __nodes__: ARRAY of: _[LndNodeMetrics](#LndNodeMetrics)_ - __amountSats__: _number_
- __memo__: _string_
### PayAddressRequest ### UserInfo
- __address__: _string_ - __userId__: _string_
- __amoutSats__: _number_ - __balance__: _number_
- __satsPerVByte__: _number_ - __max_withdrawable__: _number_
- __user_identifier__: _string_
### LnurlLinkResponse ### MigrationUpdate
- __lnurl__: _string_ - __closure__: _[ClosureMigration](#ClosureMigration)_ *this field is optional
- __k1__: _string_ - __relays__: _[RelaysMigration](#RelaysMigration)_ *this field is optional
### ChannelRouting
- __channel_id__: _string_
- __send_errors__: _number_
- __receive_errors__: _number_
- __forward_errors_as_input__: _number_
- __forward_errors_as_output__: _number_
- __missed_forward_fee_as_input__: _number_
- __missed_forward_fee_as_output__: _number_
- __forward_fee_as_input__: _number_
- __forward_fee_as_output__: _number_
### AddAppRequest
- __name__: _string_
- __allow_user_creation__: _boolean_
### PayAddressResponse
- __txId__: _string_
- __operation_id__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
### RelaysMigration
- __relays__: ARRAY of: _string_
### Empty
### LndMetricsRequest
- __from_unix__: _number_ *this field is optional
- __to_unix__: _number_ *this field is optional
### OpenChannel
- __channel_id__: _string_
- __capacity__: _number_
- __active__: _boolean_
- __lifetime__: _number_
- __local_balance__: _number_
- __remote_balance__: _number_
### Application
- __name__: _string_
- __id__: _string_
- __balance__: _number_
- __npub__: _string_
### SendAppUserToAppPaymentRequest
- __from_user_identifier__: _string_
- __amount__: _number_
### UserOperations
- __fromIndex__: _number_
- __toIndex__: _number_
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_
### GetProductBuyLinkResponse
- __link__: _string_
### AddAppUserRequest
- __identifier__: _string_
- __fail_if_exists__: _boolean_
- __balance__: _number_
### AppUser
- __identifier__: _string_
- __info__: _[UserInfo](#UserInfo)_
- __max_withdrawable__: _number_
### OpenChannelResponse
- __channelId__: _string_
### GetUserOperationsRequest ### GetUserOperationsRequest
- __latestIncomingInvoice__: _number_ - __latestIncomingInvoice__: _number_
@ -478,50 +550,92 @@ The nostr server will send back a message response, and inside the body there wi
- __latestOutgoingUserToUserPayment__: _number_ - __latestOutgoingUserToUserPayment__: _number_
- __max_size__: _number_ - __max_size__: _number_
### UserOperations ### ChainBalanceEvent
- __fromIndex__: _number_ - __block_height__: _number_
- __toIndex__: _number_ - __confirmed_balance__: _number_
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_ - __unconfirmed_balance__: _number_
- __total_balance__: _number_
### PayInvoiceResponse
- __preimage__: _string_
- __amount_paid__: _number_
- __operation_id__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
### NewAddressResponse
- __address__: _string_
### PayAddressRequest
- __address__: _string_
- __amoutSats__: _number_
- __satsPerVByte__: _number_
### UserOperation
- __paidAtUnix__: _number_
- __type__: _[UserOperationType](#UserOperationType)_
- __inbound__: _boolean_
- __amount__: _number_
- __identifier__: _string_
- __operationId__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
- __confirmed__: _boolean_
- __tx_hash__: _string_
- __internal__: _boolean_
### AddAppInvoiceRequest
- __payer_identifier__: _string_
- __http_callback_url__: _string_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
### AddAppUserInvoiceRequest
- __receiver_identifier__: _string_
- __payer_identifier__: _string_
- __http_callback_url__: _string_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
### AddProductRequest ### AddProductRequest
- __name__: _string_ - __name__: _string_
- __price_sats__: _number_ - __price_sats__: _number_
### UsersInfo
- __total__: _number_
- __no_balance__: _number_
- __negative_balance__: _number_
- __always_been_inactive__: _number_
- __balance_avg__: _number_
- __balance_median__: _number_
### LndGetInfoRequest
- __nodeId__: _number_
### LnurlLinkResponse
- __lnurl__: _string_
- __k1__: _string_
### LnurlWithdrawInfoResponse
- __tag__: _string_
- __callback__: _string_
- __k1__: _string_
- __defaultDescription__: _string_
- __minWithdrawable__: _number_
- __maxWithdrawable__: _number_
- __balanceCheck__: _string_
- __payLink__: _string_
### GetAppUserLNURLInfoRequest
- __user_identifier__: _string_
- __base_url_override__: _string_
### SetMockAppBalanceRequest
- __amount__: _number_
### PayAppUserInvoiceRequest ### PayAppUserInvoiceRequest
- __user_identifier__: _string_ - __user_identifier__: _string_
- __invoice__: _string_ - __invoice__: _string_
- __amount__: _number_ - __amount__: _number_
### SetMockInvoiceAsPaidRequest
- __invoice__: _string_
- __amount__: _number_
### Application
- __name__: _string_
- __id__: _string_
- __balance__: _number_
- __npub__: _string_
### OpenChannel
- __channel_id__: _string_
- __capacity__: _number_
- __active__: _boolean_
- __lifetime__: _number_
- __local_balance__: _number_
- __remote_balance__: _number_
### AppsMetrics
- __apps__: ARRAY of: _[AppMetrics](#AppMetrics)_
### LndMetricsRequest
- __from_unix__: _number_ *this field is optional
- __to_unix__: _number_ *this field is optional
### AddAppUserRequest
- __identifier__: _string_
- __fail_if_exists__: _boolean_
- __balance__: _number_
### PayInvoiceRequest ### PayInvoiceRequest
- __invoice__: _string_ - __invoice__: _string_
- __amount__: _number_ - __amount__: _number_
@ -532,18 +646,6 @@ The nostr server will send back a message response, and inside the body there wi
- __pushAmount__: _number_ - __pushAmount__: _number_
- __closeAddress__: _string_ - __closeAddress__: _string_
### UsersInfo
- __total__: _number_
- __no_balance__: _number_
- __negative_balance__: _number_
- __always_been_inactive__: _number_
- __balance_avg__: _number_
- __balance_median__: _number_
### NewInvoiceRequest
- __amountSats__: _number_
- __memo__: _string_
### RoutingEvent ### RoutingEvent
- __incoming_channel_id__: _number_ - __incoming_channel_id__: _number_
- __incoming_htlc_id__: _number_ - __incoming_htlc_id__: _number_
@ -558,70 +660,47 @@ The nostr server will send back a message response, and inside the body there wi
- __offchain__: _boolean_ - __offchain__: _boolean_
- __forward_fail_event__: _boolean_ - __forward_fail_event__: _boolean_
### AddAppInvoiceRequest
- __payer_identifier__: _string_
- __http_callback_url__: _string_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
### GetAppUserRequest
- __user_identifier__: _string_
### UserOperation
- __paidAtUnix__: _number_
- __type__: _[UserOperationType](#UserOperationType)_
- __inbound__: _boolean_
- __amount__: _number_
- __identifier__: _string_
- __operationId__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
- __confirmed__: _boolean_
- __tx_hash__: _string_
- __internal__: _boolean_
### LndNodeMetrics ### LndNodeMetrics
- __channels_balance_events__: ARRAY of: _[ChannelBalanceEvent](#ChannelBalanceEvent)_ - __channels_balance_events__: ARRAY of: _[ChannelBalanceEvent](#ChannelBalanceEvent)_
- __chain_balance_events__: ARRAY of: _[ChainBalanceEvent](#ChainBalanceEvent)_ - __chain_balance_events__: ARRAY of: _[ChainBalanceEvent](#ChainBalanceEvent)_
- __routing_events__: ARRAY of: _[RoutingEvent](#RoutingEvent)_
- __offline_channels__: _number_ - __offline_channels__: _number_
- __online_channels__: _number_ - __online_channels__: _number_
- __pending_channels__: _number_ - __pending_channels__: _number_
- __closing_channels__: _number_ - __closing_channels__: _number_
- __open_channels__: ARRAY of: _[OpenChannel](#OpenChannel)_ - __open_channels__: ARRAY of: _[OpenChannel](#OpenChannel)_
- __closed_channels__: ARRAY of: _[ClosedChannel](#ClosedChannel)_ - __closed_channels__: ARRAY of: _[ClosedChannel](#ClosedChannel)_
- __channel_routing__: ARRAY of: _[ChannelRouting](#ChannelRouting)_
### HandleLnurlPayResponse ### SetMockInvoiceAsPaidRequest
- __pr__: _string_ - __invoice__: _string_
- __routes__: ARRAY of: _[Empty](#Empty)_ - __amount__: _number_
### UsageMetric ### GetAppUserRequest
- __processed_at_ms__: _number_ - __user_identifier__: _string_
- __parsed_in_nano__: _number_
- __auth_in_nano__: _number_
- __validate_in_nano__: _number_
- __handle_in_nano__: _number_
- __rpc_name__: _string_
- __batch__: _boolean_
- __nostr__: _boolean_
- __batch_size__: _number_
### PayInvoiceResponse ### SendAppUserToAppUserPaymentRequest
- __preimage__: _string_ - __from_user_identifier__: _string_
- __amount_paid__: _number_ - __to_user_identifier__: _string_
- __operation_id__: _string_ - __amount__: _number_
- __service_fee__: _number_
- __network_fee__: _number_
### RelaysMigration ### GetUserOperationsResponse
- __relays__: ARRAY of: _string_ - __latestOutgoingInvoiceOperations__: _[UserOperations](#UserOperations)_
- __latestIncomingInvoiceOperations__: _[UserOperations](#UserOperations)_
- __latestOutgoingTxOperations__: _[UserOperations](#UserOperations)_
- __latestIncomingTxOperations__: _[UserOperations](#UserOperations)_
- __latestOutgoingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
- __latestIncomingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
### Empty ### ClosureMigration
- __closes_at_unix__: _number_
### ChannelBalanceEvent ### AppsMetrics
- __block_height__: _number_ - __apps__: ARRAY of: _[AppMetrics](#AppMetrics)_
### ClosedChannel
- __channel_id__: _string_ - __channel_id__: _string_
- __local_balance_sats__: _number_ - __capacity__: _number_
- __remote_balance_sats__: _number_ - __closed_height__: _number_
### AppMetrics ### AppMetrics
- __app__: _[Application](#Application)_ - __app__: _[Application](#Application)_
@ -634,102 +713,6 @@ The nostr server will send back a message response, and inside the body there wi
- __total_fees__: _number_ - __total_fees__: _number_
- __operations__: ARRAY of: _[UserOperation](#UserOperation)_ - __operations__: ARRAY of: _[UserOperation](#UserOperation)_
### GetAppUserLNURLInfoRequest
- __user_identifier__: _string_
- __base_url_override__: _string_
### DecodeInvoiceRequest
- __invoice__: _string_
### ClosureMigration
- __closes_at_unix__: _number_
### LndGetInfoRequest
- __nodeId__: _number_
### ChainBalanceEvent
- __block_height__: _number_
- __confirmed_balance__: _number_
- __unconfirmed_balance__: _number_
- __total_balance__: _number_
### AuthApp
- __app__: _[Application](#Application)_
- __auth_token__: _string_
### EncryptionExchangeRequest
- __publicKey__: _string_
- __deviceId__: _string_
### AuthAppRequest
- __name__: _string_
- __allow_user_creation__: _boolean_ *this field is optional
### SendAppUserToAppPaymentRequest
- __from_user_identifier__: _string_
- __amount__: _number_
### LnurlWithdrawInfoResponse
- __tag__: _string_
- __callback__: _string_
- __k1__: _string_
- __defaultDescription__: _string_
- __minWithdrawable__: _number_
- __maxWithdrawable__: _number_
- __balanceCheck__: _string_
- __payLink__: _string_
### Product
- __id__: _string_
- __name__: _string_
- __price_sats__: _number_
### LndGetInfoResponse
- __alias__: _string_
### AddAppUserInvoiceRequest
- __receiver_identifier__: _string_
- __payer_identifier__: _string_
- __http_callback_url__: _string_
- __invoice_req__: _[NewInvoiceRequest](#NewInvoiceRequest)_
### SetMockAppBalanceRequest
- __amount__: _number_
### GetUserOperationsResponse
- __latestOutgoingInvoiceOperations__: _[UserOperations](#UserOperations)_
- __latestIncomingInvoiceOperations__: _[UserOperations](#UserOperations)_
- __latestOutgoingTxOperations__: _[UserOperations](#UserOperations)_
- __latestIncomingTxOperations__: _[UserOperations](#UserOperations)_
- __latestOutgoingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
- __latestIncomingUserToUserPayemnts__: _[UserOperations](#UserOperations)_
### UsageMetrics
- __metrics__: ARRAY of: _[UsageMetric](#UsageMetric)_
### PayAddressResponse
- __txId__: _string_
- __operation_id__: _string_
- __service_fee__: _number_
- __network_fee__: _number_
### OpenChannelResponse
- __channelId__: _string_
### NewAddressResponse
- __address__: _string_
### AddAppRequest
- __name__: _string_
- __allow_user_creation__: _boolean_
### SetMockAppUserBalanceRequest
- __user_identifier__: _string_
- __amount__: _number_
### DecodeInvoiceResponse
- __amount__: _number_
### LnurlPayInfoResponse ### LnurlPayInfoResponse
- __tag__: _string_ - __tag__: _string_
- __callback__: _string_ - __callback__: _string_
@ -739,18 +722,6 @@ The nostr server will send back a message response, and inside the body there wi
- __allowsNostr__: _boolean_ - __allowsNostr__: _boolean_
- __nostrPubkey__: _string_ - __nostrPubkey__: _string_
### UserInfo
- __userId__: _string_
- __balance__: _number_
- __max_withdrawable__: _number_
- __user_identifier__: _string_
### GetProductBuyLinkResponse
- __link__: _string_
### LiveUserOperation
- __operation__: _[UserOperation](#UserOperation)_
### AppsMetricsRequest ### AppsMetricsRequest
- __from_unix__: _number_ *this field is optional - __from_unix__: _number_ *this field is optional
- __to_unix__: _number_ *this field is optional - __to_unix__: _number_ *this field is optional
@ -759,14 +730,54 @@ The nostr server will send back a message response, and inside the body there wi
### NewInvoiceResponse ### NewInvoiceResponse
- __invoice__: _string_ - __invoice__: _string_
### MigrationUpdate ### UsageMetric
- __closure__: _[ClosureMigration](#ClosureMigration)_ *this field is optional - __processed_at_ms__: _number_
- __relays__: _[RelaysMigration](#RelaysMigration)_ *this field is optional - __parsed_in_nano__: _number_
- __auth_in_nano__: _number_
- __validate_in_nano__: _number_
- __handle_in_nano__: _number_
- __rpc_name__: _string_
- __batch__: _boolean_
- __nostr__: _boolean_
- __batch_size__: _number_
### ClosedChannel ### LndMetrics
- __nodes__: ARRAY of: _[LndNodeMetrics](#LndNodeMetrics)_
### LndGetInfoResponse
- __alias__: _string_
### LiveUserOperation
- __operation__: _[UserOperation](#UserOperation)_
### AuthAppRequest
- __name__: _string_
- __allow_user_creation__: _boolean_ *this field is optional
### AuthApp
- __app__: _[Application](#Application)_
- __auth_token__: _string_
### DecodeInvoiceRequest
- __invoice__: _string_
### HandleLnurlPayResponse
- __pr__: _string_
- __routes__: ARRAY of: _[Empty](#Empty)_
### Product
- __id__: _string_
- __name__: _string_
- __price_sats__: _number_
### UsageMetrics
- __metrics__: ARRAY of: _[UsageMetric](#UsageMetric)_
### ChannelBalanceEvent
- __block_height__: _number_
- __channel_id__: _string_ - __channel_id__: _string_
- __capacity__: _number_ - __local_balance_sats__: _number_
- __closed_height__: _number_ - __remote_balance_sats__: _number_
## Enums ## Enums
### The enumerators used in the messages ### The enumerators used in the messages

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -112,16 +112,28 @@ message ClosedChannel {
int64 closed_height =4; 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;
}
message LndNodeMetrics { message LndNodeMetrics {
repeated ChannelBalanceEvent channels_balance_events = 1; repeated ChannelBalanceEvent channels_balance_events = 1;
repeated ChainBalanceEvent chain_balance_events = 2; repeated ChainBalanceEvent chain_balance_events = 2;
repeated RoutingEvent routing_events = 3;
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;
} }
message LndMetrics { message LndMetrics {

View file

@ -35,6 +35,7 @@ export interface LightningHandler {
ListClosedChannels(): Promise<ClosedChannelsResponse> ListClosedChannels(): Promise<ClosedChannelsResponse>
ListChannels(): Promise<ListChannelsResponse> ListChannels(): Promise<ListChannelsResponse>
ListPendingChannels(): Promise<PendingChannelsResponse> ListPendingChannels(): Promise<PendingChannelsResponse>
GetForwardingHistory(indexOffset: number): Promise<{ fee: number, chanIdIn: string, chanIdOut: string, timestampNs: number, offset: number }[]>
} }
export default (settings: LndSettings, addressPaidCb: AddressPaidCb, invoicePaidCb: InvoicePaidCb, newBlockCb: NewBlockCb, htlcCb: HtlcCb): LightningHandler => { export default (settings: LndSettings, addressPaidCb: AddressPaidCb, invoicePaidCb: InvoicePaidCb, newBlockCb: NewBlockCb, htlcCb: HtlcCb): LightningHandler => {

View file

@ -311,6 +311,10 @@ export default class {
return { confirmedBalance: Number(confirmedBalance), unconfirmedBalance: Number(unconfirmedBalance), totalBalance: Number(totalBalance), channelsBalance } return { confirmedBalance: Number(confirmedBalance), unconfirmedBalance: Number(unconfirmedBalance), totalBalance: Number(totalBalance), channelsBalance }
} }
async GetForwardingHistory(indexOffset: number): Promise<{ fee: number, chanIdIn: string, chanIdOut: string, timestampNs: number, offset: number }[]> {
const { response } = await this.lightning.forwardingHistory({ indexOffset, numMaxEvents: 0, startTime: 0n, endTime: 0n, peerAliasLookup: false }, DeadLineMetadata())
return response.forwardingEvents.map(e => ({ fee: Number(e.fee), chanIdIn: e.chanIdIn, chanIdOut: e.chanIdOut, timestampNs: Number(e.timestampNs), offset: response.lastOffsetIndex }))
}
async OpenChannel(destination: string, closeAddress: string, fundingAmount: number, pushSats: number): Promise<string> { async OpenChannel(destination: string, closeAddress: string, fundingAmount: number, pushSats: number): Promise<string> {
await this.Health() await this.Health()

View file

@ -42,6 +42,7 @@ export default class {
async ListClosedChannels(): Promise<ClosedChannelsResponse> { throw new Error("ListClosedChannels disabled in mock mode") } async ListClosedChannels(): Promise<ClosedChannelsResponse> { throw new Error("ListClosedChannels disabled in mock mode") }
async ListChannels(): Promise<ListChannelsResponse> { throw new Error("ListChannels disabled in mock mode") } async ListChannels(): Promise<ListChannelsResponse> { throw new Error("ListChannels disabled in mock mode") }
async ListPendingChannels(): Promise<PendingChannelsResponse> { throw new Error("ListPendingChannels disabled in mock mode") } async ListPendingChannels(): Promise<PendingChannelsResponse> { throw new Error("ListPendingChannels disabled in mock mode") }
async GetForwardingHistory(indexOffset: number): Promise<{ fee: number, chanIdIn: string, chanIdOut: string, timestampNs: number, offset: number }[]> { throw new Error("GetForwardingHistory disabled in mock mode") }
async GetInfo(): Promise<NodeInfo> { async GetInfo(): Promise<NodeInfo> {
return { alias: "mock", syncedToChain: true, syncedToGraph: true, blockHeight: 1, blockHash: "" } return { alias: "mock", syncedToChain: true, syncedToGraph: true, blockHeight: 1, blockHash: "" }

View file

@ -32,12 +32,12 @@ export default class HtlcTracker {
case 'forwardEvent': case 'forwardEvent':
return this.handleForward(htlcEvent.forwardEvent, info) return this.handleForward(htlcEvent.forwardEvent, info)
case 'forwardFailEvent': case 'forwardFailEvent':
return this.handleFailure({ ...info, failureReason: 'forwardFailEvent' }) return this.handleFailure(info)
case 'linkFailEvent': case 'linkFailEvent':
return this.handleFailure({ ...info, failureReason: htlcEvent.linkFailEvent.failureString || 'linkFailEvent' }) return this.handleFailure(info)
case 'finalHtlcEvent': case 'finalHtlcEvent':
if (!htlcEvent.finalHtlcEvent.settled) { if (!htlcEvent.finalHtlcEvent.settled) {
return this.handleFailure({ ...info, failureReason: 'finalHtlcEvent' }) return this.handleFailure(info)
} else { } else {
return this.handleSuccess(info) return this.handleSuccess(info)
} }
@ -64,29 +64,29 @@ export default class HtlcTracker {
} }
} }
handleFailure = ({ eventType, outgoingHtlcId, incomingHtlcId, incomingChannelId, outgoingChannelId, failureReason }: EventInfo & { failureReason: string }) => { 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, failureReason) return this.incrementSendFailures(outgoingChannelId)
} }
if (eventType === HtlcEvent_EventType.RECEIVE && this.deleteMapEntry(incomingHtlcId, this.pendingReceiveHtlcs) !== null) { if (eventType === HtlcEvent_EventType.RECEIVE && this.deleteMapEntry(incomingHtlcId, this.pendingReceiveHtlcs) !== null) {
return this.incrementReceiveFailures(incomingChannelId, failureReason) return this.incrementReceiveFailures(incomingChannelId)
} }
if (eventType === HtlcEvent_EventType.FORWARD) { if (eventType === HtlcEvent_EventType.FORWARD) {
const amt = this.deleteMapEntry(outgoingHtlcId, this.pendingForwardHtlcs) const amt = this.deleteMapEntry(outgoingHtlcId, this.pendingForwardHtlcs)
if (amt !== null) { if (amt !== null) {
return this.incrementForwardFailures(incomingChannelId, outgoingChannelId, amt, failureReason) return this.incrementForwardFailures(incomingChannelId, outgoingChannelId, amt)
} }
} }
if (eventType === HtlcEvent_EventType.UNKNOWN) { if (eventType === HtlcEvent_EventType.UNKNOWN) {
const fwdAmt = this.deleteMapEntry(outgoingHtlcId, this.pendingForwardHtlcs) const fwdAmt = this.deleteMapEntry(outgoingHtlcId, this.pendingForwardHtlcs)
if (fwdAmt !== null) { if (fwdAmt !== null) {
return this.incrementForwardFailures(incomingChannelId, outgoingChannelId, fwdAmt, failureReason) return this.incrementForwardFailures(incomingChannelId, outgoingChannelId, fwdAmt)
} }
if (this.deleteMapEntry(outgoingHtlcId, this.pendingSendHtlcs) !== null) { if (this.deleteMapEntry(outgoingHtlcId, this.pendingSendHtlcs) !== null) {
return this.incrementSendFailures(outgoingChannelId, failureReason) return this.incrementSendFailures(outgoingChannelId)
} }
if (this.deleteMapEntry(incomingHtlcId, this.pendingReceiveHtlcs) !== null) { if (this.deleteMapEntry(incomingHtlcId, this.pendingReceiveHtlcs) !== null) {
return this.incrementReceiveFailures(incomingChannelId, failureReason) return this.incrementReceiveFailures(incomingChannelId)
} }
} }
this.log("unknown htlc event type for failure event") this.log("unknown htlc event type for failure event")
@ -117,37 +117,15 @@ export default class HtlcTracker {
return v || null return v || null
} }
incrementSendFailures = async (outgoingChannelId: number, reason: string) => { incrementSendFailures = async (outgoingChannelId: number) => {
await this.storage.metricsStorage.updateHtlcErrors(getToday(), d => { await this.storage.metricsStorage.IncrementChannelRouting(outgoingChannelId.toString(), { send_errors: 1 })
d.send_failures++
d.failed_destinations[outgoingChannelId] = (d.failed_destinations[outgoingChannelId] || 0) + 1
d.errors[reason] = (d.errors[reason] || 0) + 1
return d
})
} }
incrementReceiveFailures = async (incomingChannelId: number, reason: string) => { incrementReceiveFailures = async (incomingChannelId: number) => {
await this.storage.metricsStorage.updateHtlcErrors(getToday(), d => { await this.storage.metricsStorage.IncrementChannelRouting(incomingChannelId.toString(), { receive_errors: 1 })
d.receive_failures++
d.failed_sources[incomingChannelId] = (d.failed_sources[incomingChannelId] || 0) + 1
d.errors[reason] = (d.errors[reason] || 0) + 1
return d
})
} }
incrementForwardFailures = async (incomingChannelId: number, outgoingChannelId: number, amt: number, reason: string) => { incrementForwardFailures = async (incomingChannelId: number, outgoingChannelId: number, amt: number) => {
await this.storage.metricsStorage.updateHtlcErrors(getToday(), d => { await this.storage.metricsStorage.IncrementChannelRouting(incomingChannelId.toString(), { forward_errors_as_input: 1, missed_forward_fee_as_input: amt })
d.forward_failures++ await this.storage.metricsStorage.IncrementChannelRouting(outgoingChannelId.toString(), { forward_errors_as_output: 1, missed_forward_fee_as_output: amt })
d.forward_failures_amt += amt
d.failed_sources[incomingChannelId] = (d.failed_sources[incomingChannelId] || 0) + 1
d.failed_destinations[outgoingChannelId] = (d.failed_destinations[outgoingChannelId] || 0) + 1
d.errors[reason] = (d.errors[reason] || 0) + 1
return d
})
} }
} }
const getToday = () => {
const now = new Date()
return `${now.getFullYear()}-${z(now.getMonth() + 1)}-${z(now.getDate())}`
}
const z = (n: number) => n < 10 ? `0${n}` : `${n}`

View file

@ -2,7 +2,6 @@ import Storage from '../storage/index.js'
import * as Types from '../../../proto/autogenerated/ts/types.js' import * as Types from '../../../proto/autogenerated/ts/types.js'
import { Application } from '../storage/entity/Application.js' import { Application } from '../storage/entity/Application.js'
import { HtlcEvent, HtlcEvent_EventType } from '../../../proto/lnd/router.js' import { HtlcEvent, HtlcEvent_EventType } from '../../../proto/lnd/router.js'
import { RoutingEvent } from '../storage/entity/RoutingEvent.js'
import { BalanceInfo } from '../lnd/settings.js' import { BalanceInfo } from '../lnd/settings.js'
import { BalanceEvent } from '../storage/entity/BalanceEvent.js' import { BalanceEvent } from '../storage/entity/BalanceEvent.js'
import { ChannelBalanceEvent } from '../storage/entity/ChannelsBalanceEvent.js' import { ChannelBalanceEvent } from '../storage/entity/ChannelsBalanceEvent.js'
@ -39,6 +38,15 @@ export default class Handler {
await this.storage.metricsStorage.SaveBalanceEvents(balanceEvent, channelsEvents) await this.storage.metricsStorage.SaveBalanceEvents(balanceEvent, channelsEvents)
} }
async FetchLatestForwardingEvents() {
const latestIndex = await this.storage.metricsStorage.GetLatestForwardingIndexOffset()
const forwards = await this.lnd.GetForwardingHistory(latestIndex)
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 })
}))
}
AddMetrics(newMetrics: (Types.RequestMetric & { app_id?: string })[]) { AddMetrics(newMetrics: (Types.RequestMetric & { app_id?: string })[]) {
const parsed: Types.UsageMetric[] = newMetrics.map(m => ({ const parsed: Types.UsageMetric[] = newMetrics.map(m => ({
rpc_name: m.rpcName, rpc_name: m.rpcName,
@ -197,8 +205,31 @@ export default class Handler {
const { openChannels, totalActive, totalInactive } = await this.GetChannelsInfo() const { openChannels, totalActive, totalInactive } = await this.GetChannelsInfo()
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 routingEvents = await this.storage.metricsStorage.GetRoutingEvents({ from: req.from_unix, to: req.to_unix }) const routingMap: Record<string, Types.ChannelRouting> = {}
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,
}
}
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
})
const { channelsBalanceEvents, chainBalanceEvents } = await this.storage.metricsStorage.GetBalanceEvents({ from: req.from_unix, to: req.to_unix }) const { channelsBalanceEvents, chainBalanceEvents } = await this.storage.metricsStorage.GetBalanceEvents({ from: req.from_unix, to: req.to_unix })
return { return {
nodes: [{ nodes: [{
@ -214,26 +245,13 @@ export default class Handler {
local_balance_sats: e.local_balance_sats, local_balance_sats: e.local_balance_sats,
remote_balance_sats: e.remote_balance_sats remote_balance_sats: e.remote_balance_sats
})), })),
routing_events: routingEvents.map(e => ({
event_type: e.event_type,
failure_string: e.failure_string || "",
forward_fail_event: e.forward_fail_event || false,
incoming_amt_msat: e.incoming_amt_msat || 0,
incoming_channel_id: e.incoming_channel_id || 0,
incoming_htlc_id: e.incoming_htlc_id || 0,
offchain: e.offchain || false,
outgoing_amt_msat: e.outgoing_amt_msat || 0,
outgoing_channel_id: e.outgoing_channel_id,
outgoing_htlc_id: e.outgoing_htlc_id,
settled: e.settled || false,
timestamp_ns: e.timestamp_ns
})),
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)
}], }],
} }

View file

@ -13,12 +13,10 @@ import { Product } from "./entity/Product.js"
import { UserToUserPayment } from "./entity/UserToUserPayment.js" import { UserToUserPayment } from "./entity/UserToUserPayment.js"
import { Application } from "./entity/Application.js" import { Application } from "./entity/Application.js"
import { ApplicationUser } from "./entity/ApplicationUser.js" import { ApplicationUser } from "./entity/ApplicationUser.js"
import { RoutingEvent } from "./entity/RoutingEvent.js"
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 { getLogger } from "../helpers/logger.js" import { getLogger } from "../helpers/logger.js"
import { Initial1703170309875 } from "./migrations/1703170309875-initial.js" import { ChannelRouting } from "./entity/ChannelRouting.js"
import { LndMetrics1703170330183 } from "./migrations/1703170330183-lnd_metrics.js"
export type DbSettings = { export type DbSettings = {
@ -38,7 +36,7 @@ export const newMetricsDb = async (settings: DbSettings, metricsMigrations: Func
const source = await new DataSource({ const source = await new DataSource({
type: "sqlite", type: "sqlite",
database: settings.metricsDatabaseFile, database: settings.metricsDatabaseFile,
entities: [ RoutingEvent, BalanceEvent, ChannelBalanceEvent], entities: [BalanceEvent, ChannelBalanceEvent, ChannelRouting],
migrations: metricsMigrations migrations: metricsMigrations
}).initialize(); }).initialize();
const log = getLogger({}); const log = getLogger({});

View file

@ -0,0 +1,46 @@
import { Entity, PrimaryGeneratedColumn, Column, Index, Check, CreateDateColumn, UpdateDateColumn } from "typeorm"
@Entity()
export class ChannelRouting {
@PrimaryGeneratedColumn()
serial_id: number
@Column()
day_unix: number
@Column()
channel_id: string
@Column({ default: 0 })
send_errors: number
@Column({ default: 0 })
receive_errors: number
@Column({ default: 0 })
forward_errors_as_input: number
@Column({ default: 0 })
forward_errors_as_output: number
@Column({ default: 0 })
missed_forward_fee_as_input: number
@Column({ default: 0 })
missed_forward_fee_as_output: number
@Column({ default: 0 })
forward_fee_as_input: number
@Column({ default: 0 })
forward_fee_as_output: number
@Column({ default: 0 })
latest_index_offset: number
@CreateDateColumn()
created_at: Date
@UpdateDateColumn()
updated_at: Date
}

View file

@ -1,6 +0,0 @@
import { Entity, PrimaryGeneratedColumn, Column, Index, Check, CreateDateColumn, UpdateDateColumn } from "typeorm"
import { KVStorageBase } from "./KVStorageBase.js";
@Entity()
export class HtlcFailures extends KVStorageBase {
}

View file

@ -1,22 +0,0 @@
import { PrimaryGeneratedColumn, Column, Index, CreateDateColumn, UpdateDateColumn } from "typeorm"
export abstract class KVStorageBase {
@PrimaryGeneratedColumn()
serial_id: number
@Column()
@Index({ unique: true })
key: string
@Column({ type: 'simple-json' })
value: object
@Column()
version: number
@CreateDateColumn()
created_at: Date
@UpdateDateColumn()
updated_at: Date
}

View file

@ -1,49 +0,0 @@
import { Entity, PrimaryGeneratedColumn, Column, Index, Check, CreateDateColumn, UpdateDateColumn } from "typeorm"
@Entity()
export class RoutingEvent {
@PrimaryGeneratedColumn()
serial_id: number
@Column()
incoming_channel_id: number
@Column()
incoming_htlc_id: number
@Column()
outgoing_channel_id: number
@Column()
outgoing_htlc_id: number
@Column()
timestamp_ns: number
@Column()
event_type: string
@Column({ nullable: true })
incoming_amt_msat?: number
@Column({ nullable: true })
outgoing_amt_msat?: number
@Column({ nullable: true })
failure_string?: string
@Column({ nullable: true })
settled?: boolean
@Column({ nullable: true })
offchain?: boolean
@Column({ nullable: true })
forward_fail_event?: boolean
@CreateDateColumn()
created_at: Date
@UpdateDateColumn()
updated_at: Date
}

View file

@ -1,12 +1,12 @@
import { Between, DataSource, EntityManager, FindOperator, LessThanOrEqual, MoreThanOrEqual } from "typeorm" import { Between, DataSource, EntityManager, FindOperator, LessThanOrEqual, MoreThanOrEqual } from "typeorm"
import { RoutingEvent } from "./entity/RoutingEvent.js"
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";
import { StorageSettings } from "./index.js"; import { StorageSettings } from "./index.js";
import { newMetricsDb } from "./db.js"; import { newMetricsDb } from "./db.js";
import { HtlcFailures } from "./entity/HtlcFailures.js"; import { ChannelRouting } from "./entity/ChannelRouting.js";
export default class { export default class {
DB: DataSource | EntityManager DB: DataSource | EntityManager
settings: StorageSettings settings: StorageSettings
txQueue: TransactionsQueue txQueue: TransactionsQueue
@ -19,10 +19,6 @@ export default class {
this.txQueue = new TransactionsQueue("metrics", this.DB) this.txQueue = new TransactionsQueue("metrics", this.DB)
return executedMigrations; return executedMigrations;
} }
async SaveRoutingEvent(event: Partial<RoutingEvent>) {
const entry = this.DB.getRepository(RoutingEvent).create(event)
return this.txQueue.PushToQueue<RoutingEvent>({ exec: async db => db.getRepository(RoutingEvent).save(entry), dbTx: false })
}
async SaveBalanceEvents(balanceEvent: Partial<BalanceEvent>, channelBalanceEvents: Partial<ChannelBalanceEvent>[]) { async SaveBalanceEvents(balanceEvent: Partial<BalanceEvent>, channelBalanceEvents: Partial<ChannelBalanceEvent>[]) {
const blanceEventEntry = this.DB.getRepository(BalanceEvent).create(balanceEvent) const blanceEventEntry = this.DB.getRepository(BalanceEvent).create(balanceEvent)
@ -33,27 +29,8 @@ export default class {
return { balanceEntry, channelsEntries } return { balanceEntry, channelsEntries }
} }
async GetRoutingEvents({ from, to }: { from?: number, to?: number }, entityManager = this.DB) {
let q: { where: { created_at: FindOperator<Date> } } | {} = {}
if (!!from && !!to) {
q = { where: { created_at: Between<Date>(new Date(from * 1000), new Date(to * 1000)) } }
} else if (!!from) {
q = { where: { created_at: MoreThanOrEqual<Date>(new Date(from * 1000)) } }
} else if (!!to) {
q = { where: { created_at: LessThanOrEqual<Date>(new Date(to * 1000)) } }
}
return entityManager.getRepository(RoutingEvent).find(q)
}
async GetBalanceEvents({ from, to }: { from?: number, to?: number }, entityManager = this.DB) { async GetBalanceEvents({ from, to }: { from?: number, to?: number }, entityManager = this.DB) {
let q: { where: { created_at: FindOperator<Date> } } | {} = {} const q = getTimeQuery({ from, to })
if (!!from && !!to) {
q = { where: { created_at: Between<Date>(new Date(from * 1000), new Date(to * 1000)) } }
} else if (!!from) {
q = { where: { created_at: MoreThanOrEqual<Date>(new Date(from * 1000)) } }
} else if (!!to) {
q = { where: { created_at: LessThanOrEqual<Date>(new Date(to * 1000)) } }
}
const [chainBalanceEvents, channelsBalanceEvents] = await Promise.all([ const [chainBalanceEvents, channelsBalanceEvents] = await Promise.all([
entityManager.getRepository(BalanceEvent).find(q), entityManager.getRepository(BalanceEvent).find(q),
@ -62,35 +39,76 @@ export default class {
return { chainBalanceEvents, channelsBalanceEvents } return { chainBalanceEvents, channelsBalanceEvents }
} }
updateHtlcErrors = async (key: string, update: (d: TMPHtlcFailureData) => TMPHtlcFailureData, entityManager = this.DB) => { async initChannelRoutingEvent(dayUnix: number, channelId: string) {
const existing = await entityManager.getRepository(HtlcFailures).findOne({ where: { key } }) const existing = await this.DB.getRepository(ChannelRouting).findOne({ where: { day_unix: dayUnix, channel_id: channelId } })
if (existing) { if (!existing) {
const data = update(existing.value as TMPHtlcFailureData) const entry = this.DB.getRepository(ChannelRouting).create({ day_unix: dayUnix, channel_id: channelId })
await entityManager.getRepository(HtlcFailures).update({ key }, { value: data }) return this.txQueue.PushToQueue<ChannelRouting>({ exec: async db => db.getRepository(ChannelRouting).save(entry), dbTx: false })
return
} }
const data = update(newTMPHtlcFailureData()) return existing
await this.txQueue.PushToQueue<HtlcFailures>({ exec: async db => db.getRepository(HtlcFailures).save({ key, value: data }), dbTx: false }) }
GetChannelRouting({ from, to }: { from?: number, to?: number }, entityManager = this.DB) {
const q = getTimeQuery({ from, to })
return entityManager.getRepository(ChannelRouting).find(q)
} }
}
const newTMPHtlcFailureData = () => { async GetLatestForwardingIndexOffset() {
return { const latestIndex = await this.DB.getRepository(ChannelRouting).findOne({ order: { latest_index_offset: "DESC" } })
send_failures: 0, if (latestIndex) {
receive_failures: 0, return latestIndex.latest_index_offset
forward_failures: 0, }
forward_failures_amt: 0, return 0
failed_sources: {},
failed_destinations: {},
errors: {}
} }
async IncrementChannelRouting(channelId: string, event: Partial<ChannelRouting>) {
const dayUnix = getTodayUnix()
const existing = await this.initChannelRoutingEvent(dayUnix, channelId)
const repo = this.DB.getRepository(ChannelRouting)
if (event.send_errors) {
await repo.increment({ day_unix: dayUnix, channel_id: channelId }, "send_errors", event.send_errors)
}
if (event.receive_errors) {
await repo.increment({ day_unix: dayUnix, channel_id: channelId }, "receive_errors", event.receive_errors)
}
if (event.forward_errors_as_input) {
await repo.increment({ day_unix: dayUnix, channel_id: channelId }, "forwar_errors_as_input", event.forward_errors_as_input)
}
if (event.forward_errors_as_output) {
await repo.increment({ day_unix: dayUnix, channel_id: channelId }, "forwar_errors_as_output", event.forward_errors_as_output)
}
if (event.missed_forward_fee_as_input) {
await repo.increment({ day_unix: dayUnix, channel_id: channelId }, "missed_forward_fee_as_input", event.missed_forward_fee_as_input)
}
if (event.missed_forward_fee_as_output) {
await repo.increment({ day_unix: dayUnix, channel_id: channelId }, "missed_forward_fee_as_output", event.missed_forward_fee_as_output)
}
if (event.forward_fee_as_input) {
await repo.increment({ day_unix: dayUnix, channel_id: channelId }, "forward_fee_as_input", event.forward_fee_as_input)
}
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.latest_index_offset) {
await repo.update(existing.serial_id, { latest_index_offset: event.latest_index_offset })
}
}
} }
type TMPHtlcFailureData = { // TODO: move to a file with versions and stuff
send_failures: number const getTimeQuery = ({ from, to }: { from?: number, to?: number }) => {
receive_failures: number if (!!from && !!to) {
forward_failures: number return { where: { created_at: Between<Date>(new Date(from * 1000), new Date(to * 1000)) } }
forward_failures_amt: number } else if (!!from) {
failed_sources: Record<number, number> return { where: { created_at: MoreThanOrEqual<Date>(new Date(from * 1000)) } }
failed_destinations: Record<number, number> } else if (!!to) {
errors: Record<string, number> return { where: { created_at: LessThanOrEqual<Date>(new Date(to * 1000)) } }
}
return {}
}
const getTodayUnix = () => {
const now = new Date()
return new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime() / 1000
} }

View file

@ -1,16 +0,0 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class HtlcErrors1709149327598 implements MigrationInterface {
name = 'HtlcErrors1709149327598'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "htlc_failures" ("serial_id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "key" varchar NOT NULL, "value" text NOT NULL, "version" integer NOT NULL, "created_at" datetime NOT NULL DEFAULT (datetime('now')), "updated_at" datetime NOT NULL DEFAULT (datetime('now')))`);
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_40f71cd66bed693e826d91d438" ON "htlc_failures" ("key") `);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX "IDX_40f71cd66bed693e826d91d438"`);
await queryRunner.query(`DROP TABLE "htlc_failures"`);
}
}

View file

@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class ChannelRouting1709316653538 implements MigrationInterface {
name = 'ChannelRouting1709316653538'
public async up(queryRunner: QueryRunner): Promise<void> {
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')))`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "channel_routing"`);
}
}

View file

@ -3,8 +3,8 @@ import { DbSettings } from '../db.js'
import Storage, { StorageSettings } from '../index.js' import Storage, { StorageSettings } from '../index.js'
import { Initial1703170309875 } from './1703170309875-initial.js' import { Initial1703170309875 } from './1703170309875-initial.js'
import { LndMetrics1703170330183 } from './1703170330183-lnd_metrics.js' import { LndMetrics1703170330183 } from './1703170330183-lnd_metrics.js'
import { HtlcErrors1709149327598 } from './1709149327598-htlc_errors.js' import { ChannelRouting1709316653538 } from './1709316653538-channel_routing.js'
const allMigrations = [LndMetrics1703170330183, HtlcErrors1709149327598] const allMigrations = [LndMetrics1703170330183, ChannelRouting1709316653538]
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 === 'initial_migration') { if (arg === 'initial_migration') {
await connectAndMigrate(log, storageManager, true, settings, [Initial1703170309875], []) await connectAndMigrate(log, storageManager, true, settings, [Initial1703170309875], [])
@ -12,8 +12,8 @@ export const TypeOrmMigrationRunner = async (log: PubLogger, storageManager: Sto
} else if (arg === 'lnd_metrics_migration') { } else if (arg === 'lnd_metrics_migration') {
await connectAndMigrate(log, storageManager, true, settings, [], [LndMetrics1703170330183]) await connectAndMigrate(log, storageManager, true, settings, [], [LndMetrics1703170330183])
return true return true
} else if (arg === 'htlc_errors_migration') { } else if (arg === 'channel_routing_migration') {
await connectAndMigrate(log, storageManager, true, settings, [], [HtlcErrors1709149327598]) await connectAndMigrate(log, storageManager, true, settings, [], [ChannelRouting1709316653538])
return true return true
} else if (arg === 'all_migrations') { } else if (arg === 'all_migrations') {
await connectAndMigrate(log, storageManager, true, settings, [], allMigrations) await connectAndMigrate(log, storageManager, true, settings, [], allMigrations)
@ -40,7 +40,7 @@ const connectAndMigrate = async (log: PubLogger, storageManager: Storage, manual
log("-------------------") log("-------------------")
} if (metricsMigrations.length > 0) { } if (metricsMigrations.length > 0) {
log(executedMetricsMigrations.length, "of", migrations.length, "metrics migrations were executed correctly") log(executedMetricsMigrations.length, "of", metricsMigrations.length, "metrics migrations were executed correctly")
log(executedMetricsMigrations) log(executedMetricsMigrations)
} }