paid-services 5.0.0 → 5.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Versions
2
2
 
3
+ ## Version 5.0.2
4
+
5
+ - `createGroupChannel`, `joinGroupChannel`, `manageGroupJoin`: Double check
6
+ open channel acceptance when peering
7
+
3
8
  ## Version 5.0.0
4
9
 
5
10
  - 'createGroupChannel': Repeatedly broadcast chain transaction
@@ -1,5 +1,6 @@
1
1
  const asyncAuto = require('async/auto');
2
2
  const asyncRetry = require('async/retry');
3
+ const asyncTimeout = require('async/timeout');
3
4
  const {connectPeer} = require('ln-sync');
4
5
  const {getChainBalance} = require('ln-service');
5
6
  const {getNodeAlias} = require('ln-sync');
@@ -8,6 +9,7 @@ const {returnResult} = require('asyncjs-util');
8
9
  const {getGroupDetails} = require('./p2p');
9
10
 
10
11
  const coordinatorFromJoinCode = n => n.slice(0, 66);
12
+ const defaultConnectRetryMs = 1000 * 60;
11
13
  const groupIdFromJoinCode = n => n.slice(66);
12
14
  const interval = 500;
13
15
  const isCode = n => !!n && n.length === 98;
@@ -77,7 +79,11 @@ module.exports = ({ask, lnd}, cbk) => {
77
79
  // Connect to the coordinator
78
80
  connect: ['group', ({group}, cbk) => {
79
81
  return asyncRetry({interval, times}, cbk => {
80
- return connectPeer({lnd, id: group.coordinator}, cbk);
82
+ return asyncTimeout(connectPeer, defaultConnectRetryMs)({
83
+ lnd,
84
+ id: group.coordinator,
85
+ },
86
+ cbk);
81
87
  },
82
88
  cbk);
83
89
  }],
@@ -88,11 +94,14 @@ module.exports = ({ask, lnd}, cbk) => {
88
94
  }],
89
95
 
90
96
  // Get the group details from the coordinator
91
- getDetails: ['group', ({group}, cbk) => {
92
- return getGroupDetails({
93
- lnd,
94
- coordinator: group.coordinator,
95
- id: group.id,
97
+ getDetails: ['connect', 'group', ({group}, cbk) => {
98
+ return asyncRetry({interval, times}, cbk => {
99
+ return asyncTimeout(getGroupDetails, defaultConnectRetryMs)({
100
+ lnd,
101
+ coordinator: group.coordinator,
102
+ id: group.id,
103
+ },
104
+ cbk);
96
105
  },
97
106
  cbk);
98
107
  }],
@@ -104,16 +104,20 @@ module.exports = ({capacity, count, ecp, identity, lnd, members, rate}) => {
104
104
  coordinator.events.once('joined', async ({ids}) => {
105
105
  emitter.emit('filled', {ids});
106
106
 
107
- // Exit early when this is a pair group
108
- if (count === minGroupCount) {
109
- return coordinator.connected();
110
- }
107
+ try {
108
+ // Exit early when this is a pair group
109
+ if (count === minGroupCount) {
110
+ const [outbound] = ids.filter(n => n !== identity);
111
111
 
112
- const {inbound, outbound} = coordinator.partners(identity);
112
+ await peerWithPartners({capacity, lnd, outbound});
113
113
 
114
- // Connect to the inbound and outbound partners
115
- try {
116
- await peerWithPartners({inbound, lnd, outbound});
114
+ return coordinator.connected();
115
+ }
116
+
117
+ const {inbound, outbound} = coordinator.partners(identity);
118
+
119
+ // Connect to the inbound and outbound partners
120
+ await peerWithPartners({capacity, inbound, lnd, outbound});
117
121
 
118
122
  // Register as connected
119
123
  return coordinator.connected();
@@ -1,5 +1,6 @@
1
1
  const asyncAuto = require('async/auto');
2
2
  const asyncRetry = require('async/retry');
3
+ const asyncTimeout = require('async/timeout');
3
4
  const {connectPeer} = require('ln-sync');
4
5
  const {getChainBalance} = require('ln-service');
5
6
  const {getNodeAlias} = require('ln-sync');
@@ -8,6 +9,7 @@ const {returnResult} = require('asyncjs-util');
8
9
  const {getGroupDetails} = require('./p2p');
9
10
 
10
11
  const coordinatorFromJoinCode = n => n.slice(0, 66);
12
+ const defaultTimeoutMs = 1000 * 60;
11
13
  const groupIdFromJoinCode = n => n.slice(66);
12
14
  const interval = 500;
13
15
  const isCode = n => !!n && n.length === 98;
@@ -73,7 +75,13 @@ module.exports = ({code, lnd, logger}, cbk) => {
73
75
  // Connect to the coordinator
74
76
  connect: ['group', ({group}, cbk) => {
75
77
  return asyncRetry({interval, times}, cbk => {
76
- return connectPeer({lnd, id: group.coordinator}, cbk);
78
+ logger.info({connecting_to: group.coordinator});
79
+
80
+ return asyncTimeout(connectPeer, defaultTimeoutMs)({
81
+ lnd,
82
+ id: group.coordinator,
83
+ },
84
+ cbk);
77
85
  },
78
86
  cbk);
79
87
  }],
@@ -84,11 +92,16 @@ module.exports = ({code, lnd, logger}, cbk) => {
84
92
  }],
85
93
 
86
94
  // Get the group details from the coordinator
87
- getDetails: ['group', ({group}, cbk) => {
88
- return getGroupDetails({
89
- lnd,
90
- coordinator: group.coordinator,
91
- id: group.id,
95
+ getDetails: ['connect', 'group', ({group}, cbk) => {
96
+ return asyncRetry({interval, times}, cbk => {
97
+ logger.info({requesting_group_details_from: group.coordinator});
98
+
99
+ return getGroupDetails({
100
+ lnd,
101
+ coordinator: group.coordinator,
102
+ id: group.id,
103
+ },
104
+ cbk);
92
105
  },
93
106
  cbk);
94
107
  }],
@@ -107,6 +107,7 @@ module.exports = ({capacity, coordinator, count, id, lnd, rate}, cbk) => {
107
107
  });
108
108
 
109
109
  return peerWithPartners({
110
+ capacity,
110
111
  lnd,
111
112
  inbound: partners.inbound,
112
113
  outbound: partners.outbound,
@@ -21,13 +21,14 @@ const typeGroupChannelId = '1';
21
21
 
22
22
  {
23
23
  coordinator: <Group Coordinator Identity Public Key Hex String>
24
+ count: <Group Member Count Number>
24
25
  id: <Group Identifier Hex String>
25
26
  lnd: <Authenticated LND API Object>
26
27
  }
27
28
 
28
29
  @returns via cbk or Promise
29
30
  {
30
- inbound: <Inbound Peer Public Key Identity Hex String>
31
+ [inbound]: <Inbound Peer Public Key Identity Hex String>
31
32
  outbound: <Outbound Peer Public Key Identity Hex String>
32
33
  }
33
34
  */
@@ -1,3 +1,4 @@
1
+ const {acceptsChannelOpen} = require('ln-sync');
1
2
  const asyncAuto = require('async/auto');
2
3
  const asyncRetry = require('async/retry');
3
4
  const {connectPeer} = require('ln-sync');
@@ -9,20 +10,21 @@ const times = 2 * 60 * 30;
9
10
  /** Peer up with group channel partners
10
11
 
11
12
  {
12
- inbound: <Inbound Identity Public Key Hex String>
13
+ capacity: <Channel Capacity Tokens Number>
14
+ [inbound]: <Inbound Identity Public Key Hex String>
13
15
  lnd: <Authenticated LND API Object>
14
16
  outbound: <Outbound Identity Public Key Hex String>
15
17
  }
16
18
 
17
19
  @returns via cbk or Promise
18
20
  */
19
- module.exports = ({inbound, lnd, outbound}, cbk) => {
21
+ module.exports = ({capacity, inbound, lnd, outbound}, cbk) => {
20
22
  return new Promise((resolve, reject) => {
21
23
  return asyncAuto({
22
24
  // Check arguments
23
25
  validate: cbk => {
24
- if (!inbound) {
25
- return cbk([400, 'ExpectedInboundPeerIdentityToConnectTo']);
26
+ if (!capacity) {
27
+ return cbk([400, 'ExpectedChannelCapacityToPeerWithPartners']);
26
28
  }
27
29
 
28
30
  if (!lnd) {
@@ -38,6 +40,11 @@ module.exports = ({inbound, lnd, outbound}, cbk) => {
38
40
 
39
41
  // Attempt connecting to the inbound peer
40
42
  connectInbound: ['validate', ({}, cbk) => {
43
+ // Exit early when there is no inbound peer
44
+ if (!inbound) {
45
+ return cbk();
46
+ }
47
+
41
48
  return asyncRetry({interval, times}, cbk => {
42
49
  return connectPeer({lnd, id: inbound}, cbk);
43
50
  },
@@ -51,6 +58,25 @@ module.exports = ({inbound, lnd, outbound}, cbk) => {
51
58
  },
52
59
  cbk);
53
60
  }],
61
+
62
+ // Test if outbound peer would accept a channel
63
+ getAcceptance: ['connectOutbound', ({}, cbk) => {
64
+ return acceptsChannelOpen({
65
+ capacity,
66
+ lnd,
67
+ partner_public_key: outbound,
68
+ },
69
+ cbk);
70
+ }],
71
+
72
+ // Check that the proposal would be accepted
73
+ checkAcceptance: ['getAcceptance', ({getAcceptance}, cbk) => {
74
+ if (!getAcceptance.is_accepted) {
75
+ return cbk([503, 'PeerRejectedChanOpenRequest', {peer: outbound}]);
76
+ }
77
+
78
+ return cbk();
79
+ }],
54
80
  },
55
81
  returnResult({reject, resolve}, cbk));
56
82
  });
package/package.json CHANGED
@@ -16,8 +16,8 @@
16
16
  "ecpair": "2.1.0",
17
17
  "goldengate": "12.0.5",
18
18
  "invoices": "2.2.3",
19
- "ln-service": "56.1.0",
20
- "ln-sync": "4.3.2",
19
+ "ln-service": "56.2.0",
20
+ "ln-sync": "5.1.0",
21
21
  "psbt": "2.7.2",
22
22
  "p2tr": "1.3.3",
23
23
  "tiny-secp256k1": "2.2.1"
@@ -25,7 +25,7 @@
25
25
  "description": "Lightning Paid Services library",
26
26
  "devDependencies": {
27
27
  "@alexbosworth/tap": "15.0.12",
28
- "ln-docker-daemons": "5.0.1",
28
+ "ln-docker-daemons": "5.0.2",
29
29
  "mock-lnd": "1.4.4",
30
30
  "secp256k1": "5.0.0"
31
31
  },
@@ -47,5 +47,5 @@
47
47
  "integration-tests": "tap -j 2 --branches=1 --functions=1 --lines=1 --statements=1 -t 180 test/integration/*.js",
48
48
  "test": "tap --branches=1 --functions=1 --lines=1 --statements=1 -t 60 test/actions/*.js test/balanced/*.js test/capacity/*.js test/client/*.js test/config/*.js test/p2p/*.js test/records/*.js test/respond/*.js test/server/*.js test/swaps/*.js test/services/*.js test/trades/*.js"
49
49
  },
50
- "version": "5.0.0"
50
+ "version": "5.0.2"
51
51
  }