Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging improvements #1630

Merged
merged 4 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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