Skip to content

Commit

Permalink
Merge pull request #1630 from ExchangeUnion/logging-improvements
Browse files Browse the repository at this point in the history
Logging improvements
  • Loading branch information
sangaman authored Jun 11, 2020
2 parents 43c03e7 + 0341686 commit fca4960
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/backup/Backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion lib/lndclient/LndClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/service/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
15 changes: 11 additions & 4 deletions lib/service/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions test/jest/__snapshots__/Service.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
`;

Expand Down

0 comments on commit fca4960

Please sign in to comment.