ln-docker-daemons 8.1.3 → 9.0.0
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/README.md +119 -33
- package/bitcoinrpc/add_peer.js +16 -8
- package/bitcoinrpc/check_generated.js +1 -8
- package/bitcoinrpc/generate_to_address.js +15 -15
- package/bitcoinrpc/get_added_node_info.js +79 -0
- package/bitcoinrpc/get_block_info.js +16 -8
- package/bitcoinrpc/get_blockchain_info.js +15 -6
- package/bitcoinrpc/get_peer_info.js +73 -0
- package/bitcoinrpc/index.js +4 -0
- package/bitcoinrpc/mine_blocks.js +36 -25
- package/bitcoinrpc/rpc.js +41 -36
- package/bitcoinrpc/unknown_generated_error.js +9 -3
- package/cluster/spawn_lightning_cluster.js +110 -86
- package/docker/first_file_in_tar.js +4 -4
- package/docker/get_file.js +4 -4
- package/docker/kill_docker.js +4 -4
- package/docker/kill_dockers.js +6 -3
- package/docker/make_tar.js +69 -0
- package/docker/spawn_docker_image.js +88 -27
- package/index.js +2 -0
- package/lnd/constants.json +1 -1
- package/lnd/spawn_lightning_docker.js +10 -8
- package/lnd/spawn_lnd_docker.js +24 -17
- package/loop/check_chain_synced.js +119 -0
- package/loop/check_grpc_server.js +300 -0
- package/loop/constants.json +3 -0
- package/loop/index.js +3 -0
- package/loop/retry_within.js +71 -0
- package/loop/spawn_loop_server_docker.js +263 -0
- package/package.json +5 -3
- package/setup/setup_channel.js +65 -28
- package/setup/wait_for_channel.js +30 -20
- package/setup/wait_for_pending_channel.js +3 -3
- package/tls/index.js +4 -0
- package/tls/make_self_signed_cert.js +167 -0
- package/tls/start_tls_proxy.js +196 -0
|
@@ -6,11 +6,11 @@ const checkGenerated = require('./check_generated');
|
|
|
6
6
|
const getBlockchainInfo = require('./get_blockchain_info');
|
|
7
7
|
const rpc = require('./rpc');
|
|
8
8
|
|
|
9
|
-
const checkInterval = 100;
|
|
10
|
-
const checkTimes = 100;
|
|
11
9
|
const cmd = 'generatetoaddress';
|
|
12
|
-
const
|
|
13
|
-
const
|
|
10
|
+
const defaultCheckInterval = 100;
|
|
11
|
+
const defaultCheckTimes = 100;
|
|
12
|
+
const hasResponse = err => isCommandError(err) || !!err[2].status;
|
|
13
|
+
const host = '127.0.0.1'; // Published ports bind IPv4 loopback only
|
|
14
14
|
const isCommandError = err => err[1] === 'UnexpectedErrorFromRpcCommand';
|
|
15
15
|
const isDisconnected = err => isUnsent(err) || isLost(err);
|
|
16
16
|
const isInvalid = err => err[0] === 400;
|
|
@@ -21,11 +21,10 @@ const retryUnsent = {errorFilter: isUnsent, interval: 100, times: 5};
|
|
|
21
21
|
|
|
22
22
|
/** Mine blocks to an address, checking the chain when the outcome is unclear
|
|
23
23
|
|
|
24
|
-
A request is only retried when it never reached bitcoind. When it fails in
|
|
25
|
-
any other way, it may have mined blocks, so the chain is checked for them.
|
|
26
|
-
|
|
27
24
|
{
|
|
28
25
|
address: <Address to Mine Outputs Towards String>
|
|
26
|
+
[check_interval]: <Unclear Outcome Poll Interval Milliseconds Number>
|
|
27
|
+
[check_times]: <Unclear Outcome Poll Times Number>
|
|
29
28
|
count: <Generate Count Number>
|
|
30
29
|
pass: <RPC Password String>
|
|
31
30
|
port: <RPC Port Number>
|
|
@@ -35,28 +34,28 @@ const retryUnsent = {errorFilter: isUnsent, interval: 100, times: 5};
|
|
|
35
34
|
@returns via cbk or Promise
|
|
36
35
|
[<Generated Block Hash Hex String>]
|
|
37
36
|
*/
|
|
38
|
-
module.exports = (
|
|
37
|
+
module.exports = (args, cbk) => {
|
|
39
38
|
return new Promise((resolve, reject) => {
|
|
40
39
|
return asyncAuto({
|
|
41
40
|
// Check arguments
|
|
42
41
|
validate: cbk => {
|
|
43
|
-
if (!address) {
|
|
42
|
+
if (!args.address) {
|
|
44
43
|
return cbk([400, 'ExpectedAddressToMineBlocks']);
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
if (!count) {
|
|
46
|
+
if (!args.count) {
|
|
48
47
|
return cbk([400, 'ExpectedCountOfBlocksToMine']);
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
if (!pass) {
|
|
50
|
+
if (!args.pass) {
|
|
52
51
|
return cbk([400, 'ExpectedRpcPasswordToMineBlocks']);
|
|
53
52
|
}
|
|
54
53
|
|
|
55
|
-
if (!port) {
|
|
54
|
+
if (!args.port) {
|
|
56
55
|
return cbk([400, 'ExpectedRpcPortNumberToMineBlocks']);
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
if (!user) {
|
|
58
|
+
if (!args.user) {
|
|
60
59
|
return cbk([400, 'ExpectedRpcUsernameToMineBlocks']);
|
|
61
60
|
}
|
|
62
61
|
|
|
@@ -66,17 +65,30 @@ module.exports = ({address, count, pass, port, user}, cbk) => {
|
|
|
66
65
|
// Get the chain height to check against if the request fails
|
|
67
66
|
getStart: ['validate', ({}, cbk) => {
|
|
68
67
|
return asyncRetry(retryRead, cbk => {
|
|
69
|
-
return getBlockchainInfo({
|
|
68
|
+
return getBlockchainInfo({
|
|
69
|
+
pass: args.pass,
|
|
70
|
+
port: args.port,
|
|
71
|
+
user: args.user,
|
|
72
|
+
},
|
|
73
|
+
cbk);
|
|
70
74
|
},
|
|
71
75
|
cbk);
|
|
72
76
|
}],
|
|
73
77
|
|
|
74
78
|
// Generate the blocks, retrying when the request never reached bitcoind
|
|
75
79
|
generate: ['getStart', ({}, cbk) => {
|
|
76
|
-
const params = [count, address];
|
|
80
|
+
const params = [args.count, args.address];
|
|
77
81
|
|
|
78
82
|
return asyncRetry(retryUnsent, cbk => {
|
|
79
|
-
return rpc({
|
|
83
|
+
return rpc({
|
|
84
|
+
cmd,
|
|
85
|
+
host,
|
|
86
|
+
params,
|
|
87
|
+
pass: args.pass,
|
|
88
|
+
port: args.port,
|
|
89
|
+
user: args.user,
|
|
90
|
+
},
|
|
91
|
+
cbk);
|
|
80
92
|
},
|
|
81
93
|
(err, hashes) => {
|
|
82
94
|
if (!err) {
|
|
@@ -95,23 +107,22 @@ module.exports = ({address, count, pass, port, user}, cbk) => {
|
|
|
95
107
|
|
|
96
108
|
// Check the chain for blocks when the generate request failed
|
|
97
109
|
check: ['generate', 'getStart', ({generate, getStart}, cbk) => {
|
|
98
|
-
// Exit early when bitcoind returned the generated block hashes
|
|
99
|
-
// the blocks are known to exist and there is nothing to check
|
|
110
|
+
// Exit early when bitcoind returned the generated block hashes
|
|
100
111
|
if (!generate.err) {
|
|
101
112
|
return cbk(null, generate.hashes);
|
|
102
113
|
}
|
|
103
114
|
|
|
104
115
|
return checkGenerated({
|
|
105
|
-
address,
|
|
106
|
-
count,
|
|
107
|
-
pass,
|
|
108
|
-
port,
|
|
109
|
-
user,
|
|
116
|
+
address: args.address,
|
|
117
|
+
count: args.count,
|
|
110
118
|
err: generate.err,
|
|
111
|
-
interval:
|
|
119
|
+
interval: args.check_interval || defaultCheckInterval,
|
|
112
120
|
is_finished: hasResponse(generate.err),
|
|
121
|
+
pass: args.pass,
|
|
122
|
+
port: args.port,
|
|
113
123
|
start: getStart.blocks,
|
|
114
|
-
times:
|
|
124
|
+
times: args.check_times || defaultCheckTimes,
|
|
125
|
+
user: args.user,
|
|
115
126
|
},
|
|
116
127
|
cbk);
|
|
117
128
|
}],
|
package/bitcoinrpc/rpc.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
const asyncAuto = require('async/auto');
|
|
2
|
+
const asyncify = require('async/asyncify');
|
|
2
3
|
const {returnResult} = require('asyncjs-util');
|
|
3
4
|
|
|
4
5
|
const defaultTimeout = 1000 * 30;
|
|
5
6
|
const {isInteger} = Number;
|
|
7
|
+
const isPositiveInteger = n => isInteger(n) && n > 0;
|
|
6
8
|
const isSuccess = code => code >= 200 && code < 300;
|
|
7
9
|
const isTimeout = err => ['AbortError', 'TimeoutError'].includes(err.name);
|
|
8
10
|
const lostCodes = ['ECONNRESET', 'EPIPE', 'UND_ERR_CLOSED', 'UND_ERR_SOCKET'];
|
|
@@ -25,39 +27,35 @@ const unsentCodes = ['ECONNREFUSED', 'UND_ERR_CONNECT_TIMEOUT'];
|
|
|
25
27
|
user: <Username String>
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
ConnectionToBitcoindRpcServiceFailed means the request never reached the
|
|
29
|
-
server. ConnectionToBitcoindRpcServiceLost and TimedOutWaitingForRpcResponse
|
|
30
|
-
mean the server may have executed the command.
|
|
31
|
-
|
|
32
30
|
@returns via cbk or Promise
|
|
33
31
|
<Result Object>
|
|
34
32
|
*/
|
|
35
|
-
module.exports = (
|
|
33
|
+
module.exports = (args, cbk) => {
|
|
36
34
|
return new Promise((resolve, reject) => {
|
|
37
35
|
return asyncAuto({
|
|
38
36
|
// Check arguments
|
|
39
37
|
validate: cbk => {
|
|
40
|
-
if (!cmd) {
|
|
38
|
+
if (!args.cmd) {
|
|
41
39
|
return cbk([400, 'ExpectedCommandNameToExecuteRpcCall']);
|
|
42
40
|
}
|
|
43
41
|
|
|
44
|
-
if (!host) {
|
|
42
|
+
if (!args.host) {
|
|
45
43
|
return cbk([400, 'ExpectedRpcHostToExecuteRpcCall']);
|
|
46
44
|
}
|
|
47
45
|
|
|
48
|
-
if (!params) {
|
|
46
|
+
if (!args.params) {
|
|
49
47
|
return cbk([400, 'ExpectedCommandParametersToExecuteRpcCall']);
|
|
50
48
|
}
|
|
51
49
|
|
|
52
|
-
if (!pass) {
|
|
50
|
+
if (!args.pass) {
|
|
53
51
|
return cbk([400, 'ExpectedRpcPasswordToExecuteRpcCall']);
|
|
54
52
|
}
|
|
55
53
|
|
|
56
|
-
if (timeout !== undefined && !(
|
|
54
|
+
if (args.timeout !== undefined && !isPositiveInteger(args.timeout)) {
|
|
57
55
|
return cbk([400, 'ExpectedPositiveTimeoutToExecuteRpcCall']);
|
|
58
56
|
}
|
|
59
57
|
|
|
60
|
-
if (!user) {
|
|
58
|
+
if (!args.user) {
|
|
61
59
|
return cbk([400, 'ExpectedRpcUsernameToExecuteRpcCall']);
|
|
62
60
|
}
|
|
63
61
|
|
|
@@ -67,19 +65,21 @@ module.exports = ({cmd, host, params, pass, port, timeout, user}, cbk) => {
|
|
|
67
65
|
// Send request to the server, failures are returned rather than thrown
|
|
68
66
|
request: ['validate', async ({}) => {
|
|
69
67
|
const controller = new AbortController();
|
|
70
|
-
const credentials = Buffer.from(`${user}:${pass}`);
|
|
68
|
+
const credentials = Buffer.from(`${args.user}:${args.pass}`);
|
|
71
69
|
|
|
72
|
-
//
|
|
73
|
-
// AbortSignal.timeout does not, and on Node 22 a fetch can be left
|
|
74
|
-
// waiting on a closed socket, so the process would exit mid-request.
|
|
70
|
+
// Unlike AbortSignal.timeout, this timer keeps the process alive
|
|
75
71
|
const timer = setTimeout(() => {
|
|
76
72
|
return controller.abort(new DOMException(timeoutMessage, timedOut));
|
|
77
73
|
},
|
|
78
|
-
timeout || defaultTimeout);
|
|
74
|
+
args.timeout || defaultTimeout);
|
|
79
75
|
|
|
80
76
|
try {
|
|
81
|
-
const response = await fetch(`http://${host}:${port}/`, {
|
|
82
|
-
body: stringify({
|
|
77
|
+
const response = await fetch(`http://${args.host}:${args.port}/`, {
|
|
78
|
+
body: stringify({
|
|
79
|
+
id: `${++requests}`,
|
|
80
|
+
method: args.cmd,
|
|
81
|
+
params: args.params,
|
|
82
|
+
}),
|
|
83
83
|
headers: {
|
|
84
84
|
'Authorization': `Basic ${credentials.toString('base64')}`,
|
|
85
85
|
'Content-Type': 'application/json',
|
|
@@ -88,11 +88,15 @@ module.exports = ({cmd, host, params, pass, port, timeout, user}, cbk) => {
|
|
|
88
88
|
signal: controller.signal,
|
|
89
89
|
});
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
const body = await response.text();
|
|
92
|
+
|
|
93
|
+
clearTimeout(timer);
|
|
94
|
+
|
|
95
|
+
return {body, statusCode: response.status};
|
|
92
96
|
} catch (err) {
|
|
93
|
-
return {err};
|
|
94
|
-
} finally {
|
|
95
97
|
clearTimeout(timer);
|
|
98
|
+
|
|
99
|
+
return {err};
|
|
96
100
|
}
|
|
97
101
|
}],
|
|
98
102
|
|
|
@@ -105,8 +109,9 @@ module.exports = ({cmd, host, params, pass, port, timeout, user}, cbk) => {
|
|
|
105
109
|
return cbk();
|
|
106
110
|
}
|
|
107
111
|
|
|
112
|
+
// The request timed out so the command may have been executed
|
|
108
113
|
if (isTimeout(err)) {
|
|
109
|
-
return cbk([503, 'TimedOutWaitingForRpcResponse', {cmd}]);
|
|
114
|
+
return cbk([503, 'TimedOutWaitingForRpcResponse', {cmd: args.cmd}]);
|
|
110
115
|
}
|
|
111
116
|
|
|
112
117
|
// Undici puts the underlying failure reason into the error cause
|
|
@@ -118,7 +123,7 @@ module.exports = ({cmd, host, params, pass, port, timeout, user}, cbk) => {
|
|
|
118
123
|
const reason = failure || cause;
|
|
119
124
|
|
|
120
125
|
const details = {
|
|
121
|
-
cmd,
|
|
126
|
+
cmd: args.cmd,
|
|
122
127
|
code,
|
|
123
128
|
err,
|
|
124
129
|
message: reason.message || err.message,
|
|
@@ -138,22 +143,22 @@ module.exports = ({cmd, host, params, pass, port, timeout, user}, cbk) => {
|
|
|
138
143
|
}],
|
|
139
144
|
|
|
140
145
|
// Parse the response body as a JSON-RPC response object
|
|
141
|
-
parseBody: ['checkRequest', 'request', ({request}
|
|
142
|
-
const details = {cmd, status: request.statusCode};
|
|
143
|
-
let body;
|
|
146
|
+
parseBody: ['checkRequest', 'request', asyncify(({request}) => {
|
|
147
|
+
const details = {cmd: args.cmd, status: request.statusCode};
|
|
144
148
|
|
|
145
149
|
try {
|
|
146
|
-
body = parse(request.body);
|
|
147
|
-
} catch (err) {
|
|
148
|
-
return cbk([503, 'FailedToParseRpcServiceResponse', details]);
|
|
149
|
-
}
|
|
150
|
+
const body = parse(request.body);
|
|
150
151
|
|
|
151
|
-
|
|
152
|
-
|
|
152
|
+
if (!!body && typeof body === 'object') {
|
|
153
|
+
return body;
|
|
154
|
+
}
|
|
155
|
+
} catch (err) {
|
|
156
|
+
throw [503, 'FailedToParseRpcServiceResponse', details];
|
|
153
157
|
}
|
|
154
158
|
|
|
155
|
-
|
|
156
|
-
|
|
159
|
+
// The body is JSON but not an object, such as null or a number
|
|
160
|
+
throw [503, 'UnexpectedRpcServiceResponse', details];
|
|
161
|
+
})],
|
|
157
162
|
|
|
158
163
|
// Check the response for a command failure and pull out the result
|
|
159
164
|
result: ['parseBody', 'request', ({parseBody, request}, cbk) => {
|
|
@@ -164,7 +169,7 @@ module.exports = ({cmd, host, params, pass, port, timeout, user}, cbk) => {
|
|
|
164
169
|
return cbk([
|
|
165
170
|
503,
|
|
166
171
|
'UnexpectedErrorFromRpcCommand',
|
|
167
|
-
{cmd, code: error.code, message: error.message},
|
|
172
|
+
{cmd: args.cmd, code: error.code, message: error.message},
|
|
168
173
|
]);
|
|
169
174
|
}
|
|
170
175
|
|
|
@@ -173,7 +178,7 @@ module.exports = ({cmd, host, params, pass, port, timeout, user}, cbk) => {
|
|
|
173
178
|
return cbk([
|
|
174
179
|
503,
|
|
175
180
|
'UnexpectedRpcServiceResponse',
|
|
176
|
-
{cmd, status: request.statusCode},
|
|
181
|
+
{cmd: args.cmd, status: request.statusCode},
|
|
177
182
|
]);
|
|
178
183
|
}
|
|
179
184
|
|
|
@@ -10,13 +10,19 @@
|
|
|
10
10
|
@returns
|
|
11
11
|
[<Error Code Number>, <Error Message String>, <Error Details Object>]
|
|
12
12
|
*/
|
|
13
|
-
module.exports =
|
|
14
|
-
const [, cause, details] = err;
|
|
13
|
+
module.exports = args => {
|
|
14
|
+
const [, cause, details] = args.err;
|
|
15
15
|
const {code} = details || {};
|
|
16
16
|
|
|
17
17
|
return [
|
|
18
18
|
503,
|
|
19
19
|
'UnknownIfBlocksWereGenerated',
|
|
20
|
-
{
|
|
20
|
+
{
|
|
21
|
+
cause,
|
|
22
|
+
code,
|
|
23
|
+
count: args.count,
|
|
24
|
+
height: args.height,
|
|
25
|
+
start: args.start,
|
|
26
|
+
},
|
|
21
27
|
];
|
|
22
28
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const asyncAuto = require('async/auto');
|
|
2
2
|
const asyncEach = require('async/each');
|
|
3
|
+
const asyncify = require('async/asyncify');
|
|
3
4
|
const asyncMapSeries = require('async/mapSeries');
|
|
4
5
|
const asyncRetry = require('async/retry');
|
|
5
6
|
const {authenticatedLndGrpc} = require('lightning');
|
|
@@ -17,6 +18,11 @@ const line = arr => arr.slice(1).map((_, i) => [i, i + 1]);
|
|
|
17
18
|
const pairs = n => n.map((x, i) => n.slice(i + 1).map(y => [x, y])).flat();
|
|
18
19
|
const started = all => all.filter(n => !!n.value).map(n => n.value);
|
|
19
20
|
|
|
21
|
+
// Stop nodes for cleanup, ignoring any failures to stop them
|
|
22
|
+
const stopNodes = (nodes, cbk) => {
|
|
23
|
+
return asyncEach(nodes, ({kill}, cbk) => kill({}, () => cbk()), cbk);
|
|
24
|
+
};
|
|
25
|
+
|
|
20
26
|
/** Spawn a cluster of nodes
|
|
21
27
|
|
|
22
28
|
When a channel capacity is specified, each node opens a channel of that size
|
|
@@ -66,8 +72,8 @@ module.exports = (args, cbk) => {
|
|
|
66
72
|
},
|
|
67
73
|
|
|
68
74
|
// Spawn nodes
|
|
69
|
-
spawn: ['validate',
|
|
70
|
-
return
|
|
75
|
+
spawn: ['validate', ({}, cbk) => {
|
|
76
|
+
return asyncRetry({interval, times: 25}, cbk => {
|
|
71
77
|
const spawning = [...Array(count(args.size))].map(() => {
|
|
72
78
|
return spawnLightningDocker({
|
|
73
79
|
generate_address: generateAddress,
|
|
@@ -76,111 +82,120 @@ module.exports = (args, cbk) => {
|
|
|
76
82
|
});
|
|
77
83
|
|
|
78
84
|
// Wait for every node to finish starting, even when one fails
|
|
79
|
-
|
|
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
|
-
}
|
|
85
|
+
return Promise.allSettled(spawning).then(spawned => {
|
|
86
|
+
const failure = spawned.find(n => n.status === 'rejected');
|
|
91
87
|
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
// Stop the nodes that started so they are not left running
|
|
89
|
+
if (!!failure) {
|
|
90
|
+
return stopNodes(started(spawned), () => cbk(failure.reason));
|
|
91
|
+
}
|
|
94
92
|
|
|
95
|
-
|
|
96
|
-
cert: lightningDocker.cert,
|
|
97
|
-
macaroon: lightningDocker.macaroon,
|
|
98
|
-
socket: lightningDocker.socket,
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
id,
|
|
103
|
-
lnd,
|
|
104
|
-
chain: {
|
|
105
|
-
addPeer: lightningDocker.add_chain_peer,
|
|
106
|
-
generateToAddress: lightningDocker.generate,
|
|
107
|
-
getBlockInfo: lightningDocker.get_block_info,
|
|
108
|
-
socket: lightningDocker.chain_socket,
|
|
109
|
-
},
|
|
110
|
-
generate: ({address, count}, cbk) => {
|
|
111
|
-
return generateBlocks({
|
|
112
|
-
address,
|
|
113
|
-
count,
|
|
114
|
-
lnd,
|
|
115
|
-
generate: lightningDocker.generate,
|
|
116
|
-
},
|
|
117
|
-
cbk);
|
|
118
|
-
},
|
|
119
|
-
kill: lightningDocker.kill,
|
|
120
|
-
public_key: id,
|
|
121
|
-
rpc: ({macaroon}) => {
|
|
122
|
-
const {lnd} = authenticatedLndGrpc({
|
|
123
|
-
macaroon,
|
|
124
|
-
cert: lightningDocker.cert,
|
|
125
|
-
socket: lightningDocker.socket,
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
return {lnd};
|
|
129
|
-
},
|
|
130
|
-
socket: lightningDocker.ln_socket,
|
|
131
|
-
tower: lightningDocker.tower_socket,
|
|
132
|
-
};
|
|
93
|
+
return cbk(null, started(spawned));
|
|
133
94
|
});
|
|
95
|
+
},
|
|
96
|
+
cbk);
|
|
97
|
+
}],
|
|
98
|
+
|
|
99
|
+
// Make an LND API object for each node, which throws for bad details
|
|
100
|
+
lnds: ['spawn', asyncify(({spawn}) => {
|
|
101
|
+
return spawn.map(lightningDocker => {
|
|
102
|
+
return authenticatedLndGrpc({
|
|
103
|
+
cert: lightningDocker.cert,
|
|
104
|
+
macaroon: lightningDocker.macaroon,
|
|
105
|
+
socket: lightningDocker.socket,
|
|
106
|
+
}).lnd;
|
|
134
107
|
});
|
|
108
|
+
})],
|
|
109
|
+
|
|
110
|
+
// Describe each node of the cluster
|
|
111
|
+
cluster: ['lnds', 'spawn', ({lnds, spawn}, cbk) => {
|
|
112
|
+
return cbk(null, spawn.map((lightningDocker, i) => {
|
|
113
|
+
const id = lightningDocker.public_key;
|
|
114
|
+
const lnd = lnds[i];
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
id,
|
|
118
|
+
lnd,
|
|
119
|
+
chain: {
|
|
120
|
+
addPeer: lightningDocker.add_chain_peer,
|
|
121
|
+
generateToAddress: lightningDocker.generate,
|
|
122
|
+
getBlockInfo: lightningDocker.get_block_info,
|
|
123
|
+
socket: lightningDocker.chain_socket,
|
|
124
|
+
},
|
|
125
|
+
generate: (args, cbk) => {
|
|
126
|
+
return generateBlocks({
|
|
127
|
+
lnd,
|
|
128
|
+
address: args.address,
|
|
129
|
+
count: args.count,
|
|
130
|
+
generate: lightningDocker.generate,
|
|
131
|
+
},
|
|
132
|
+
cbk);
|
|
133
|
+
},
|
|
134
|
+
kill: lightningDocker.kill,
|
|
135
|
+
public_key: id,
|
|
136
|
+
// Making the connection throws for a macaroon that is not valid
|
|
137
|
+
rpc: args => {
|
|
138
|
+
const {lnd} = authenticatedLndGrpc({
|
|
139
|
+
cert: lightningDocker.cert,
|
|
140
|
+
macaroon: args.macaroon,
|
|
141
|
+
socket: lightningDocker.socket,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
return {lnd};
|
|
145
|
+
},
|
|
146
|
+
socket: lightningDocker.ln_socket,
|
|
147
|
+
tower: lightningDocker.tower_socket,
|
|
148
|
+
};
|
|
149
|
+
}));
|
|
135
150
|
}],
|
|
136
151
|
|
|
137
152
|
// Connect nodes in the cluster to each other
|
|
138
|
-
connect: ['
|
|
139
|
-
return
|
|
153
|
+
connect: ['cluster', ({cluster}, cbk) => {
|
|
154
|
+
return asyncEach(pairs(cluster), (pair, cbk) => {
|
|
140
155
|
const [a, b] = pair.map(({chain}) => chain);
|
|
141
156
|
|
|
142
|
-
return
|
|
143
|
-
}
|
|
157
|
+
return a.addPeer({socket: b.socket}).then(() => cbk(), cbk);
|
|
158
|
+
},
|
|
159
|
+
cbk);
|
|
144
160
|
}],
|
|
145
161
|
|
|
146
162
|
// Open channels between neighboring nodes, one at a time
|
|
147
|
-
channels: ['
|
|
163
|
+
channels: ['cluster', 'connect', ({cluster}, cbk) => {
|
|
148
164
|
// Exit early when there is no channel capacity to create channels
|
|
149
165
|
if (!args.capacity) {
|
|
150
|
-
return [];
|
|
166
|
+
return cbk(null, []);
|
|
151
167
|
}
|
|
152
168
|
|
|
153
|
-
|
|
154
|
-
return
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
169
|
+
return asyncMapSeries(line(cluster), ([from, to], cbk) => {
|
|
170
|
+
return setupChannel({
|
|
171
|
+
capacity: args.capacity,
|
|
172
|
+
generate: cluster[from].generate,
|
|
173
|
+
lnd: cluster[from].lnd,
|
|
174
|
+
to: cluster[to],
|
|
175
|
+
},
|
|
176
|
+
(err, res) => {
|
|
177
|
+
if (!!err) {
|
|
178
|
+
return cbk(err);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return cbk(null, {
|
|
163
182
|
from,
|
|
164
183
|
to,
|
|
165
|
-
id:
|
|
166
|
-
transaction_id:
|
|
167
|
-
transaction_vout:
|
|
168
|
-
};
|
|
184
|
+
id: res.id,
|
|
185
|
+
transaction_id: res.transaction_id,
|
|
186
|
+
transaction_vout: res.transaction_vout,
|
|
187
|
+
});
|
|
169
188
|
});
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
await asyncEach(spawn, async ({kill}) => await kill({}));
|
|
173
|
-
|
|
174
|
-
throw err;
|
|
175
|
-
}
|
|
189
|
+
},
|
|
190
|
+
cbk);
|
|
176
191
|
}],
|
|
177
192
|
|
|
178
193
|
// Final set of nodes
|
|
179
|
-
nodes: ['channels', '
|
|
180
|
-
return {
|
|
194
|
+
nodes: ['channels', 'cluster', ({channels, cluster}, cbk) => {
|
|
195
|
+
return cbk(null, {
|
|
181
196
|
channels,
|
|
182
|
-
kill: ({}) => asyncEach(
|
|
183
|
-
nodes:
|
|
197
|
+
kill: ({}) => asyncEach(cluster, ({kill}, cbk) => kill({}, cbk)),
|
|
198
|
+
nodes: cluster.map(node => ({
|
|
184
199
|
generate: node.generate,
|
|
185
200
|
id: node.id,
|
|
186
201
|
kill: node.kill,
|
|
@@ -189,9 +204,18 @@ module.exports = (args, cbk) => {
|
|
|
189
204
|
socket: node.socket,
|
|
190
205
|
tower: node.tower,
|
|
191
206
|
})),
|
|
192
|
-
};
|
|
207
|
+
});
|
|
193
208
|
}],
|
|
194
209
|
},
|
|
195
|
-
|
|
210
|
+
(err, res) => {
|
|
211
|
+
// Stop the spawned nodes when the cluster cannot be set up
|
|
212
|
+
if (!!err && !!res && !!res.spawn) {
|
|
213
|
+
return stopNodes(res.spawn, () => {
|
|
214
|
+
return returnResult({reject, resolve}, cbk)(err);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return returnResult({reject, resolve, of: 'nodes'}, cbk)(err, res);
|
|
219
|
+
});
|
|
196
220
|
});
|
|
197
221
|
};
|
|
@@ -21,11 +21,11 @@ const typeOffset = 156;
|
|
|
21
21
|
[file]: <File Buffer Object>
|
|
22
22
|
}
|
|
23
23
|
*/
|
|
24
|
-
module.exports =
|
|
24
|
+
module.exports = args => {
|
|
25
25
|
let offset = 0;
|
|
26
26
|
|
|
27
|
-
while (offset + blockSize <= tar.length) {
|
|
28
|
-
const header = tar.subarray(offset, offset + blockSize);
|
|
27
|
+
while (offset + blockSize <= args.tar.length) {
|
|
28
|
+
const header = args.tar.subarray(offset, offset + blockSize);
|
|
29
29
|
|
|
30
30
|
// Exit early when hitting the end of archive marker
|
|
31
31
|
if (header.every(isZero)) {
|
|
@@ -37,7 +37,7 @@ module.exports = ({tar}) => {
|
|
|
37
37
|
|
|
38
38
|
// Exit early when this is a regular entry
|
|
39
39
|
if (!metaTypes.includes(fromCharCode(header[typeOffset]))) {
|
|
40
|
-
return {file: tar.subarray(start, start + size)};
|
|
40
|
+
return {file: args.tar.subarray(start, start + size)};
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
offset = start + ceil(size / blockSize) * blockSize;
|
package/docker/get_file.js
CHANGED
|
@@ -17,16 +17,16 @@ const {concat} = Buffer;
|
|
|
17
17
|
file: <File Buffer Object>
|
|
18
18
|
}
|
|
19
19
|
*/
|
|
20
|
-
module.exports = (
|
|
20
|
+
module.exports = (args, cbk) => {
|
|
21
21
|
return new Promise((resolve, reject) => {
|
|
22
22
|
return asyncAuto({
|
|
23
23
|
// Check arguments
|
|
24
24
|
validate: cbk => {
|
|
25
|
-
if (!container) {
|
|
25
|
+
if (!args.container) {
|
|
26
26
|
return cbk([400, 'ExpectedContainerToGetFileFromDockerContainer']);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
if (!path) {
|
|
29
|
+
if (!args.path) {
|
|
30
30
|
return cbk([400, 'ExpectedFilePathToGetFileFromDockerContainer']);
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -35,7 +35,7 @@ module.exports = ({container, path}, cbk) => {
|
|
|
35
35
|
|
|
36
36
|
// Get archive
|
|
37
37
|
getArchive: ['validate', ({}, cbk) => {
|
|
38
|
-
return container.getArchive({path}, (err, stream) => {
|
|
38
|
+
return args.container.getArchive({path: args.path}, (err, stream) => {
|
|
39
39
|
// Exit early when there are no files at the path
|
|
40
40
|
if (!!err && err.statusCode === 404) {
|
|
41
41
|
return cbk([404, 'FailedToFindFileAtPathInContainer']);
|
package/docker/kill_docker.js
CHANGED
|
@@ -12,12 +12,12 @@ const t = 1;
|
|
|
12
12
|
|
|
13
13
|
@returns via cbk or Promise
|
|
14
14
|
*/
|
|
15
|
-
module.exports = (
|
|
15
|
+
module.exports = (args, cbk) => {
|
|
16
16
|
return new Promise((resolve, reject) => {
|
|
17
17
|
return asyncAuto({
|
|
18
18
|
// Check arguments
|
|
19
19
|
validate: cbk => {
|
|
20
|
-
if (!container) {
|
|
20
|
+
if (!args.container) {
|
|
21
21
|
return cbk([400, 'ExpectedContainerToKillContainer']);
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -26,7 +26,7 @@ module.exports = ({container}, cbk) => {
|
|
|
26
26
|
|
|
27
27
|
// Stop the running image
|
|
28
28
|
stop: ['validate', ({}, cbk) => {
|
|
29
|
-
return container.stop({t}, err => {
|
|
29
|
+
return args.container.stop({t}, err => {
|
|
30
30
|
if (!!err && err.reason === errorAlreadyStopped) {
|
|
31
31
|
return cbk();
|
|
32
32
|
}
|
|
@@ -45,7 +45,7 @@ module.exports = ({container}, cbk) => {
|
|
|
45
45
|
|
|
46
46
|
// Remove the container
|
|
47
47
|
remove: ['stop', ({}, cbk) => {
|
|
48
|
-
return container.remove(err => {
|
|
48
|
+
return args.container.remove(err => {
|
|
49
49
|
// Exit early when the container is already gone
|
|
50
50
|
if (!!err && err.statusCode === 404) {
|
|
51
51
|
return cbk();
|