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): don't default lnd clients as disabled #692

Merged
merged 1 commit into from
Nov 19, 2018
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
3 changes: 2 additions & 1 deletion lib/BaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Logger from './Logger';
import { EventEmitter } from 'events';

enum ClientStatus {
NotInitialized,
Disabled,
Disconnected,
ConnectionVerified,
Expand All @@ -12,7 +13,7 @@ enum ClientStatus {
* A base class to represent a client for an external service such as LND or Raiden.
*/
abstract class BaseClient extends EventEmitter {
protected status: ClientStatus = ClientStatus.Disabled;
protected status: ClientStatus = ClientStatus.NotInitialized;

constructor(protected logger: Logger) {
super();
Expand Down
10 changes: 3 additions & 7 deletions lib/Xud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,11 @@ class Xud extends EventEmitter {
this.db = new DB(loggers.db, this.config.dbpath);
await this.db.init(this.config.initdb);

// setup LND clients and connect if configured
// setup LND clients and initialize
this.lndbtcClient = new LndClient(this.config.lndbtc, loggers.lnd);
if (!this.lndbtcClient.isDisabled()) {
initPromises.push(this.lndbtcClient.init());
}
initPromises.push(this.lndbtcClient.init());
this.lndltcClient = new LndClient(this.config.lndltc, loggers.lnd);
if (!this.lndltcClient.isDisabled()) {
initPromises.push(this.lndltcClient.init());
}
initPromises.push(this.lndltcClient.init());

// setup raiden client and connect if configured
this.raidenClient = new RaidenClient(this.config.raiden, loggers.raiden);
Expand Down
43 changes: 21 additions & 22 deletions lib/lndclient/LndClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,37 +72,36 @@ class LndClient extends BaseClient {

/** Initializes the client for calls to lnd and verifies that we can connect to it. */
public init = async () => {
let shouldEnable = true;
const { disable, certpath, macaroonpath, nomacaroons, host, port } = this.config;
let shouldDisable = disable;

if (disable) {
shouldEnable = false;
}
if (!(await exists(certpath))) {
this.logger.error('could not find lnd certificate, is lnd installed?');
shouldEnable = false;
shouldDisable = true;
}
if (!nomacaroons && !(await exists(macaroonpath))) {
this.logger.error('could not find lnd macaroon, is lnd installed?');
shouldEnable = false;
shouldDisable = true;
}
if (shouldEnable) {
assert(this.cltvDelta > 0, 'cltvdelta must be a positive number');
this.uri = `${host}:${port}`;
const lndCert = await readFile(certpath);
this.credentials = grpc.credentials.createSsl(lndCert);

this.meta = new grpc.Metadata();
if (!nomacaroons) {
const adminMacaroon = await readFile(macaroonpath);
this.meta.add('macaroon', adminMacaroon.toString('hex'));
} else {
this.logger.info(`macaroons are disabled for lnd at ${this.uri}`);
}
// set status as disconnected until we can verify the connection
this.setStatus(ClientStatus.Disconnected);
await this.verifyConnection();
if (shouldDisable) {
return;
}

assert(this.cltvDelta > 0, 'cltvdelta must be a positive number');
this.uri = `${host}:${port}`;
const lndCert = await readFile(certpath);
this.credentials = grpc.credentials.createSsl(lndCert);

this.meta = new grpc.Metadata();
if (!nomacaroons) {
const adminMacaroon = await readFile(macaroonpath);
this.meta.add('macaroon', adminMacaroon.toString('hex'));
} else {
this.logger.info(`macaroons are disabled for lnd at ${this.uri}`);
}
// set status as disconnected until we can verify the connection
this.setStatus(ClientStatus.Disconnected);
return this.verifyConnection();
}

public get pubKey() {
Expand Down
4 changes: 2 additions & 2 deletions lib/raidenclient/RaidenClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ class RaidenClient extends BaseClient {
this.port = port;
this.host = host;

if (!disable) {
this.setStatus(ClientStatus.Disconnected);
if (disable) {
this.setStatus(ClientStatus.Disabled);
}
}

Expand Down