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.
package/bitcoinrpc/rpc.js CHANGED
@@ -2,8 +2,14 @@ const asyncAuto = require('async/auto');
2
2
  const {returnResult} = require('asyncjs-util');
3
3
 
4
4
  const defaultTimeout = 1000 * 30;
5
+ const {isInteger} = Number;
6
+ const isSuccess = code => code >= 200 && code < 300;
7
+ const isTimeout = err => ['AbortError', 'TimeoutError'].includes(err.name);
8
+ const lostCodes = ['ECONNRESET', 'EPIPE', 'UND_ERR_CLOSED', 'UND_ERR_SOCKET'];
9
+ const {parse} = JSON;
5
10
  let requests = 0;
6
11
  const {stringify} = JSON;
12
+ const unsentCodes = ['ECONNREFUSED', 'UND_ERR_CONNECT_TIMEOUT'];
7
13
 
8
14
  /** Call JSON RPC
9
15
 
@@ -13,13 +19,18 @@ const {stringify} = JSON;
13
19
  params: [<Parameter Object>]
14
20
  pass: <Password String>
15
21
  port: <Port Number>
22
+ [timeout]: <Request Timeout Milliseconds Number>
16
23
  user: <Username String>
17
24
  }
18
25
 
26
+ ConnectionToBitcoindRpcServiceFailed means the request never reached the
27
+ server. ConnectionToBitcoindRpcServiceLost and TimedOutWaitingForRpcResponse
28
+ mean the server may have executed the command.
29
+
19
30
  @returns via cbk or Promise
20
31
  <Result Object>
21
32
  */
22
- module.exports = ({cmd, host, params, pass, port, user}, cbk) => {
33
+ module.exports = ({cmd, host, params, pass, port, timeout, user}, cbk) => {
23
34
  return new Promise((resolve, reject) => {
24
35
  return asyncAuto({
25
36
  // Check arguments
@@ -40,6 +51,10 @@ module.exports = ({cmd, host, params, pass, port, user}, cbk) => {
40
51
  return cbk([400, 'ExpectedRpcPasswordToExecuteRpcCall']);
41
52
  }
42
53
 
54
+ if (timeout !== undefined && !(isInteger(timeout) && timeout > 0)) {
55
+ return cbk([400, 'ExpectedPositiveTimeoutToExecuteRpcCall']);
56
+ }
57
+
43
58
  if (!user) {
44
59
  return cbk([400, 'ExpectedRpcUsernameToExecuteRpcCall']);
45
60
  }
@@ -47,39 +62,111 @@ module.exports = ({cmd, host, params, pass, port, user}, cbk) => {
47
62
  return cbk();
48
63
  },
49
64
 
50
- // Send request to the server
65
+ // Send request to the server, failures are returned rather than thrown
51
66
  request: ['validate', async ({}) => {
52
67
  const credentials = Buffer.from(`${user}:${pass}`);
53
68
 
54
69
  try {
55
- const response = await fetch(
56
- `http://${host}:${port}/`,
57
- {
58
- body: stringify({
59
- id: `${++requests}`,
60
- method: cmd,
61
- params: params,
62
- }),
63
- headers: {
64
- 'Authorization': `Basic ${credentials.toString('base64')}`,
65
- 'Content-Type': 'application/json',
66
- },
67
- method: 'POST',
70
+ const response = await fetch(`http://${host}:${port}/`, {
71
+ body: stringify({params, id: `${++requests}`, method: cmd}),
72
+ headers: {
73
+ 'Authorization': `Basic ${credentials.toString('base64')}`,
74
+ 'Content-Type': 'application/json',
68
75
  },
69
- );
76
+ method: 'POST',
77
+ signal: AbortSignal.timeout(timeout || defaultTimeout),
78
+ });
79
+
80
+ return {body: await response.text(), statusCode: response.status};
81
+ } catch (err) {
82
+ return {err};
83
+ }
84
+ }],
85
+
86
+ // Check for a failure to get a response from the server
87
+ checkRequest: ['request', ({request}, cbk) => {
88
+ const {err} = request;
70
89
 
71
- const {result} = await response.json();
90
+ // Exit early when there is a response
91
+ if (!err) {
92
+ return cbk();
93
+ }
94
+
95
+ if (isTimeout(err)) {
96
+ return cbk([503, 'TimedOutWaitingForRpcResponse', {cmd}]);
97
+ }
98
+
99
+ // Undici puts the underlying failure reason into the error cause
100
+ const cause = err.cause || {};
101
+ const code = cause.code || err.code;
102
+
103
+ // Failing to connect to every address of a host groups the failures
104
+ const [failure] = cause.errors || [];
105
+ const reason = failure || cause;
106
+
107
+ const details = {
108
+ cmd,
109
+ code,
110
+ err,
111
+ message: reason.message || err.message,
112
+ };
113
+
114
+ // The connection was never made so the command was not executed
115
+ if (unsentCodes.includes(code)) {
116
+ return cbk([503, 'ConnectionToBitcoindRpcServiceFailed', details]);
117
+ }
72
118
 
73
- return result;
119
+ // The connection broke so the command may have been executed
120
+ if (lostCodes.includes(code)) {
121
+ return cbk([503, 'ConnectionToBitcoindRpcServiceLost', details]);
122
+ }
123
+
124
+ return cbk([503, 'UnexpectedErrorFromRpcService', details]);
125
+ }],
126
+
127
+ // Parse the response body as a JSON-RPC response object
128
+ parseBody: ['checkRequest', 'request', ({request}, cbk) => {
129
+ const details = {cmd, status: request.statusCode};
130
+ let body;
131
+
132
+ try {
133
+ body = parse(request.body);
74
134
  } catch (err) {
75
- if ([err.code, err.cause?.code].includes('ECONNRESET')) {
76
- throw [503, 'ConnectionToBitcoindRpcServiceFailed'];
77
- }
135
+ return cbk([503, 'FailedToParseRpcServiceResponse', details]);
136
+ }
78
137
 
79
- throw [503, 'UnexpectedErrorFromRpcService', {err}];
138
+ if (!body || typeof body !== 'object') {
139
+ return cbk([503, 'UnexpectedRpcServiceResponse', details]);
80
140
  }
141
+
142
+ return cbk(null, body);
143
+ }],
144
+
145
+ // Check the response for a command failure and pull out the result
146
+ result: ['parseBody', 'request', ({parseBody, request}, cbk) => {
147
+ const {error} = parseBody;
148
+
149
+ // A JSON-RPC command failure is reported in the error attribute
150
+ if (error !== undefined && error !== null) {
151
+ return cbk([
152
+ 503,
153
+ 'UnexpectedErrorFromRpcCommand',
154
+ {cmd, code: error.code, message: error.message},
155
+ ]);
156
+ }
157
+
158
+ // Without a command failure the HTTP response should be a success
159
+ if (!isSuccess(request.statusCode)) {
160
+ return cbk([
161
+ 503,
162
+ 'UnexpectedRpcServiceResponse',
163
+ {cmd, status: request.statusCode},
164
+ ]);
165
+ }
166
+
167
+ return cbk(null, parseBody.result);
81
168
  }],
82
169
  },
83
- returnResult({reject, resolve, of: 'request'}, cbk));
170
+ returnResult({reject, resolve, of: 'result'}, cbk));
84
171
  });
85
172
  };
@@ -0,0 +1,22 @@
1
+ /** Make an error for when it cannot be known that blocks were generated
2
+
3
+ {
4
+ count: <Expected Generated Blocks Count Number>
5
+ err: <Generate Request Error Object>
6
+ [height]: <Current Chain Height Number>
7
+ start: <Chain Height Before Generating Number>
8
+ }
9
+
10
+ @returns
11
+ [<Error Code Number>, <Error Message String>, <Error Details Object>]
12
+ */
13
+ module.exports = ({count, err, height, start}) => {
14
+ const [, cause, details] = err;
15
+ const {code} = details || {};
16
+
17
+ return [
18
+ 503,
19
+ 'UnknownIfBlocksWereGenerated',
20
+ {cause, code, count, height, start},
21
+ ];
22
+ };
@@ -0,0 +1,82 @@
1
+ const asyncAuto = require('async/auto');
2
+ const asyncRetry = require('async/retry');
3
+ const {createChainAddress} = require('lightning');
4
+ const {getUtxos} = require('lightning');
5
+ const {returnResult} = require('asyncjs-util');
6
+
7
+ const interval = 10;
8
+ const maturity = 100;
9
+ const times = 3000;
10
+
11
+ /** Generate blocks for a node, waiting for a UTXO when enough blocks mature
12
+
13
+ {
14
+ [address]: <Mine Coinbase Outputs to Address String>
15
+ [count]: <Generate Blocks Count Number>
16
+ generate: <Generate Blocks Function> ({address, count}, cbk) => {}
17
+ lnd: <Authenticated LND API Object>
18
+ }
19
+
20
+ @returns via cbk or Promise
21
+ */
22
+ module.exports = (args, cbk) => {
23
+ return new Promise((resolve, reject) => {
24
+ return asyncAuto({
25
+ // Check arguments
26
+ validate: cbk => {
27
+ if (!args.generate) {
28
+ return cbk([400, 'ExpectedGenerateFunctionToGenerateBlocks']);
29
+ }
30
+
31
+ if (!args.lnd) {
32
+ return cbk([400, 'ExpectedAuthenticatedLndToGenerateBlocks']);
33
+ }
34
+
35
+ return cbk();
36
+ },
37
+
38
+ // Get a node address to mine to when no address is specified
39
+ getAddress: ['validate', ({}, cbk) => {
40
+ // Exit early when there is an address to mine to
41
+ if (!!args.address) {
42
+ return cbk(null, {address: args.address});
43
+ }
44
+
45
+ return createChainAddress({lnd: args.lnd}, cbk);
46
+ }],
47
+
48
+ // Generate the blocks
49
+ generate: ['getAddress', ({getAddress}, cbk) => {
50
+ return args.generate({
51
+ address: getAddress.address,
52
+ count: args.count,
53
+ },
54
+ cbk);
55
+ }],
56
+
57
+ // Wait for a UTXO to show up when there are enough blocks to mature it
58
+ waitForUtxo: ['generate', ({}, cbk) => {
59
+ // Exit early when there are not enough blocks to mature a coinbase
60
+ if (!args.count || args.count < maturity) {
61
+ return cbk();
62
+ }
63
+
64
+ return asyncRetry({interval, times}, cbk => {
65
+ return getUtxos({lnd: args.lnd}, (err, res) => {
66
+ if (!!err) {
67
+ return cbk(err);
68
+ }
69
+
70
+ if (!res.utxos.length) {
71
+ return cbk([503, 'ExpectedUtxoInUtxos']);
72
+ }
73
+
74
+ return cbk();
75
+ });
76
+ },
77
+ cbk);
78
+ }],
79
+ },
80
+ returnResult({reject, resolve}, cbk));
81
+ });
82
+ };
@@ -1,32 +1,21 @@
1
1
  const asyncAuto = require('async/auto');
2
2
  const asyncEach = require('async/each');
3
- const asyncMap = require('async/map');
4
3
  const asyncMapSeries = require('async/mapSeries');
5
4
  const asyncRetry = require('async/retry');
6
5
  const {authenticatedLndGrpc} = require('lightning');
7
- const {createChainAddress} = require('lightning');
8
- const {findFreePorts} = require('find-free-ports');
9
- const {getUtxos} = require('lightning');
10
- const {getIdentity} = require('lightning');
11
6
  const {returnResult} = require('asyncjs-util');
12
7
 
8
+ const generateBlocks = require('./generate_blocks');
13
9
  const {setupChannel} = require('./../setup');
14
10
  const {spawnLightningDocker} = require('./../lnd');
15
11
 
16
- const between = (min, max) => Math.floor(Math.random() * (max - min) + min);
17
- const chunk = (arr, n, size) => [...Array(size)].map(_ => arr.splice(0, n));
18
12
  const count = size => size || 1;
19
- const endPort = 65000;
20
13
  const generateAddress = '2N8hwP1WmJrFF5QWABn38y63uYLhnJYJYTF';
21
14
  const interval = 10;
22
15
  const {isInteger} = Number;
23
16
  const line = arr => arr.slice(1).map((_, i) => [i, i + 1]);
24
- const makeAddress = ({lnd}) => createChainAddress({lnd});
25
- const maturity = 100;
26
17
  const pairs = n => n.map((x, i) => n.slice(i + 1).map(y => [x, y])).flat();
27
- const portsPerLnd = 7;
28
- const startPort = 1025;
29
- const times = 3000;
18
+ const started = all => all.filter(n => !!n.value).map(n => n.value);
30
19
 
31
20
  /** Spawn a cluster of nodes
32
21
 
@@ -79,38 +68,29 @@ module.exports = (args, cbk) => {
79
68
  // Spawn nodes
80
69
  spawn: ['validate', async () => {
81
70
  return await asyncRetry({interval, times: 25}, async () => {
82
- const options = {startPort: between(startPort, endPort)};
83
-
84
- // Find ports for the requested daemons
85
- const findPorts = await findFreePorts(
86
- portsPerLnd * count(args.size),
87
- options
88
- );
89
-
90
- const nodes = chunk(findPorts, portsPerLnd, count(args.size));
91
-
92
- return await asyncMap(nodes, async (ports) => {
93
- const [
94
- chainP2pPort,
95
- chainRpcPort,
96
- chainZmqBlockPort,
97
- chainZmqTxPort,
98
- lightningP2pPort,
99
- lightningRpcPort,
100
- lightningTowerPort,
101
- ] = ports;
102
-
103
- const lightningDocker = await spawnLightningDocker({
104
- chain_p2p_port: chainP2pPort,
105
- chain_rpc_port: chainRpcPort,
106
- chain_zmq_block_port: chainZmqBlockPort,
107
- chain_zmq_tx_port: chainZmqTxPort,
71
+ const spawning = [...Array(count(args.size))].map(() => {
72
+ return spawnLightningDocker({
108
73
  generate_address: generateAddress,
109
- lightning_p2p_port: lightningP2pPort,
110
- lightning_rpc_port: lightningRpcPort,
111
- lightning_tower_port: lightningTowerPort,
112
74
  lnd_configuration: args.lnd_configuration,
113
75
  });
76
+ });
77
+
78
+ // Wait for every node to finish starting, even when one fails
79
+ const spawned = await Promise.allSettled(spawning);
80
+
81
+ const failure = spawned.find(n => n.status === 'rejected');
82
+
83
+ // Stop the nodes that started so they are not left running
84
+ if (!!failure) {
85
+ await asyncEach(started(spawned), async ({kill}) => {
86
+ return await kill({});
87
+ });
88
+
89
+ throw failure.reason;
90
+ }
91
+
92
+ return started(spawned).map(lightningDocker => {
93
+ const id = lightningDocker.public_key;
114
94
 
115
95
  const {lnd} = authenticatedLndGrpc({
116
96
  cert: lightningDocker.cert,
@@ -118,8 +98,6 @@ module.exports = (args, cbk) => {
118
98
  socket: lightningDocker.socket,
119
99
  });
120
100
 
121
- const id = (await getIdentity({lnd})).public_key;
122
-
123
101
  return {
124
102
  id,
125
103
  lnd,
@@ -129,29 +107,14 @@ module.exports = (args, cbk) => {
129
107
  getBlockInfo: lightningDocker.get_block_info,
130
108
  socket: lightningDocker.chain_socket,
131
109
  },
132
- generate: ({address, count}) => {
133
- return new Promise(async (resolve, reject) => {
134
- await lightningDocker.generate({
135
- count,
136
- address: address || (await makeAddress({lnd})).address,
137
- });
138
-
139
- if (!count || count < maturity) {
140
- return resolve();
141
- }
142
-
143
- await asyncRetry({interval, times}, async () => {
144
- const [utxo] = (await getUtxos({lnd})).utxos;
145
-
146
- if (!utxo) {
147
- throw new Error('ExpectedUtxoInUtxos');
148
- }
149
-
150
- return utxo;
151
- });
152
-
153
- return resolve();
154
- });
110
+ generate: ({address, count}, cbk) => {
111
+ return generateBlocks({
112
+ address,
113
+ count,
114
+ lnd,
115
+ generate: lightningDocker.generate,
116
+ },
117
+ cbk);
155
118
  },
156
119
  kill: lightningDocker.kill,
157
120
  public_key: id,
@@ -12,6 +12,8 @@ const stopAfterRuntimeSeconds = 60;
12
12
 
13
13
  /** Spawn a new docker image
14
14
 
15
+ An undefined external port is published on a free port that Docker picks
16
+
15
17
  {
16
18
  arguments: [<Command Arguments String>]
17
19
  [expose]: [<Expose Port String>]
@@ -24,7 +26,11 @@ const stopAfterRuntimeSeconds = 60;
24
26
  @returns via cbk or Promise
25
27
  {
26
28
  getFile: <Get File Function>
29
+ host: <Container Network Address String>
27
30
  kill: <Kill Daemon Function>
31
+ ports: {
32
+ <Internal Port String>: <External Port Number>
33
+ }
28
34
  }
29
35
  */
30
36
  module.exports = ({arguments, expose, image, ports}, cbk) => {
@@ -106,7 +112,8 @@ module.exports = ({arguments, expose, image, ports}, cbk) => {
106
112
  HostConfig: {
107
113
  AutoRemove: true,
108
114
  PortBindings: keys(ports).reduce((sum, port) => {
109
- sum[port] = [{HostPort: ports[port].toString()}];
115
+ // Docker picks a free host port when none is specified
116
+ sum[port] = [{HostPort: !ports[port] ? '' : `${ports[port]}`}];
110
117
 
111
118
  return sum;
112
119
  },
@@ -135,22 +142,53 @@ module.exports = ({arguments, expose, image, ports}, cbk) => {
135
142
  return cbk();
136
143
  });
137
144
  },
138
- cbk);
145
+ err => {
146
+ // Exit early when the container started
147
+ if (!err) {
148
+ return cbk();
149
+ }
150
+
151
+ // Remove the container so a failed start does not leave it behind
152
+ return container.remove({force: true}, () => cbk(err));
153
+ });
139
154
  }],
140
155
 
141
156
  // Get the details about the container
142
157
  spawned: ['container', 'start', ({container}, cbk) => {
143
158
  return container.inspect({}, (err, res) => {
144
159
  if (!!err) {
145
- return cbk([503, 'UnexpectedErrorGettingContainerDetails', {err}]);
160
+ return killDocker({container}, () => cbk([
161
+ 503,
162
+ 'UnexpectedErrorGettingContainerDetails',
163
+ {err},
164
+ ]));
146
165
  }
147
166
 
148
167
  const network = res.NetworkSettings;
168
+ const published = network.Ports || {};
169
+ const {bridge} = network.Networks || {};
170
+
171
+ const host = network.IPAddress || (!!bridge && bridge.IPAddress);
172
+
173
+ // Exit early when the container has no network address
174
+ if (!host) {
175
+ return killDocker({container}, () => {
176
+ return cbk([503, 'ExpectedNetworkAddressForDockerContainer']);
177
+ });
178
+ }
149
179
 
150
180
  return cbk(null, {
181
+ host,
151
182
  getFile: ({path}, cbk) => getFile({container, path}, cbk),
152
- host: network.IPAddress || network.Networks.bridge.IPAddress,
153
183
  kill: ({}, cbk) => killDocker({container}, cbk),
184
+ ports: keys(ports).reduce((sum, port) => {
185
+ const [binding] = published[port] || [];
186
+
187
+ sum[port] = !binding ? undefined : Number(binding.HostPort);
188
+
189
+ return sum;
190
+ },
191
+ {}),
154
192
  });
155
193
  });
156
194
  }],
@@ -12,15 +12,19 @@ const defaultBitcoindRpcPort = 18443;
12
12
 
13
13
  /** Spawn an LND Docker
14
14
 
15
+ Ports are optional. When RPC or tower ports are not specified, Docker picks
16
+ free host ports for them. Other ports that are not specified are only
17
+ reachable over the Docker network.
18
+
15
19
  {
16
- chain_p2p_port: <Chain Network P2P Listen Port Number>
17
- chain_rpc_port: <Chain Node RPC Port Number>
18
- chain_zmq_block_port: <Chain Node ZMQ Blocks Port Number>
19
- chain_zmq_tx_port: <Chain Node ZMQ Transactions Port Number>
20
+ [chain_p2p_port]: <Chain Network P2P Listen Port Number>
21
+ [chain_rpc_port]: <Chain Node RPC Port Number>
22
+ [chain_zmq_block_port]: <Chain Node ZMQ Blocks Port Number>
23
+ [chain_zmq_tx_port]: <Chain Node ZMQ Transactions Port Number>
20
24
  generate_address: <Generate Blocks to Address String>
21
- lightning_p2p_port: <Lightning Network P2P Listen Port Number>
22
- lightning_rpc_port: <Lightning Node RPC Port Number>
23
- lightning_tower_port: <Lightning Tower Port Number>
25
+ [lightning_p2p_port]: <Lightning Network P2P Listen Port Number>
26
+ [lightning_rpc_port]: <Lightning Node RPC Port Number>
27
+ [lightning_tower_port]: <Lightning Tower Port Number>
24
28
  [lnd_configuration]: [<LND Configuration Argument String>]
25
29
  [seed]: <Mnemonic Seed String>
26
30
  }
@@ -45,38 +49,10 @@ module.exports = (args, cbk) => {
45
49
  return asyncAuto({
46
50
  // Check arguments
47
51
  validate: cbk => {
48
- if (!args.chain_p2p_port) {
49
- return cbk([400, 'ExpectedBlockchainDaemonP2pPortToSpawnLnDocker']);
50
- }
51
-
52
- if (!args.chain_rpc_port) {
53
- return cbk([400, 'ExpecteddChainRpcPortToSpawnLightningDocker']);
54
- }
55
-
56
- if (!args.chain_zmq_block_port) {
57
- return cbk([400, 'ExpectedChainZmqBlockPortToSpawnLightningDocker']);
58
- }
59
-
60
- if (!args.chain_zmq_tx_port) {
61
- return cbk([400, 'ExpectedChainZmqTxPortToSpawnLightningDocker']);
62
- }
63
-
64
52
  if (!args.generate_address) {
65
53
  return cbk([400, 'ExpectedGenerateAddressToSpawnLightningDocker']);
66
54
  }
67
55
 
68
- if (!args.lightning_p2p_port) {
69
- return cbk([400, 'ExpectedLnP2pPortToSpawnLightningDocker']);
70
- }
71
-
72
- if (!args.lightning_rpc_port) {
73
- return cbk([400, 'ExpectedLnRpcPortToSpawnLightningDocker']);
74
- }
75
-
76
- if (!args.lightning_tower_port) {
77
- return cbk([400, 'ExpectedLnTowerPortToSpawnLightningDocker']);
78
- }
79
-
80
56
  return cbk();
81
57
  },
82
58
 
@@ -96,10 +72,18 @@ module.exports = (args, cbk) => {
96
72
  return generateToAddress({
97
73
  address: args.generate_address,
98
74
  pass: spawnChainDaemon.rpc_pass,
99
- port: args.chain_rpc_port,
75
+ port: spawnChainDaemon.rpc_port,
100
76
  user: spawnChainDaemon.rpc_user,
101
77
  },
102
- cbk);
78
+ err => {
79
+ // Exit early when the block was generated
80
+ if (!err) {
81
+ return cbk();
82
+ }
83
+
84
+ // Stop the chain daemon so it is not left running
85
+ return spawnChainDaemon.kill({}, () => cbk(err));
86
+ });
103
87
  }],
104
88
 
105
89
  // Spawn the LND lightning daemon
@@ -114,14 +98,22 @@ module.exports = (args, cbk) => {
114
98
  bitcoind_rpc_pass: spawnChainDaemon.rpc_pass,
115
99
  bitcoind_rpc_port: defaultBitcoindRpcPort,
116
100
  bitcoind_rpc_user: spawnChainDaemon.rpc_user,
117
- bitcoind_zmq_block_port: args.chain_zmq_block_port,
118
- bitcoind_zmq_tx_port: args.chain_zmq_tx_port,
101
+ bitcoind_zmq_block_port: spawnChainDaemon.zmq_block_port,
102
+ bitcoind_zmq_tx_port: spawnChainDaemon.zmq_tx_port,
119
103
  p2p_port: args.lightning_p2p_port,
120
104
  rpc_port: args.lightning_rpc_port,
121
105
  tower_port: args.lightning_tower_port,
122
106
  seed: args.seed,
123
107
  },
124
- cbk);
108
+ (err, res) => {
109
+ // Exit early when LND started
110
+ if (!err) {
111
+ return cbk(null, res);
112
+ }
113
+
114
+ // Stop the chain daemon when LND does not start
115
+ return spawnChainDaemon.kill({}, () => cbk(err));
116
+ });
125
117
  }],
126
118
 
127
119
  // Return the result
@@ -136,22 +128,23 @@ module.exports = (args, cbk) => {
136
128
  add_chain_peer: ({socket}) => addPeer({
137
129
  socket,
138
130
  pass: spawnChainDaemon.rpc_pass,
139
- port: args.chain_rpc_port,
131
+ port: spawnChainDaemon.rpc_port,
140
132
  user: spawnChainDaemon.rpc_user,
141
133
  }),
142
134
  cert: spawnLightningDaemon.cert,
143
135
  chain_socket: `${spawnChainDaemon.host}`,
144
- generate: ({address, count}) => generateToAddress({
136
+ generate: ({address, count}, cbk) => generateToAddress({
145
137
  address,
146
138
  count,
147
139
  pass: spawnChainDaemon.rpc_pass,
148
- port: args.chain_rpc_port,
140
+ port: spawnChainDaemon.rpc_port,
149
141
  user: spawnChainDaemon.rpc_user,
150
- }),
142
+ },
143
+ cbk),
151
144
  get_block_info: ({id}) => getBlockInfo({
152
145
  id,
153
146
  pass: spawnChainDaemon.rpc_pass,
154
- port: args.chain_rpc_port,
147
+ port: spawnChainDaemon.rpc_port,
155
148
  user: spawnChainDaemon.rpc_user,
156
149
  }),
157
150
  kill: ({}, cbk) => killDockers({dockers}, cbk),