Unverified Commit 395f37f2 authored by Tankred Hase's avatar Tankred Hase Committed by GitHub

Merge pull request #909 from lightninglabs/remote-lnd

Enable users to connect to a remote lnd node.
parents ce9929e0 641c0bdc
......@@ -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:
......
......@@ -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,
......@@ -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.
......@@ -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 {
......@@ -199,7 +210,7 @@ app.on('ready', () => {
initAutoUpdate();
createWindow();
initApplicationMenu();
startLnd();
if (!lndIP) startLnd();
});
// Quit when all windows are closed.
......
......@@ -48,6 +48,7 @@ function getMacaroonCreds(lndSettingsDir, network) {
module.exports.init = async function({
ipcMain,
lndIP = 'localhost',
lndPort,
lndSettingsDir,
network,
......@@ -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 });
});
......@@ -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 });
});
......
/**
* 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;
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment