paid-services 3.11.3 → 3.11.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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Versions
2
2
 
3
- ## Version 3.11.3
3
+ ## Version 3.11.4
4
4
 
5
5
  - `changeChannelCapacity`: Add `nodes` to allow moving channel to another node
6
6
 
@@ -293,8 +293,22 @@ module.exports = (args, cbk) => {
293
293
  return cbk(null, newCapacity);
294
294
  }],
295
295
 
296
+ // Make sure that we are still connected to the original peer
297
+ confirmConnection: [
298
+ 'newCapacity',
299
+ 'pendingChannel',
300
+ ({pendingChannel}, cbk) =>
301
+ {
302
+ return connectPeer({
303
+ id: pendingChannel.partner_public_key,
304
+ lnd: args.open_lnd,
305
+ },
306
+ cbk);
307
+ }],
308
+
296
309
  // Propose the new channel to replace the existing one
297
310
  proposeChannel: [
311
+ 'confirmConnection',
298
312
  'newCapacity',
299
313
  'pendingChannel',
300
314
  ({newCapacity, pendingChannel}, cbk) =>
@@ -351,12 +351,24 @@ module.exports = (args, cbk) => {
351
351
 
352
352
  // Listen to new blocks to wait for the channel change confirmation
353
353
  const sub = subscribeToBlocks({lnd: args.lnd});
354
+ let isFinished = false;
354
355
 
355
- // Fail with error when the blocks subscription is lost
356
- sub.on('error', err => {
356
+ // Avoid multiple callbacks
357
+ const done = (err, res) => {
357
358
  sub.removeAllListeners();
358
359
 
359
- return cbk([503, 'LostBlockchainSubscription', {err}]);
360
+ if (isFinished) {
361
+ return;
362
+ }
363
+
364
+ isFinished = true;
365
+
366
+ return cbk(err, res);
367
+ };
368
+
369
+ // Fail with error when the blocks subscription is lost
370
+ sub.on('error', err => {
371
+ return done([503, 'LostBlockchainSubscription', {err}]);
360
372
  });
361
373
 
362
374
  // Publish the new channel transaction when a block is received
@@ -383,9 +395,7 @@ module.exports = (args, cbk) => {
383
395
 
384
396
  // The new channel confirmed successfully and so the change worked
385
397
  if (!!channel && !!channel.is_active) {
386
- sub.removeAllListeners();
387
-
388
- return cbk(null, {is_success: true});
398
+ return done(null, {is_success: true});
389
399
  }
390
400
  } catch (err) {
391
401
  args.logger.error({err});
@@ -419,9 +429,7 @@ module.exports = (args, cbk) => {
419
429
 
420
430
  // The old channel force closed and so the change fully failed
421
431
  if (!!channel && channel.close_transaction_id !== txId) {
422
- sub.removeAllListeners();
423
-
424
- return cbk(null, {is_success: false});
432
+ return done(null, {is_success: false});
425
433
  }
426
434
  } catch (err) {
427
435
  args.logger.error({err});
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "bolt07": "1.8.0",
14
14
  "ecpair": "2.0.1",
15
15
  "invoices": "2.0.4",
16
- "ln-service": "53.9.0",
16
+ "ln-service": "53.9.1",
17
17
  "ln-sync": "3.10.1",
18
18
  "tiny-secp256k1": "2.2.0"
19
19
  },
@@ -42,5 +42,5 @@
42
42
  "integration-tests": "tap -j 2 --branches=1 --functions=1 --lines=1 --statements=1 -t 180 test/integration/*.js",
43
43
  "test": "tap --branches=1 --functions=1 --lines=1 --statements=1 -t 60 test/actions/*.js test/capacity/*.js test/client/*.js test/config/*.js test/p2p/*.js test/records/*.js test/respond/*.js test/server/*.js test/server/*.js test/services/*.js test/trades/*.js"
44
44
  },
45
- "version": "3.11.3"
45
+ "version": "3.11.4"
46
46
  }
@@ -6,6 +6,7 @@ const {broadcastChainTransaction} = require('ln-service');
6
6
  const {closeChannel} = require('ln-service');
7
7
  const {createChainAddress} = require('ln-service');
8
8
  const {getChainTransactions} = require('ln-service');
9
+ const {getChannel} = require('ln-service');
9
10
  const {getChannels} = require('ln-service');
10
11
  const {getNetwork} = require('ln-sync');
11
12
  const {networks} = require('bitcoinjs-lib');
@@ -51,18 +52,30 @@ test(`Accept capacity replacement`, async ({end, equal, strictSame}) => {
51
52
 
52
53
  try {
53
54
  // Open up a new channel
54
- const channelOpen = await openChannel({
55
- lnd,
56
- local_tokens: capacity,
57
- partner_public_key: target.id,
58
- partner_socket: target.socket,
55
+ const channelOpen = await asyncRetry({interval, times}, async () => {
56
+ return await openChannel({
57
+ lnd,
58
+ local_tokens: capacity,
59
+ partner_public_key: target.id,
60
+ partner_socket: target.socket,
61
+ });
59
62
  });
60
63
 
61
64
  // Wait for the channel to be active
62
65
  const channel = await asyncRetry({interval, times}, async () => {
63
66
  const [channel] = (await getChannels({lnd})).channels;
64
67
 
65
- if (!!channel && !!channel.is_active) {
68
+ if (!channel) {
69
+ await generate({});
70
+
71
+ throw new Error('ExpectedInitialChannelActivation');
72
+ }
73
+
74
+ const {policies} = await getChannel({lnd, id: channel.id});
75
+
76
+ const [missingCltv] = policies.filter(n => !n.cltv_delta);
77
+
78
+ if (!!channel && !!channel.is_active && !missingCltv) {
66
79
  return channel;
67
80
  }
68
81
 
@@ -46,12 +46,14 @@ test(`Accept capacity replacement`, async ({end, equal, strictSame}) => {
46
46
 
47
47
  try {
48
48
  // Open up a new channel
49
- const channelOpen = await openChannel({
50
- lnd,
51
- is_private: true,
52
- local_tokens: capacity,
53
- partner_public_key: target.id,
54
- partner_socket: target.socket,
49
+ const channelOpen = await asyncRetry({interval, times}, async () => {
50
+ return await openChannel({
51
+ lnd,
52
+ is_private: true,
53
+ local_tokens: capacity,
54
+ partner_public_key: target.id,
55
+ partner_socket: target.socket,
56
+ });
55
57
  });
56
58
 
57
59
  // Wait for the channel to be active