ln-docker-daemons 8.1.0 → 8.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,12 +11,19 @@ const {spawnDockerImage} = require('./../docker');
11
11
  const imageName = ver => !!ver ? `lightninglabs/lnd:${ver}` : dockerLndImage;
12
12
  const interval = 100;
13
13
  const join = n => n.join('');
14
+ const localSocket = port => `localhost:${port}`;
14
15
  const macaroonPath = '/root/.lnd/data/chain/bitcoin/regtest/admin.macaroon';
16
+ const p2pPort = '9735/tcp';
17
+ const rpcPort = '10009/tcp';
15
18
  const times = 500;
16
19
  const tlsCertPath = '/root/.lnd/tls.cert';
20
+ const towerPort = '9911/tcp';
17
21
 
18
22
  /** Spawn a new Docker image running LND
19
23
 
24
+ When RPC or tower ports are not specified, Docker picks free host ports for
25
+ them. A p2p port that is not specified is not published to the host.
26
+
20
27
  {
21
28
  bitcoind_rpc_host: <Bitcoin Core RPC Host String>
22
29
  bitcoind_rpc_pass: <Bitcoin Core RPC Password String>
@@ -25,9 +32,9 @@ const tlsCertPath = '/root/.lnd/tls.cert';
25
32
  [bitcoind_zmq_block_port]: <Bitcoin Core ZMQ Block Port Number>
26
33
  [bitcoind_zmq_tx_port]: <Bitcoin Core ZMQ Transaction Port Number>
27
34
  [configuration]: [<LND Configuration Argument String>]
28
- p2p_port: <LND Peer to Peer Listen Port Number>
29
- rpc_port: <LND RPC Port Number>
30
- tower_port: <LND Tower Port Number>
35
+ [p2p_port]: <LND Peer to Peer Listen Port Number>
36
+ [rpc_port]: <LND RPC Port Number>
37
+ [tower_port]: <LND Tower Port Number>
31
38
  [seed]: <Mnemonic Seed String>
32
39
  }
33
40
 
@@ -58,18 +65,6 @@ module.exports = (args, cbk) => {
58
65
  return cbk([400, 'ExpectedBitcoinCoreRpcUserToSpawnLndDocker']);
59
66
  }
60
67
 
61
- if (!args.p2p_port) {
62
- return cbk([400, 'ExpectedLndPeer2PeerNetworkPortToSpawnLndDocker']);
63
- }
64
-
65
- if (!args.rpc_port) {
66
- return cbk([400, 'ExpectedRpcPortToSpawnLndDocker']);
67
- }
68
-
69
- if (!args.tower_port) {
70
- return cbk([400, 'ExpectedTowerPortToSpawnLndDocker']);
71
- }
72
-
73
68
  return cbk();
74
69
  },
75
70
 
@@ -124,14 +119,21 @@ module.exports = (args, cbk) => {
124
119
  arguments.push('--bitcoind.txpollinginterval=1s');
125
120
  }
126
121
 
122
+ // Docker picks free host ports for RPC and tower when not specified
123
+ const ports = {
124
+ [rpcPort]: args.rpc_port,
125
+ [towerPort]: args.tower_port,
126
+ };
127
+
128
+ // Peers connect over the Docker network unless a p2p port is specified
129
+ if (!!args.p2p_port) {
130
+ ports[p2pPort] = args.p2p_port;
131
+ }
132
+
127
133
  return spawnDockerImage({
134
+ ports,
128
135
  arguments: arguments.concat(args.configuration || []),
129
136
  image: imageName(process.env.DOCKER_LND_VERSION),
130
- ports: {
131
- '9735/tcp': args.p2p_port,
132
- '9911/tcp': args.tower_port,
133
- '10009/tcp': args.rpc_port,
134
- },
135
137
  },
136
138
  cbk);
137
139
  }],
@@ -145,9 +147,13 @@ module.exports = (args, cbk) => {
145
147
  }],
146
148
 
147
149
  // Create a wallet for the LND
148
- createWallet: ['getCertificate', ({getCertificate}, cbk) => {
150
+ createWallet: [
151
+ 'getCertificate',
152
+ 'spawnDocker',
153
+ ({getCertificate, spawnDocker}, cbk) =>
154
+ {
149
155
  const cert = getCertificate.file.toString('hex');
150
- const socket = `localhost:${args.rpc_port}`;
156
+ const socket = localSocket(spawnDocker.ports[rpcPort]);
151
157
 
152
158
  const {lnd} = unauthenticatedLndGrpc({cert, socket});
153
159
 
@@ -185,7 +191,7 @@ module.exports = (args, cbk) => {
185
191
  const {lnd} = authenticatedLndGrpc({
186
192
  cert: getCertificate.file.toString('hex'),
187
193
  macaroon: createWallet.toString('hex'),
188
- socket: `localhost:${args.rpc_port}`,
194
+ socket: localSocket(spawnDocker.ports[rpcPort]),
189
195
  });
190
196
 
191
197
  return asyncRetry({interval, times}, cbk => {
@@ -208,11 +214,20 @@ module.exports = (args, cbk) => {
208
214
  kill: spawnDocker.kill,
209
215
  macaroon: createWallet.toString('hex'),
210
216
  public_key: waitForRpc.public_key,
211
- socket: `localhost:${args.rpc_port}`,
212
- tower_socket: `localhost:${args.tower_port}`,
217
+ socket: localSocket(spawnDocker.ports[rpcPort]),
218
+ tower_socket: localSocket(spawnDocker.ports[towerPort]),
213
219
  });
214
220
  }],
215
221
  },
216
- returnResult({reject, resolve, of: 'spawned'}, cbk));
222
+ (err, res) => {
223
+ // Stop the container when LND does not start so it is not left running
224
+ if (!!err && !!res && !!res.spawnDocker) {
225
+ return res.spawnDocker.kill({}, () => {
226
+ return returnResult({reject, resolve}, cbk)(err);
227
+ });
228
+ }
229
+
230
+ return returnResult({reject, resolve, of: 'spawned'}, cbk)(err, res);
231
+ });
217
232
  });
218
233
  };
package/package.json CHANGED
@@ -15,8 +15,7 @@
15
15
  "async": "3.2.6",
16
16
  "asyncjs-util": "1.2.12",
17
17
  "dockerode": "5.0.1",
18
- "find-free-ports": "3.1.1",
19
- "lightning": "13.1.2"
18
+ "lightning": "13.1.5"
20
19
  },
21
20
  "description": "Spawn and control LN Docker daemons",
22
21
  "engines": {
@@ -45,5 +44,5 @@
45
44
  "scripts": {
46
45
  "test": "node --experimental-test-coverage --test"
47
46
  },
48
- "version": "8.1.0"
47
+ "version": "8.1.2"
49
48
  }