ln-docker-daemons 8.1.3 → 8.1.4
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/check_generated.js +0 -7
- package/bitcoinrpc/generate_to_address.js +15 -15
- package/bitcoinrpc/mine_blocks.js +35 -24
- package/bitcoinrpc/rpc.js +20 -20
- package/cluster/spawn_lightning_cluster.js +98 -87
- package/docker/spawn_docker_image.js +13 -10
- package/lnd/constants.json +1 -1
- package/package.json +2 -2
- package/setup/setup_channel.js +65 -28
- package/setup/wait_for_channel.js +30 -20
|
@@ -13,13 +13,6 @@ const txVerbosityFlag = 2;
|
|
|
13
13
|
|
|
14
14
|
/** Check what blocks a failed generate request made
|
|
15
15
|
|
|
16
|
-
Generate requests run one at a time, so blocks on top of the start height
|
|
17
|
-
can only be from this request, unless they were mined outside this process.
|
|
18
|
-
They must all pay to the address, and there can't be more than requested.
|
|
19
|
-
|
|
20
|
-
A request that may still be running is given time to finish mining. When a
|
|
21
|
-
request finished without mining anything, its original error is returned.
|
|
22
|
-
|
|
23
16
|
{
|
|
24
17
|
address: <Coinbase Output Address String>
|
|
25
18
|
count: <Requested Blocks Count Number>
|
|
@@ -8,12 +8,10 @@ const queue = asyncQueue(mineBlocks, 1);
|
|
|
8
8
|
|
|
9
9
|
/** Generate blocks and mine coinbase outputs to an address
|
|
10
10
|
|
|
11
|
-
Requests run one at a time. When the outcome of a request is unclear, blocks
|
|
12
|
-
on top of where it started can then only be from that request, unless they
|
|
13
|
-
were mined outside of this process.
|
|
14
|
-
|
|
15
11
|
{
|
|
16
12
|
address: <Address to Mine Outputs Towards String>
|
|
13
|
+
[check_interval]: <Unclear Outcome Poll Interval Milliseconds Number>
|
|
14
|
+
[check_times]: <Unclear Outcome Poll Times Number>
|
|
17
15
|
[count]: <Generate Count Number>
|
|
18
16
|
pass: <RPC Password String>
|
|
19
17
|
port: <RPC Port Number>
|
|
@@ -23,38 +21,40 @@ const queue = asyncQueue(mineBlocks, 1);
|
|
|
23
21
|
@returns via cbk or Promise
|
|
24
22
|
[<Generated Block Hash Hex String>]
|
|
25
23
|
*/
|
|
26
|
-
module.exports = (
|
|
24
|
+
module.exports = (args, cbk) => {
|
|
27
25
|
return new Promise((resolve, reject) => {
|
|
28
26
|
return asyncAuto({
|
|
29
27
|
// Check arguments
|
|
30
28
|
validate: cbk => {
|
|
31
|
-
if (!address) {
|
|
29
|
+
if (!args.address) {
|
|
32
30
|
return cbk([400, 'ExpectedAddressToGenerateToAddress']);
|
|
33
31
|
}
|
|
34
32
|
|
|
35
|
-
if (!pass) {
|
|
33
|
+
if (!args.pass) {
|
|
36
34
|
return cbk([400, 'ExpectedRpcPasswordToGenerateToAddress']);
|
|
37
35
|
}
|
|
38
36
|
|
|
39
|
-
if (!port) {
|
|
37
|
+
if (!args.port) {
|
|
40
38
|
return cbk([400, 'ExpectedRpcPortNumberToGenerateToAddress']);
|
|
41
39
|
}
|
|
42
40
|
|
|
43
|
-
if (!user) {
|
|
41
|
+
if (!args.user) {
|
|
44
42
|
return cbk([400, 'ExpectedRpcUsernameToGenerateToAddresss']);
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
return cbk();
|
|
48
46
|
},
|
|
49
47
|
|
|
50
|
-
// Mine
|
|
48
|
+
// Mine after earlier requests so that new blocks are from this request
|
|
51
49
|
generate: ['validate', ({}, cbk) => {
|
|
52
50
|
return queue.push({
|
|
53
|
-
address,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
address: args.address,
|
|
52
|
+
check_interval: args.check_interval,
|
|
53
|
+
check_times: args.check_times,
|
|
54
|
+
count: args.count || [args.address].length,
|
|
55
|
+
pass: args.pass,
|
|
56
|
+
port: args.port,
|
|
57
|
+
user: args.user,
|
|
58
58
|
},
|
|
59
59
|
cbk);
|
|
60
60
|
}],
|
|
@@ -6,10 +6,10 @@ 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
|
|
10
|
+
const defaultCheckInterval = 100;
|
|
11
|
+
const defaultCheckTimes = 100;
|
|
12
|
+
const hasResponse = err => isCommandError(err) || !!err[2].status;
|
|
13
13
|
const host = 'localhost';
|
|
14
14
|
const isCommandError = err => err[1] === 'UnexpectedErrorFromRpcCommand';
|
|
15
15
|
const isDisconnected = err => isUnsent(err) || isLost(err);
|
|
@@ -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,4 +1,5 @@
|
|
|
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;
|
|
@@ -25,10 +26,6 @@ const unsentCodes = ['ECONNREFUSED', 'UND_ERR_CONNECT_TIMEOUT'];
|
|
|
25
26
|
user: <Username String>
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
ConnectionToBitcoindRpcServiceFailed means the request never reached the
|
|
29
|
-
server. ConnectionToBitcoindRpcServiceLost and TimedOutWaitingForRpcResponse
|
|
30
|
-
mean the server may have executed the command.
|
|
31
|
-
|
|
32
29
|
@returns via cbk or Promise
|
|
33
30
|
<Result Object>
|
|
34
31
|
*/
|
|
@@ -69,9 +66,7 @@ module.exports = ({cmd, host, params, pass, port, timeout, user}, cbk) => {
|
|
|
69
66
|
const controller = new AbortController();
|
|
70
67
|
const credentials = Buffer.from(`${user}:${pass}`);
|
|
71
68
|
|
|
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.
|
|
69
|
+
// Unlike AbortSignal.timeout, this timer keeps the process alive
|
|
75
70
|
const timer = setTimeout(() => {
|
|
76
71
|
return controller.abort(new DOMException(timeoutMessage, timedOut));
|
|
77
72
|
},
|
|
@@ -88,11 +83,15 @@ module.exports = ({cmd, host, params, pass, port, timeout, user}, cbk) => {
|
|
|
88
83
|
signal: controller.signal,
|
|
89
84
|
});
|
|
90
85
|
|
|
91
|
-
|
|
86
|
+
const body = await response.text();
|
|
87
|
+
|
|
88
|
+
clearTimeout(timer);
|
|
89
|
+
|
|
90
|
+
return {body, statusCode: response.status};
|
|
92
91
|
} catch (err) {
|
|
93
|
-
return {err};
|
|
94
|
-
} finally {
|
|
95
92
|
clearTimeout(timer);
|
|
93
|
+
|
|
94
|
+
return {err};
|
|
96
95
|
}
|
|
97
96
|
}],
|
|
98
97
|
|
|
@@ -105,6 +104,7 @@ module.exports = ({cmd, host, params, pass, port, timeout, user}, cbk) => {
|
|
|
105
104
|
return cbk();
|
|
106
105
|
}
|
|
107
106
|
|
|
107
|
+
// The request timed out so the command may have been executed
|
|
108
108
|
if (isTimeout(err)) {
|
|
109
109
|
return cbk([503, 'TimedOutWaitingForRpcResponse', {cmd}]);
|
|
110
110
|
}
|
|
@@ -138,22 +138,22 @@ module.exports = ({cmd, host, params, pass, port, timeout, user}, cbk) => {
|
|
|
138
138
|
}],
|
|
139
139
|
|
|
140
140
|
// Parse the response body as a JSON-RPC response object
|
|
141
|
-
parseBody: ['checkRequest', 'request', ({request}
|
|
141
|
+
parseBody: ['checkRequest', 'request', asyncify(({request}) => {
|
|
142
142
|
const details = {cmd, status: request.statusCode};
|
|
143
|
-
let body;
|
|
144
143
|
|
|
145
144
|
try {
|
|
146
|
-
body = parse(request.body);
|
|
147
|
-
} catch (err) {
|
|
148
|
-
return cbk([503, 'FailedToParseRpcServiceResponse', details]);
|
|
149
|
-
}
|
|
145
|
+
const body = parse(request.body);
|
|
150
146
|
|
|
151
|
-
|
|
152
|
-
|
|
147
|
+
if (!!body && typeof body === 'object') {
|
|
148
|
+
return body;
|
|
149
|
+
}
|
|
150
|
+
} catch (err) {
|
|
151
|
+
throw [503, 'FailedToParseRpcServiceResponse', details];
|
|
153
152
|
}
|
|
154
153
|
|
|
155
|
-
|
|
156
|
-
|
|
154
|
+
// The body is JSON but not an object, such as null or a number
|
|
155
|
+
throw [503, 'UnexpectedRpcServiceResponse', details];
|
|
156
|
+
})],
|
|
157
157
|
|
|
158
158
|
// Check the response for a command failure and pull out the result
|
|
159
159
|
result: ['parseBody', 'request', ({parseBody, request}, cbk) => {
|
|
@@ -17,6 +17,11 @@ const line = arr => arr.slice(1).map((_, i) => [i, i + 1]);
|
|
|
17
17
|
const pairs = n => n.map((x, i) => n.slice(i + 1).map(y => [x, y])).flat();
|
|
18
18
|
const started = all => all.filter(n => !!n.value).map(n => n.value);
|
|
19
19
|
|
|
20
|
+
// Stop nodes for cleanup, ignoring any failures to stop them
|
|
21
|
+
const stopNodes = (nodes, cbk) => {
|
|
22
|
+
return asyncEach(nodes, ({kill}, cbk) => kill({}, () => cbk()), cbk);
|
|
23
|
+
};
|
|
24
|
+
|
|
20
25
|
/** Spawn a cluster of nodes
|
|
21
26
|
|
|
22
27
|
When a channel capacity is specified, each node opens a channel of that size
|
|
@@ -66,8 +71,8 @@ module.exports = (args, cbk) => {
|
|
|
66
71
|
},
|
|
67
72
|
|
|
68
73
|
// Spawn nodes
|
|
69
|
-
spawn: ['validate',
|
|
70
|
-
return
|
|
74
|
+
spawn: ['validate', ({}, cbk) => {
|
|
75
|
+
return asyncRetry({interval, times: 25}, cbk => {
|
|
71
76
|
const spawning = [...Array(count(args.size))].map(() => {
|
|
72
77
|
return spawnLightningDocker({
|
|
73
78
|
generate_address: generateAddress,
|
|
@@ -76,110 +81,107 @@ module.exports = (args, cbk) => {
|
|
|
76
81
|
});
|
|
77
82
|
|
|
78
83
|
// Wait for every node to finish starting, even when one fails
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
count,
|
|
114
|
-
lnd,
|
|
115
|
-
generate: lightningDocker.generate,
|
|
84
|
+
return Promise.allSettled(spawning).then(spawned => {
|
|
85
|
+
const failure = spawned.find(n => n.status === 'rejected');
|
|
86
|
+
|
|
87
|
+
// Stop the nodes that started so they are not left running
|
|
88
|
+
if (!!failure) {
|
|
89
|
+
return stopNodes(started(spawned), () => cbk(failure.reason));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return cbk(null, started(spawned).map(lightningDocker => {
|
|
93
|
+
const id = lightningDocker.public_key;
|
|
94
|
+
|
|
95
|
+
const {lnd} = authenticatedLndGrpc({
|
|
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);
|
|
116
118
|
},
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
};
|
|
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
|
+
};
|
|
133
|
+
}));
|
|
133
134
|
});
|
|
134
|
-
}
|
|
135
|
+
},
|
|
136
|
+
cbk);
|
|
135
137
|
}],
|
|
136
138
|
|
|
137
139
|
// Connect nodes in the cluster to each other
|
|
138
|
-
connect: ['spawn',
|
|
139
|
-
return
|
|
140
|
+
connect: ['spawn', ({spawn}, cbk) => {
|
|
141
|
+
return asyncEach(pairs(spawn), (pair, cbk) => {
|
|
140
142
|
const [a, b] = pair.map(({chain}) => chain);
|
|
141
143
|
|
|
142
|
-
return
|
|
143
|
-
}
|
|
144
|
+
return a.addPeer({socket: b.socket}).then(() => cbk(), cbk);
|
|
145
|
+
},
|
|
146
|
+
cbk);
|
|
144
147
|
}],
|
|
145
148
|
|
|
146
149
|
// Open channels between neighboring nodes, one at a time
|
|
147
|
-
channels: ['connect', 'spawn',
|
|
150
|
+
channels: ['connect', 'spawn', ({spawn}, cbk) => {
|
|
148
151
|
// Exit early when there is no channel capacity to create channels
|
|
149
152
|
if (!args.capacity) {
|
|
150
|
-
return [];
|
|
153
|
+
return cbk(null, []);
|
|
151
154
|
}
|
|
152
155
|
|
|
153
|
-
|
|
154
|
-
return
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
156
|
+
return asyncMapSeries(line(spawn), ([from, to], cbk) => {
|
|
157
|
+
return setupChannel({
|
|
158
|
+
capacity: args.capacity,
|
|
159
|
+
generate: spawn[from].generate,
|
|
160
|
+
lnd: spawn[from].lnd,
|
|
161
|
+
to: spawn[to],
|
|
162
|
+
},
|
|
163
|
+
(err, res) => {
|
|
164
|
+
if (!!err) {
|
|
165
|
+
return cbk(err);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return cbk(null, {
|
|
163
169
|
from,
|
|
164
170
|
to,
|
|
165
|
-
id:
|
|
166
|
-
transaction_id:
|
|
167
|
-
transaction_vout:
|
|
168
|
-
};
|
|
171
|
+
id: res.id,
|
|
172
|
+
transaction_id: res.transaction_id,
|
|
173
|
+
transaction_vout: res.transaction_vout,
|
|
174
|
+
});
|
|
169
175
|
});
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
await asyncEach(spawn, async ({kill}) => await kill({}));
|
|
173
|
-
|
|
174
|
-
throw err;
|
|
175
|
-
}
|
|
176
|
+
},
|
|
177
|
+
cbk);
|
|
176
178
|
}],
|
|
177
179
|
|
|
178
180
|
// Final set of nodes
|
|
179
|
-
nodes: ['channels', 'connect', 'spawn',
|
|
180
|
-
return {
|
|
181
|
+
nodes: ['channels', 'connect', 'spawn', ({channels, spawn}, cbk) => {
|
|
182
|
+
return cbk(null, {
|
|
181
183
|
channels,
|
|
182
|
-
kill: ({}) => asyncEach(spawn,
|
|
184
|
+
kill: ({}) => asyncEach(spawn, ({kill}, cbk) => kill({}, cbk)),
|
|
183
185
|
nodes: spawn.map(node => ({
|
|
184
186
|
generate: node.generate,
|
|
185
187
|
id: node.id,
|
|
@@ -189,9 +191,18 @@ module.exports = (args, cbk) => {
|
|
|
189
191
|
socket: node.socket,
|
|
190
192
|
tower: node.tower,
|
|
191
193
|
})),
|
|
192
|
-
};
|
|
194
|
+
});
|
|
193
195
|
}],
|
|
194
196
|
},
|
|
195
|
-
|
|
197
|
+
(err, res) => {
|
|
198
|
+
// Stop the spawned nodes when the cluster cannot be set up
|
|
199
|
+
if (!!err && !!res && !!res.spawn) {
|
|
200
|
+
return stopNodes(res.spawn, () => {
|
|
201
|
+
return returnResult({reject, resolve}, cbk)(err);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return returnResult({reject, resolve, of: 'nodes'}, cbk)(err, res);
|
|
206
|
+
});
|
|
196
207
|
});
|
|
197
208
|
};
|
|
@@ -61,20 +61,23 @@ module.exports = ({arguments, expose, image, ports}, cbk) => {
|
|
|
61
61
|
docker: ['validate', ({}, cbk) => cbk(null, new Dockerode({}))],
|
|
62
62
|
|
|
63
63
|
// Check if the image is cached
|
|
64
|
-
getImage: ['docker',
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return;
|
|
64
|
+
getImage: ['docker', ({docker}, cbk) => {
|
|
65
|
+
return docker.getImage(image).inspect((err, res) => {
|
|
66
|
+
// Exit early when the image is not cached
|
|
67
|
+
if (!!err && err.statusCode === 404) {
|
|
68
|
+
return cbk();
|
|
70
69
|
}
|
|
71
70
|
|
|
72
|
-
if (err.code === 'ECONNREFUSED') {
|
|
73
|
-
|
|
71
|
+
if (!!err && err.code === 'ECONNREFUSED') {
|
|
72
|
+
return cbk([503, 'CannotConnectToDockerDaemon']);
|
|
74
73
|
}
|
|
75
74
|
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
if (!!err) {
|
|
76
|
+
return cbk([503, 'UnexpectedErrorGettingDockerImage', {err}]);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return cbk(null, res);
|
|
80
|
+
});
|
|
78
81
|
}],
|
|
79
82
|
|
|
80
83
|
// Pull the docker image
|
package/lnd/constants.json
CHANGED
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"async": "3.2.6",
|
|
16
16
|
"asyncjs-util": "1.2.12",
|
|
17
17
|
"dockerode": "5.0.1",
|
|
18
|
-
"lightning": "13.1.
|
|
18
|
+
"lightning": "13.1.10"
|
|
19
19
|
},
|
|
20
20
|
"description": "Spawn and control LN Docker daemons",
|
|
21
21
|
"engines": {
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"integration-tests": "node --test \"test/integration/*.js\"",
|
|
46
46
|
"test": "node --experimental-test-coverage --test \"test/!(integration)/**/*.js\""
|
|
47
47
|
},
|
|
48
|
-
"version": "8.1.
|
|
48
|
+
"version": "8.1.4"
|
|
49
49
|
}
|
package/setup/setup_channel.js
CHANGED
|
@@ -17,6 +17,13 @@ const defaultDelay = 1;
|
|
|
17
17
|
const interval = 100;
|
|
18
18
|
const times = 1500;
|
|
19
19
|
|
|
20
|
+
// Generate blocks, passing back a failure without async wrapping it
|
|
21
|
+
const generateBlocks = ({generate, request}, cbk) => {
|
|
22
|
+
return Promise.resolve()
|
|
23
|
+
.then(() => generate(request))
|
|
24
|
+
.then(() => cbk(), cbk);
|
|
25
|
+
};
|
|
26
|
+
|
|
20
27
|
/** Setup channel
|
|
21
28
|
|
|
22
29
|
{
|
|
@@ -43,40 +50,66 @@ module.exports = (args, cbk) => {
|
|
|
43
50
|
return new Promise((resolve, reject) => {
|
|
44
51
|
return asyncAuto({
|
|
45
52
|
// Make sure the node is connected
|
|
46
|
-
addPeer:
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
addPeer: cbk => {
|
|
54
|
+
return asyncRetry({interval, times}, cbk => {
|
|
55
|
+
return generateBlocks({
|
|
56
|
+
generate: args.generate,
|
|
57
|
+
request: {},
|
|
58
|
+
},
|
|
59
|
+
err => {
|
|
60
|
+
if (!!err) {
|
|
61
|
+
return cbk(err);
|
|
62
|
+
}
|
|
49
63
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
64
|
+
return addPeer({
|
|
65
|
+
lnd: args.lnd,
|
|
66
|
+
public_key: args.to.id || args.to.public_key,
|
|
67
|
+
retry_count: defaultRetryCount,
|
|
68
|
+
retry_delay: defaultDelay,
|
|
69
|
+
socket: args.to.socket,
|
|
70
|
+
},
|
|
71
|
+
cbk);
|
|
56
72
|
});
|
|
57
|
-
}
|
|
73
|
+
},
|
|
74
|
+
cbk);
|
|
58
75
|
},
|
|
59
76
|
|
|
60
77
|
// Make sure the node has funds
|
|
61
|
-
generateFunds:
|
|
78
|
+
generateFunds: ['addPeer', ({}, cbk) => {
|
|
79
|
+
return generateBlocks({
|
|
80
|
+
generate: args.generate,
|
|
81
|
+
request: {count},
|
|
82
|
+
},
|
|
83
|
+
cbk);
|
|
84
|
+
}],
|
|
62
85
|
|
|
63
86
|
// Open channel
|
|
64
|
-
chanOpen:
|
|
65
|
-
return
|
|
66
|
-
|
|
87
|
+
chanOpen: ['generateFunds', ({}, cbk) => {
|
|
88
|
+
return asyncRetry({interval, times}, cbk => {
|
|
89
|
+
return generateBlocks({
|
|
90
|
+
generate: args.generate,
|
|
91
|
+
request: {},
|
|
92
|
+
},
|
|
93
|
+
err => {
|
|
94
|
+
if (!!err) {
|
|
95
|
+
return cbk(err);
|
|
96
|
+
}
|
|
67
97
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
98
|
+
return openChannel({
|
|
99
|
+
chain_fee_tokens_per_vbyte: defaultFee,
|
|
100
|
+
give_tokens: args.give_tokens,
|
|
101
|
+
is_private: args.is_private,
|
|
102
|
+
lnd: args.lnd,
|
|
103
|
+
local_tokens: args.capacity || channelCapacityTokens,
|
|
104
|
+
partner_csv_delay: args.partner_csv_delay,
|
|
105
|
+
partner_public_key: args.to.public_key || args.to.id,
|
|
106
|
+
socket: args.to.socket,
|
|
107
|
+
},
|
|
108
|
+
cbk);
|
|
77
109
|
});
|
|
78
|
-
}
|
|
79
|
-
|
|
110
|
+
},
|
|
111
|
+
cbk);
|
|
112
|
+
}],
|
|
80
113
|
|
|
81
114
|
// Wait for pending
|
|
82
115
|
waitPending: ['chanOpen', ({chanOpen}, cbk) => {
|
|
@@ -88,12 +121,16 @@ module.exports = (args, cbk) => {
|
|
|
88
121
|
}],
|
|
89
122
|
|
|
90
123
|
// Generate blocks to confirm the pending channel
|
|
91
|
-
generate: ['waitPending',
|
|
92
|
-
return
|
|
124
|
+
generate: ['waitPending', ({}, cbk) => {
|
|
125
|
+
return generateBlocks({
|
|
126
|
+
generate: args.generate,
|
|
127
|
+
request: {count: confCount},
|
|
128
|
+
},
|
|
129
|
+
cbk);
|
|
93
130
|
}],
|
|
94
131
|
|
|
95
132
|
// Wait for open
|
|
96
|
-
channel: ['chanOpen', ({chanOpen}, cbk) => {
|
|
133
|
+
channel: ['chanOpen', 'generate', ({chanOpen}, cbk) => {
|
|
97
134
|
return waitForChannel({
|
|
98
135
|
id: chanOpen.transaction_id,
|
|
99
136
|
lnd: args.lnd,
|
|
@@ -60,35 +60,45 @@ module.exports = (args, cbk) => {
|
|
|
60
60
|
},
|
|
61
61
|
|
|
62
62
|
// Find channel in channels list
|
|
63
|
-
channel: ['validate',
|
|
64
|
-
return
|
|
65
|
-
|
|
63
|
+
channel: ['validate', ({}, cbk) => {
|
|
64
|
+
return asyncRetry({interval, times}, cbk => {
|
|
65
|
+
return getChannels({lnd: args.lnd}, (err, res) => {
|
|
66
|
+
if (!!err) {
|
|
67
|
+
return cbk(err);
|
|
68
|
+
}
|
|
66
69
|
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
const chan = res.channels.find(channel => {
|
|
71
|
+
const isFunding = channel.transaction_id === args.id;
|
|
69
72
|
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
return isFunding && channel.transaction_vout === args.vout;
|
|
74
|
+
});
|
|
72
75
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
if (!chan) {
|
|
77
|
+
return cbk([503, 'FailedToFindChannelWithTransactionId']);
|
|
78
|
+
}
|
|
76
79
|
|
|
77
|
-
|
|
78
|
-
|
|
80
|
+
return cbk(null, chan);
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
cbk);
|
|
79
84
|
}],
|
|
80
85
|
|
|
81
86
|
// Check channel fully created
|
|
82
|
-
gotChannel: ['channel',
|
|
83
|
-
return
|
|
84
|
-
|
|
87
|
+
gotChannel: ['channel', ({channel}, cbk) => {
|
|
88
|
+
return asyncRetry({interval, times}, cbk => {
|
|
89
|
+
return getChannel({id: channel.id, lnd: args.lnd}, (err, res) => {
|
|
90
|
+
if (!!err) {
|
|
91
|
+
return cbk(err);
|
|
92
|
+
}
|
|
85
93
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
94
|
+
if (!!res.policies.find(n => !n.cltv_delta)) {
|
|
95
|
+
return cbk([503, 'FailedToFindChannelWithFullPolicyDetails']);
|
|
96
|
+
}
|
|
89
97
|
|
|
90
|
-
|
|
91
|
-
|
|
98
|
+
return cbk();
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
cbk);
|
|
92
102
|
}],
|
|
93
103
|
},
|
|
94
104
|
returnResult({reject, resolve, of: 'channel'}, cbk));
|