ln-docker-daemons 8.1.2 → 8.1.3
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.
|
@@ -18,6 +18,7 @@ const deriveHmac = (s, p) => createHmac('sha256', s).update(p).digest('hex');
|
|
|
18
18
|
const generateAuthSalt = () => randomBytes(16).toString('hex');
|
|
19
19
|
const generatePassword = () => randomBytes(32).toString('base64');
|
|
20
20
|
const interval = 100;
|
|
21
|
+
const readyCheckTimeout = 1000 * 5;
|
|
21
22
|
const times = 100;
|
|
22
23
|
const trim = string => string.replace(/=+$/g, '');
|
|
23
24
|
const zmqBlockPort = args => args.zmq_block_port || defaultZmqBlockPort;
|
|
@@ -106,9 +107,11 @@ module.exports = (args, cbk) => {
|
|
|
106
107
|
({generateAuth, spawnDocker}, cbk) =>
|
|
107
108
|
{
|
|
108
109
|
return asyncRetry({interval, times}, cbk => {
|
|
110
|
+
// A check that hangs is retried rather than waited on for long
|
|
109
111
|
return getBlockchainInfo({
|
|
110
112
|
pass: generateAuth.rpc_pass,
|
|
111
113
|
port: spawnDocker.ports['18443/tcp'],
|
|
114
|
+
timeout: readyCheckTimeout,
|
|
112
115
|
user: rpcUser,
|
|
113
116
|
},
|
|
114
117
|
cbk);
|
|
@@ -12,6 +12,7 @@ const params = [];
|
|
|
12
12
|
{
|
|
13
13
|
pass: <RPC Password String>
|
|
14
14
|
port: <RPC Port Number>
|
|
15
|
+
[timeout]: <Request Timeout Milliseconds Number>
|
|
15
16
|
user: <RPC Username String>
|
|
16
17
|
}
|
|
17
18
|
|
|
@@ -20,7 +21,7 @@ const params = [];
|
|
|
20
21
|
blocks: <Best Chain Block Height Number>
|
|
21
22
|
}
|
|
22
23
|
*/
|
|
23
|
-
module.exports = ({pass, port, user}, cbk) => {
|
|
24
|
+
module.exports = ({pass, port, timeout, user}, cbk) => {
|
|
24
25
|
return new Promise((resolve, reject) => {
|
|
25
26
|
return asyncAuto({
|
|
26
27
|
// Check arguments
|
|
@@ -42,7 +43,7 @@ module.exports = ({pass, port, user}, cbk) => {
|
|
|
42
43
|
|
|
43
44
|
// Execute request
|
|
44
45
|
request: ['validate', ({}, cbk) => {
|
|
45
|
-
return rpc({cmd, host, pass, params, port, user}, cbk);
|
|
46
|
+
return rpc({cmd, host, pass, params, port, timeout, user}, cbk);
|
|
46
47
|
}],
|
|
47
48
|
},
|
|
48
49
|
returnResult({reject, resolve, of: 'request'}, cbk));
|
package/bitcoinrpc/rpc.js
CHANGED
|
@@ -9,6 +9,8 @@ const lostCodes = ['ECONNRESET', 'EPIPE', 'UND_ERR_CLOSED', 'UND_ERR_SOCKET'];
|
|
|
9
9
|
const {parse} = JSON;
|
|
10
10
|
let requests = 0;
|
|
11
11
|
const {stringify} = JSON;
|
|
12
|
+
const timedOut = 'TimeoutError';
|
|
13
|
+
const timeoutMessage = 'The operation was aborted due to timeout';
|
|
12
14
|
const unsentCodes = ['ECONNREFUSED', 'UND_ERR_CONNECT_TIMEOUT'];
|
|
13
15
|
|
|
14
16
|
/** Call JSON RPC
|
|
@@ -64,8 +66,17 @@ module.exports = ({cmd, host, params, pass, port, timeout, user}, cbk) => {
|
|
|
64
66
|
|
|
65
67
|
// Send request to the server, failures are returned rather than thrown
|
|
66
68
|
request: ['validate', async ({}) => {
|
|
69
|
+
const controller = new AbortController();
|
|
67
70
|
const credentials = Buffer.from(`${user}:${pass}`);
|
|
68
71
|
|
|
72
|
+
// This timer keeps the process alive until the request settles.
|
|
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.
|
|
75
|
+
const timer = setTimeout(() => {
|
|
76
|
+
return controller.abort(new DOMException(timeoutMessage, timedOut));
|
|
77
|
+
},
|
|
78
|
+
timeout || defaultTimeout);
|
|
79
|
+
|
|
69
80
|
try {
|
|
70
81
|
const response = await fetch(`http://${host}:${port}/`, {
|
|
71
82
|
body: stringify({params, id: `${++requests}`, method: cmd}),
|
|
@@ -74,12 +85,14 @@ module.exports = ({cmd, host, params, pass, port, timeout, user}, cbk) => {
|
|
|
74
85
|
'Content-Type': 'application/json',
|
|
75
86
|
},
|
|
76
87
|
method: 'POST',
|
|
77
|
-
signal:
|
|
88
|
+
signal: controller.signal,
|
|
78
89
|
});
|
|
79
90
|
|
|
80
91
|
return {body: await response.text(), statusCode: response.status};
|
|
81
92
|
} catch (err) {
|
|
82
93
|
return {err};
|
|
94
|
+
} finally {
|
|
95
|
+
clearTimeout(timer);
|
|
83
96
|
}
|
|
84
97
|
}],
|
|
85
98
|
|
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.6"
|
|
19
19
|
},
|
|
20
20
|
"description": "Spawn and control LN Docker daemons",
|
|
21
21
|
"engines": {
|
|
@@ -42,7 +42,8 @@
|
|
|
42
42
|
"url": "git+https://github.com/alexbosworth/ln-docker-daemons.git"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
|
-
"
|
|
45
|
+
"integration-tests": "node --test \"test/integration/*.js\"",
|
|
46
|
+
"test": "node --experimental-test-coverage --test \"test/!(integration)/**/*.js\""
|
|
46
47
|
},
|
|
47
|
-
"version": "8.1.
|
|
48
|
+
"version": "8.1.3"
|
|
48
49
|
}
|