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

fix(lnd): handling hold invoice check errors #1969

Merged
merged 1 commit into from
Nov 9, 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
23 changes: 13 additions & 10 deletions lib/lndclient/LndClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,12 @@ class LndClient extends SwapClient {
this.setStatus(ClientStatus.Misconfigured);
}

if (this.walletUnlocker) {
// WalletUnlocker service is disabled when the main Lightning service is available
this.walletUnlocker.close();
this.walletUnlocker = undefined;
}

this.invoices = new InvoicesClient(this.uri, this.credentials);
try {
const randomHash = crypto.randomBytes(32).toString('hex');
Expand All @@ -501,16 +507,13 @@ class LndClient extends SwapClient {
await this.addInvoice({ rHash: randomHash, units: 1 });
await this.removeInvoice(randomHash);
} catch (err) {
const errStr = typeof(err) === 'string' ? err : JSON.stringify(err);

this.logger.error(`could not add hold invoice, error: ${errStr}`);
this.setStatus(ClientStatus.NoHoldInvoiceSupport);
}

if (this.walletUnlocker) {
// WalletUnlocker service is disabled when the main Lightning service is available
this.walletUnlocker.close();
this.walletUnlocker = undefined;
if (err.code !== grpc.status.UNAVAILABLE) {
// mark the client as not having hold invoice support if the invoice calls failed due to
// reasons other than generic grpc connectivity errors
this.logger.error('could not add hold invoice', err);
this.setStatus(ClientStatus.NoHoldInvoiceSupport);
}
throw err; // we don't want to proceed with marking the client as connected, regardless of the error
}

await this.setConnected(newPubKey, newUris);
Expand Down
4 changes: 2 additions & 2 deletions lib/swaps/SwapClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ abstract class SwapClient extends EventEmitter {
case ClientStatus.WaitingUnlock:
case ClientStatus.OutOfSync:
case ClientStatus.NoHoldInvoiceSupport:
// these statuses can only be set on an operational, initalized client
// these statuses can only be set on an operational, initialized client
validStatusTransition = this.isOperational();
break;
case ClientStatus.NotInitialized:
Expand Down Expand Up @@ -349,7 +349,7 @@ abstract class SwapClient extends EventEmitter {
* Returns `true` if the client is enabled and configured properly.
*/
public isOperational(): boolean {
return !this.isDisabled() && !this.isMisconfigured() && !this.isNotInitialized() && !this.hasNoInvoiceSupport();
return !this.isDisabled() && !this.isMisconfigured() && !this.isNotInitialized();
}
public isDisconnected(): boolean {
return this.status === ClientStatus.Disconnected;
Expand Down