ln-service 57.14.0 → 57.14.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,6 +1,6 @@
1
1
  # Versions
2
2
 
3
- ## 57.14.0
3
+ ## 57.14.2
4
4
 
5
5
  - `getChannel`: Add support for specifying `transaction_id` and
6
6
  `transaction_vout` instead of `id`
package/package.json CHANGED
@@ -7,9 +7,9 @@
7
7
  "url": "https://github.com/alexbosworth/ln-service/issues"
8
8
  },
9
9
  "dependencies": {
10
- "bolt07": "1.9.2",
10
+ "bolt07": "1.9.3",
11
11
  "invoices": "3.0.0",
12
- "lightning": "10.14.0",
12
+ "lightning": "10.14.1",
13
13
  "macaroon": "3.0.4"
14
14
  },
15
15
  "description": "Interaction helper for your Lightning Network daemon",
@@ -24,7 +24,7 @@
24
24
  "bn.js": "5.2.1",
25
25
  "bs58check": "3.0.1",
26
26
  "ecpair": "2.1.0",
27
- "ln-docker-daemons": "6.0.18",
27
+ "ln-docker-daemons": "6.0.19",
28
28
  "p2tr": "2.0.0",
29
29
  "portfinder": "1.0.32",
30
30
  "psbt": "3.0.0",
@@ -72,5 +72,5 @@
72
72
  "integration-test-0.14.4": "DOCKER_LND_VERSION=v0.14.4-beta npm run test",
73
73
  "test": "echo $DOCKER_LND_VERSION && node test/runner"
74
74
  },
75
- "version": "57.14.0"
75
+ "version": "57.14.2"
76
76
  }
@@ -0,0 +1,136 @@
1
+ const {equal} = require('node:assert').strict;
2
+ const test = require('node:test');
3
+
4
+ const asyncRetry = require('async/retry');
5
+ const {setupChannel} = require('ln-docker-daemons');
6
+ const {spawnLightningCluster} = require('ln-docker-daemons');
7
+
8
+ const {addPeer} = require('./../../');
9
+ const {createInvoice} = require('./../../');
10
+ const {decodePaymentRequest} = require('./../../');
11
+ const {getHeight} = require('./../../');
12
+ const {getChannel} = require('./../../');
13
+ const {getRouteThroughHops} = require('./../../');
14
+ const {getRouteToDestination} = require('./../../');
15
+ const {getWalletInfo} = require('./../../');
16
+ const {payViaRoutes} = require('./../../');
17
+ const {routeFromChannels} = require('./../../');
18
+ const {updateRoutingFees} = require('./../../');
19
+ const {waitForRoute} = require('./../macros');
20
+
21
+ const baseFee = '1000';
22
+ const confirmationCount = 6;
23
+ const discount = '1000';
24
+ const interval = 10;
25
+ const size = 3;
26
+ const times = 1000;
27
+ const tokens = 100;
28
+
29
+ // Calculating a route from channels should result in a route
30
+ test(`Get route through hops`, async () => {
31
+ const {kill, nodes} = await spawnLightningCluster({size});
32
+
33
+ const [{generate, lnd}, target, remote] = nodes;
34
+
35
+ const controlToTargetChan = await setupChannel({generate, lnd, to: target});
36
+
37
+ await generate({});
38
+
39
+ const targetRemoteChannel = await asyncRetry({interval, times}, async () => {
40
+ await generate({});
41
+
42
+ await addPeer({
43
+ lnd: target.lnd,
44
+ public_key: remote.id,
45
+ socket: remote.socket,
46
+ });
47
+
48
+ return await setupChannel({
49
+ generate: target.generate,
50
+ lnd: target.lnd,
51
+ to: remote,
52
+ });
53
+ });
54
+
55
+ await target.generate({count: confirmationCount});
56
+
57
+ await asyncRetry({interval, times}, async () => {
58
+ const wallet = await getWalletInfo({lnd: remote.lnd});
59
+
60
+ await addPeer({lnd, public_key: remote.id, socket: remote.socket});
61
+
62
+ if (!wallet.is_synced_to_chain) {
63
+ throw new Error('ExpectedWalletSyncedToChain');
64
+ }
65
+ });
66
+
67
+ const invoice = await createInvoice({tokens, lnd: remote.lnd});
68
+
69
+ const {id} = invoice;
70
+ const {request} = invoice;
71
+
72
+ const decodedRequest = await decodePaymentRequest({lnd, request});
73
+
74
+ await waitForRoute({lnd, destination: remote.id, tokens: invoice.tokens});
75
+
76
+ const {route} = await asyncRetry({interval, times}, async () => {
77
+ return await getRouteToDestination({
78
+ lnd,
79
+ cltv_delta: decodedRequest.cltv_delta,
80
+ destination: decodedRequest.destination,
81
+ tokens: invoice.tokens,
82
+ });
83
+ });
84
+
85
+ const policyAStart = await getChannel({lnd, id: controlToTargetChan.id});
86
+
87
+ // Target gives a discount to traffic coming from control
88
+ await updateRoutingFees({
89
+ inbound_base_discount_mtokens: discount,
90
+ lnd: target.lnd,
91
+ transaction_id: controlToTargetChan.transaction_id,
92
+ transaction_vout: controlToTargetChan.transaction_vout,
93
+ });
94
+
95
+ // Wait for policy to be updated
96
+ const policyA = await asyncRetry({interval, times}, async () => {
97
+ const policy = await getChannel({lnd, id: controlToTargetChan.id});
98
+
99
+ if (policy.updated_at === policyAStart.updated_at) {
100
+ throw new Error('PolicyNotUpdatedYet');
101
+ }
102
+
103
+ return policy;
104
+ });
105
+
106
+ // A discount should be set for traffic from control to remote
107
+ const discountFee = policyA.policies.find(n => n.public_key === target.id);
108
+
109
+ // Get the routing policy of target to remote to calculate the route
110
+ const policyB = await getChannel({
111
+ id: targetRemoteChannel.id,
112
+ lnd: target.lnd,
113
+ });
114
+
115
+ const channelsRoute = routeFromChannels({
116
+ channels: [policyA, policyB],
117
+ cltv_delta: decodedRequest.cltv_delta + confirmationCount,
118
+ destination: decodedRequest.destination,
119
+ height: (await getHeight({lnd})).current_block_height,
120
+ mtokens: decodedRequest.mtokens,
121
+ payment: decodedRequest.payment,
122
+ total_mtokens: decodedRequest.mtokens,
123
+ });
124
+
125
+ const discounted = BigInt(discountFee.inbound_base_discount_mtokens);
126
+
127
+ const gotTotalFee = BigInt(channelsRoute.route.fee_mtokens);
128
+
129
+ await payViaRoutes({lnd, id: invoice.id, routes: [channelsRoute.route]});
130
+
131
+ await kill({});
132
+
133
+ equal(gotTotalFee, BigInt(baseFee) - discounted, 'Got expected discount');
134
+
135
+ return;
136
+ });