Skip to content
This repository has been archived by the owner on Feb 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #909 from lightninglabs/remote-lnd
Browse files Browse the repository at this point in the history
Enable users to connect to a remote lnd node.
  • Loading branch information
tanx authored Feb 7, 2019
2 parents ce9929e + 641c0bd commit 395f37f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ To run the packaged version of the app e.g. for macOS run:
./dist/mac/Lightning.app/Contents/MacOS/Lightning --bitcoin.node=bitcoind --bitcoind.rpcuser=kek --bitcoind.rpcpass=kek --bitcoind.zmqpubrawblock=tcp://127.0.0.1:28332 --bitcoind.zmqpubrawtx=tcp://127.0.0.1:28333
```

### Connect to a remote lnd node
1. In your remote node's `lnd.conf`, set `rpclisten=0.0.0.0:10006` and `tlsextraip=<insert your node's IP address here>`, then restart the node.

2. Copy the `tls.cert` and `tls.key` from your remote node's `.lnd` into the appropriate folder for your platform (specified in the section below).

3. Copy `admin.macaroon` from the remote node into `lnd/data/chain/bitcoin/<network>` (in the same folder you put the `tls` files).

4. When starting the app, add the flag `--lndip=<your remote node's IP address>`. Note that the node must be locked when the app connects to it.

### Lnd data and logs
Lnd data and logs are written to the following locations in production:

Expand Down
13 changes: 12 additions & 1 deletion public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const url = require('url');
const isDev = require('electron-is-dev');
const log = require('electron-log');
const { startLndProcess, startBtcdProcess } = require('./lnd-child-process');
const { parseCliArg } = require('./helper');
const grcpClient = require('./grpc-client');
const {
PREFIX_NAME,
Expand Down Expand Up @@ -37,6 +38,7 @@ const btcdSettingsDir = path.join(isDev ? 'data' : userDataPath, 'btcd');
const lndArgs = process.argv.filter(a =>
/(^--bitcoin)|(^--btcd)|(^--neutrino)/.test(a)
);
let lndIP = parseCliArg('lndip');

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
Expand Down Expand Up @@ -125,12 +127,21 @@ function createWindow() {
grcpClient.init({
ipcMain,
lndSettingsDir,
lndIP,
lndPort: LND_PORT,
network: isDev ? 'simnet' : NETWORK,
});
}

ipcMain.on('lnd-restart-process', async event => {
if (lndIP) {
event.sender.send(
'lnd-restart-error',
'Unable to reset password of remote lnd node.'
);
return;
}

lndProcess && lndProcess.kill('SIGINT');
let restartError;
try {
Expand Down Expand Up @@ -199,7 +210,7 @@ app.on('ready', () => {
initAutoUpdate();
createWindow();
initApplicationMenu();
startLnd();
if (!lndIP) startLnd();
});

// Quit when all windows are closed.
Expand Down
5 changes: 3 additions & 2 deletions public/grpc-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function getMacaroonCreds(lndSettingsDir, network) {

module.exports.init = async function({
ipcMain,
lndIP = 'localhost',
lndPort,
lndSettingsDir,
network,
Expand All @@ -70,7 +71,7 @@ module.exports.init = async function({
};
const packageDef = protoLoader.loadSync(protoPath, options);
lnrpc = grpc.loadPackageDefinition(packageDef).lnrpc;
unlocker = new lnrpc.WalletUnlocker(`localhost:${lndPort}`, credentials);
unlocker = new lnrpc.WalletUnlocker(`${lndIP}:${lndPort}`, credentials);
grpc.waitForClientReady(unlocker, Infinity, err => {
event.sender.send('unlockReady', { err });
});
Expand All @@ -87,7 +88,7 @@ module.exports.init = async function({
credentials,
macaroonCreds
);
lnd = new lnrpc.Lightning(`localhost:${lndPort}`, credentials);
lnd = new lnrpc.Lightning(`${lndIP}:${lndPort}`, credentials);
grpc.waitForClientReady(lnd, Infinity, err => {
event.sender.send('lndReady', { err });
});
Expand Down
18 changes: 18 additions & 0 deletions public/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Parse a list of CLI arguments searching for a target argument.
* @param {string} target The target argument we're searching for.
* @return {string|undefined} The target argument's value, or undefined.
*/
module.exports.parseCliArg = function(target) {
let regex = new RegExp('--' + target);
let value;
process.argv.filter(a => {
if (regex.test(a)) {
let split = a.split('=');
if (split.length > 1) {
value = split[1];
}
}
});
return value;
};

0 comments on commit 395f37f

Please sign in to comment.