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

Commit 395f37f

Browse files
authored
Merge pull request #909 from lightninglabs/remote-lnd
Enable users to connect to a remote lnd node.
2 parents ce9929e + 641c0bd commit 395f37f

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ To run the packaged version of the app e.g. for macOS run:
9898
./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
9999
```
100100

101+
### Connect to a remote lnd node
102+
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.
103+
104+
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).
105+
106+
3. Copy `admin.macaroon` from the remote node into `lnd/data/chain/bitcoin/<network>` (in the same folder you put the `tls` files).
107+
108+
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.
109+
101110
### Lnd data and logs
102111
Lnd data and logs are written to the following locations in production:
103112

public/electron.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const url = require('url');
66
const isDev = require('electron-is-dev');
77
const log = require('electron-log');
88
const { startLndProcess, startBtcdProcess } = require('./lnd-child-process');
9+
const { parseCliArg } = require('./helper');
910
const grcpClient = require('./grpc-client');
1011
const {
1112
PREFIX_NAME,
@@ -37,6 +38,7 @@ const btcdSettingsDir = path.join(isDev ? 'data' : userDataPath, 'btcd');
3738
const lndArgs = process.argv.filter(a =>
3839
/(^--bitcoin)|(^--btcd)|(^--neutrino)/.test(a)
3940
);
41+
let lndIP = parseCliArg('lndip');
4042

4143
// Keep a global reference of the window object, if you don't, the window will
4244
// be closed automatically when the JavaScript object is garbage collected.
@@ -125,12 +127,21 @@ function createWindow() {
125127
grcpClient.init({
126128
ipcMain,
127129
lndSettingsDir,
130+
lndIP,
128131
lndPort: LND_PORT,
129132
network: isDev ? 'simnet' : NETWORK,
130133
});
131134
}
132135

133136
ipcMain.on('lnd-restart-process', async event => {
137+
if (lndIP) {
138+
event.sender.send(
139+
'lnd-restart-error',
140+
'Unable to reset password of remote lnd node.'
141+
);
142+
return;
143+
}
144+
134145
lndProcess && lndProcess.kill('SIGINT');
135146
let restartError;
136147
try {
@@ -199,7 +210,7 @@ app.on('ready', () => {
199210
initAutoUpdate();
200211
createWindow();
201212
initApplicationMenu();
202-
startLnd();
213+
if (!lndIP) startLnd();
203214
});
204215

205216
// Quit when all windows are closed.

public/grpc-client.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function getMacaroonCreds(lndSettingsDir, network) {
4848

4949
module.exports.init = async function({
5050
ipcMain,
51+
lndIP = 'localhost',
5152
lndPort,
5253
lndSettingsDir,
5354
network,
@@ -70,7 +71,7 @@ module.exports.init = async function({
7071
};
7172
const packageDef = protoLoader.loadSync(protoPath, options);
7273
lnrpc = grpc.loadPackageDefinition(packageDef).lnrpc;
73-
unlocker = new lnrpc.WalletUnlocker(`localhost:${lndPort}`, credentials);
74+
unlocker = new lnrpc.WalletUnlocker(`${lndIP}:${lndPort}`, credentials);
7475
grpc.waitForClientReady(unlocker, Infinity, err => {
7576
event.sender.send('unlockReady', { err });
7677
});
@@ -87,7 +88,7 @@ module.exports.init = async function({
8788
credentials,
8889
macaroonCreds
8990
);
90-
lnd = new lnrpc.Lightning(`localhost:${lndPort}`, credentials);
91+
lnd = new lnrpc.Lightning(`${lndIP}:${lndPort}`, credentials);
9192
grpc.waitForClientReady(lnd, Infinity, err => {
9293
event.sender.send('lndReady', { err });
9394
});

public/helper.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Parse a list of CLI arguments searching for a target argument.
3+
* @param {string} target The target argument we're searching for.
4+
* @return {string|undefined} The target argument's value, or undefined.
5+
*/
6+
module.exports.parseCliArg = function(target) {
7+
let regex = new RegExp('--' + target);
8+
let value;
9+
process.argv.filter(a => {
10+
if (regex.test(a)) {
11+
let split = a.split('=');
12+
if (split.length > 1) {
13+
value = split[1];
14+
}
15+
}
16+
});
17+
return value;
18+
};

0 commit comments

Comments
 (0)