From fa7b13c9142d64086d0f9edda9eb904e47295ae4 Mon Sep 17 00:00:00 2001 From: Daniel McNally Date: Wed, 10 Jun 2020 14:12:06 -0400 Subject: [PATCH 1/4] feat(lnd): log htlc acceptance --- lib/lndclient/LndClient.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/lndclient/LndClient.ts b/lib/lndclient/LndClient.ts index 739e2a32a..22bec39c0 100644 --- a/lib/lndclient/LndClient.ts +++ b/lib/lndclient/LndClient.ts @@ -1006,6 +1006,7 @@ class LndClient extends SwapClient { invoiceSubscription.on('data', (invoice: lndrpc.Invoice) => { if (invoice.getState() === lndrpc.Invoice.InvoiceState.ACCEPTED) { // we have accepted an htlc for this invoice + this.logger.debug(`accepted htlc for invoice ${rHash}`); this.emit('htlcAccepted', rHash, invoice.getValue()); } }).on('end', deleteInvoiceSubscription).on('error', deleteInvoiceSubscription); From 2df88c5bd30b9dea5ee984730b592d71f30a8995 Mon Sep 17 00:00:00 2001 From: Daniel McNally Date: Wed, 10 Jun 2020 14:12:39 -0400 Subject: [PATCH 2/4] feat(backup): change log level debug to trace This is done to reduce the verbosity of the logs in debug mode as the backup logic will log multiple statements for every operation affecting channels or databases such as a swap. --- lib/backup/Backup.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/backup/Backup.ts b/lib/backup/Backup.ts index af5573dae..717aa882c 100644 --- a/lib/backup/Backup.ts +++ b/lib/backup/Backup.ts @@ -117,7 +117,7 @@ class Backup extends EventEmitter { this.logger.info(`Listening to ${currency} LND channel backups`); lndClient.on('channelBackup', (channelBackup) => { - this.logger.debug(`New ${lndClient.currency} channel backup`); + this.logger.trace(`New ${lndClient.currency} channel backup`); this.writeBackup(backupPath, channelBackup); }); lndClient.on('channelBackupEnd', async () => { @@ -169,7 +169,7 @@ class Backup extends EventEmitter { // Compare the MD5 hash of the current content of the file with hash of the content when // it was backed up the last time to ensure that the content of the file has changed if (hash !== previousDatabaseHash) { - this.logger.debug(`${client} database changed`); + this.logger.trace(`${client} database changed`); previousDatabaseHash = hash; this.writeBackup(backupPath, content); From 704072e668f1737479617bad7b1db3478ff6e67f Mon Sep 17 00:00:00 2001 From: Daniel McNally Date: Wed, 10 Jun 2020 14:24:17 -0400 Subject: [PATCH 3/4] feat: improve open channel fail logging --- lib/service/Service.ts | 2 +- lib/service/errors.ts | 15 +++++++++++---- test/jest/__snapshots__/Service.spec.ts.snap | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/service/Service.ts b/lib/service/Service.ts index fa6ea5f1e..8d9f0a3e2 100644 --- a/lib/service/Service.ts +++ b/lib/service/Service.ts @@ -287,7 +287,7 @@ class Service { }); } catch (e) { const errorMessage = e.message || 'unknown'; - throw errors.OPEN_CHANNEL_FAILURE(currency, nodeIdentifier, amount, errorMessage); + throw errors.OPEN_CHANNEL_FAILURE(currency, amount, errorMessage, nodeIdentifier); } } diff --git a/lib/service/errors.ts b/lib/service/errors.ts index 7441bf667..52982bc67 100644 --- a/lib/service/errors.ts +++ b/lib/service/errors.ts @@ -28,10 +28,17 @@ const errors = { message: 'a pending call is ongoing that conflicts with this call', code: errorCodes.PENDING_CALL_CONFLICT, }, - OPEN_CHANNEL_FAILURE: (currency: string, nodePubKey: string, amount: number, message: string) => ({ - message: `failed to open channel with nodePubKey: ${nodePubKey}, currency: ${currency}, amount: ${amount}, message: ${message}`, - code: errorCodes.OPEN_CHANNEL_FAILURE, - }), + OPEN_CHANNEL_FAILURE: (currency: string, amount: number, errorMessage: string, nodeIdentifier?: string) => { + let message = `failed to open ${currency} channel for ${amount}`; + if (nodeIdentifier) { + message += ` with ${nodeIdentifier}`; + } + message += `: ${errorMessage}`; + return { + message, + code: errorCodes.OPEN_CHANNEL_FAILURE, + }; + }, NODE_DOES_NOT_EXIST: { message: 'xud node cannot be unlocked because it does not exist', code: errorCodes.NODE_DOES_NOT_EXIST, diff --git a/test/jest/__snapshots__/Service.spec.ts.snap b/test/jest/__snapshots__/Service.spec.ts.snap index 9793b3f6f..e01d0f533 100644 --- a/test/jest/__snapshots__/Service.spec.ts.snap +++ b/test/jest/__snapshots__/Service.spec.ts.snap @@ -17,14 +17,14 @@ Object { exports[`Service openChannel throws when failure from swapClientManager 1`] = ` Object { "code": "6.5", - "message": "failed to open channel with nodePubKey: 02f8895eb03c37b2665415be4d83b20228acc0abc55ebf6728565141c66cfc164a, currency: BTC, amount: 16000000, message: swapClientManager openChannel failure", + "message": "failed to open BTC channel for 16000000 with 02f8895eb03c37b2665415be4d83b20228acc0abc55ebf6728565141c66cfc164a: swapClientManager openChannel failure", } `; exports[`Service openChannel throws when peer not found 1`] = ` Object { "code": "6.5", - "message": "failed to open channel with nodePubKey: 02f8895eb03c37b2665415be4d83b20228acc0abc55ebf6728565141c66cfc164a, currency: BTC, amount: 16000000, message: peer not found", + "message": "failed to open BTC channel for 16000000 with 02f8895eb03c37b2665415be4d83b20228acc0abc55ebf6728565141c66cfc164a: peer not found", } `; From 03416860f49a7ab122a9c23e88b444acd1b5785a Mon Sep 17 00:00:00 2001 From: Daniel McNally Date: Thu, 11 Jun 2020 14:15:48 -0400 Subject: [PATCH 4/4] refactor: log lnd settleInvoice call up front --- lib/lndclient/LndClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lndclient/LndClient.ts b/lib/lndclient/LndClient.ts index 22bec39c0..d332f8c00 100644 --- a/lib/lndclient/LndClient.ts +++ b/lib/lndclient/LndClient.ts @@ -902,13 +902,13 @@ class LndClient extends SwapClient { } public settleInvoice = async (rHash: string, rPreimage: string) => { + this.logger.debug(`settling invoice for ${rHash}`); const settleInvoiceRequest = new lndinvoices.SettleInvoiceMsg(); settleInvoiceRequest.setPreimage(hexToUint8Array(rPreimage)); await this.settleInvoiceLnd(settleInvoiceRequest); const invoiceSubscription = this.invoiceSubscriptions.get(rHash); if (invoiceSubscription) { - this.logger.debug(`settled invoice for ${rHash}`); invoiceSubscription.cancel(); } }