ln-service 52.12.0 → 52.14.1
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 +11 -1
- package/README.md +101 -30
- package/index.js +7 -3
- package/package.json +4 -4
- package/test/integration/test_get_failed_payments.js +15 -47
- package/test/integration/test_send_message_to_peer.js +65 -0
- package/test/integration/test_subscribe_to_peer_messages.js +83 -0
- package/test/routerrpc-integration/test_probe_for_route.js +12 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
# Versions
|
|
2
2
|
|
|
3
|
-
## 52.
|
|
3
|
+
## 52.14.1
|
|
4
|
+
|
|
5
|
+
- `probeForRoute`, `subscribeToProbeForRoute`, `subscribeToPayViaRoutes`,
|
|
6
|
+
`payViaRoutes`: When probing (no hash), delete the payment failure record after the probe
|
|
7
|
+
|
|
8
|
+
## 52.13.0
|
|
9
|
+
|
|
10
|
+
- Add method `sendMessageToPeer` to send a custom peer message
|
|
11
|
+
- Add method `subscribeToPeerMessages` to be notified on custom peer messages
|
|
12
|
+
|
|
13
|
+
## 52.12.1
|
|
4
14
|
|
|
5
15
|
- `getFailedPayments`: Add method to get payments that failed
|
|
6
16
|
|
package/README.md
CHANGED
|
@@ -191,38 +191,40 @@ for `unlocker` methods.
|
|
|
191
191
|
- [recoverFundsFromChannels](#recoverFundsFromChannels) - Restore all channels
|
|
192
192
|
- [removePeer](#removePeer) - Disconnect from a connected peer
|
|
193
193
|
- [requestChainFeeIncrease](#requestchainfeeincrease) - Request a CPFP spend on a UTXO
|
|
194
|
-
- [restrictMacaroon](#
|
|
195
|
-
- [revokeAccess](#
|
|
196
|
-
- [routeFromChannels](#
|
|
197
|
-
- [
|
|
198
|
-
- [
|
|
194
|
+
- [restrictMacaroon](#restrictmacaroon) - Add limitations to a macaroon
|
|
195
|
+
- [revokeAccess](#revokeaccess) - Revoke all access macaroons given to an id
|
|
196
|
+
- [routeFromChannels](#routefromchannels) - Convert channel series to a route
|
|
197
|
+
- [sendMessageToPeer](#sendmessagetopeer) - Send a custom message to a peer
|
|
198
|
+
- [sendToChainAddress](#sendtochainaddress) - Send on-chain to an address
|
|
199
|
+
- [sendToChainAddresses](#sendtochainaddresses) - Send on-chain to addresses
|
|
199
200
|
- [sendToChainOutputScripts](#sendtochainoutputscripts) - Send to on-chain script outputs
|
|
200
|
-
- [setAutopilot](#
|
|
201
|
-
- [settleHodlInvoice](#
|
|
202
|
-
- [signBytes](#
|
|
203
|
-
- [signMessage](#
|
|
204
|
-
- [signPsbt](#
|
|
205
|
-
- [signTransaction](#
|
|
206
|
-
- [stopDaemon](#
|
|
207
|
-
- [subscribeToBackups](#
|
|
208
|
-
- [subscribeToBlocks](#
|
|
209
|
-
- [subscribeToChainAddress](#
|
|
210
|
-
- [subscribeToChainSpend](#
|
|
211
|
-
- [subscribeToChannels](#
|
|
212
|
-
- [subscribeToForwardRequests](#
|
|
213
|
-
- [subscribeToForwards](#
|
|
214
|
-
- [subscribeToGraph](#
|
|
215
|
-
- [subscribeToInvoice](#
|
|
216
|
-
- [subscribeToInvoices](#
|
|
217
|
-
- [subscribeToOpenRequests](#
|
|
218
|
-
- [subscribeToPastPayment](#
|
|
201
|
+
- [setAutopilot](#setautopilot) - Turn autopilot on and set autopilot scores
|
|
202
|
+
- [settleHodlInvoice](#settlehodlinvoice) - Accept a HODL HTLC invoice
|
|
203
|
+
- [signBytes](#signbytes) - Sign over arbitrary bytes with node keys
|
|
204
|
+
- [signMessage](#signmessage) - Sign a message with the node identity key
|
|
205
|
+
- [signPsbt](#signpsbt) - Sign and finalize an unsigned PSBT using internal keys
|
|
206
|
+
- [signTransaction](#signtransaction) - Sign an on-chain transaction
|
|
207
|
+
- [stopDaemon](#stopdaemon) - Stop lnd
|
|
208
|
+
- [subscribeToBackups](#subscribetobackups) - Subscribe to channel backups
|
|
209
|
+
- [subscribeToBlocks](#subscribetoblocks) - Subscribe to on-chain blocks
|
|
210
|
+
- [subscribeToChainAddress](#subscribetochainaddress) - Subscribe to receives
|
|
211
|
+
- [subscribeToChainSpend](#subscribetochainspend) - Subscribe to chain spends
|
|
212
|
+
- [subscribeToChannels](#subscribetochannels) - Subscribe to channel statuses
|
|
213
|
+
- [subscribeToForwardRequests](#subscribetoforwardrequests) - Interactively route
|
|
214
|
+
- [subscribeToForwards](#subscribetoforwards) - Subscribe to HTLC events
|
|
215
|
+
- [subscribeToGraph](#subscribetograph) - Subscribe to network graph updates
|
|
216
|
+
- [subscribeToInvoice](#subscribetoinvoice) - Subscribe to invoice updates
|
|
217
|
+
- [subscribeToInvoices](#subscribetoinvoices) - Subscribe to all invoices
|
|
218
|
+
- [subscribeToOpenRequests](#subscribetoopenrequests) - Approve open requests
|
|
219
|
+
- [subscribeToPastPayment](#subscribetopastpayment) - Subscribe to a payment
|
|
219
220
|
- [subscribeToPastPayments](#subscribetopastpayments) - Subscribe to all sent payments
|
|
220
|
-
- [subscribeToPayViaDetails](#
|
|
221
|
-
- [subscribeToPayViaRequest](#
|
|
222
|
-
- [subscribeToPayViaRoutes](#
|
|
223
|
-
- [
|
|
224
|
-
- [
|
|
225
|
-
- [
|
|
221
|
+
- [subscribeToPayViaDetails](#subscribetopayviadetails) - Pay using details
|
|
222
|
+
- [subscribeToPayViaRequest](#subscribetopayviarequest) - Pay using a request
|
|
223
|
+
- [subscribeToPayViaRoutes](#subscribetopayviaroutes) - Pay using routes
|
|
224
|
+
- [subscribeToPeerMessages](#subscribetopeermessages) - Listen to incoming custom messages
|
|
225
|
+
- [subscribeToPeers](#subscribetopeers) - Subscribe to peers connectivity
|
|
226
|
+
- [subscribeToProbe](#subscribetoprobe) - Subscribe to a probe for a route
|
|
227
|
+
- [subscribeToProbeForRoute](#subscribetoprobeforroute) - Probe for a route
|
|
226
228
|
- [subscribeToRpcRequests](#subscribetorpcrequests) - Subscribe to rpc requests
|
|
227
229
|
- [subscribeToTransactions](#subscribetotransactions) - Subscribe to chain tx
|
|
228
230
|
- [subscribeToWalletStatus](#subscribetowalletstatus) - Subscribe to node state
|
|
@@ -4056,6 +4058,39 @@ const res = routeFromChannels({channels, destination, height, mtokens});
|
|
|
4056
4058
|
const {route} = res;
|
|
4057
4059
|
```
|
|
4058
4060
|
|
|
4061
|
+
### sendMessageToPeer
|
|
4062
|
+
|
|
4063
|
+
Send a custom message to a connected peer
|
|
4064
|
+
|
|
4065
|
+
If specified, message type is expected to be between 32768 and 65535
|
|
4066
|
+
|
|
4067
|
+
Message data should not be larger than 65533 bytes
|
|
4068
|
+
|
|
4069
|
+
Note: this method is not supported in LND versions 0.13.3 and below
|
|
4070
|
+
|
|
4071
|
+
Requires `offchain:write` permission
|
|
4072
|
+
|
|
4073
|
+
{
|
|
4074
|
+
lnd: <Authenticated LND API Object>
|
|
4075
|
+
message: <Message Hex String>
|
|
4076
|
+
public_key: <To Peer Public Key Hex String>
|
|
4077
|
+
[type]: <Message Type Number>
|
|
4078
|
+
}
|
|
4079
|
+
|
|
4080
|
+
@returns via cbk or Promise
|
|
4081
|
+
|
|
4082
|
+
Example:
|
|
4083
|
+
|
|
4084
|
+
```node
|
|
4085
|
+
const {sendMessageToPeer} = require('ln-service');
|
|
4086
|
+
|
|
4087
|
+
await sendMessageToPeer({
|
|
4088
|
+
lnd,
|
|
4089
|
+
message: Buffer.from('Hello world').toString('hex'),
|
|
4090
|
+
public_key: peerPublicKeyHex,
|
|
4091
|
+
});
|
|
4092
|
+
```
|
|
4093
|
+
|
|
4059
4094
|
### sendToChainAddress
|
|
4060
4095
|
|
|
4061
4096
|
Send tokens in a blockchain transaction.
|
|
@@ -5564,6 +5599,42 @@ const sub = subscribeToPayViaRoutes({lnd, routes: [route]});
|
|
|
5564
5599
|
const [success] = await once(sub, 'success');
|
|
5565
5600
|
```
|
|
5566
5601
|
|
|
5602
|
+
### subscribeToPeerMessages
|
|
5603
|
+
|
|
5604
|
+
Subscribe to incoming peer messages
|
|
5605
|
+
|
|
5606
|
+
Requires `offchain:read` permission
|
|
5607
|
+
|
|
5608
|
+
This method is not supported in LND 0.13.3 and below
|
|
5609
|
+
|
|
5610
|
+
{
|
|
5611
|
+
lnd: <Authenticated LND API Object>
|
|
5612
|
+
}
|
|
5613
|
+
|
|
5614
|
+
@returns
|
|
5615
|
+
<EventEmitter Object>
|
|
5616
|
+
|
|
5617
|
+
// A message was received from a peer
|
|
5618
|
+
@event 'message_received'
|
|
5619
|
+
{
|
|
5620
|
+
message: <Message Hex String>
|
|
5621
|
+
public_key: <From Peer Public Key Hex String>
|
|
5622
|
+
type: <Message Type Number>
|
|
5623
|
+
}
|
|
5624
|
+
|
|
5625
|
+
Example
|
|
5626
|
+
|
|
5627
|
+
```node
|
|
5628
|
+
const {subscribeToPeerMessages} = require('ln-service');
|
|
5629
|
+
|
|
5630
|
+
const sub = subscribeToPeerMessages({lnd});
|
|
5631
|
+
|
|
5632
|
+
const messages = [];
|
|
5633
|
+
|
|
5634
|
+
// Collect peer custom messages
|
|
5635
|
+
sub.on('message_received', received => messages.push(received.message));
|
|
5636
|
+
```
|
|
5637
|
+
|
|
5567
5638
|
### subscribeToPeers
|
|
5568
5639
|
|
|
5569
5640
|
Subscribe to peer connectivity events
|
package/index.js
CHANGED
|
@@ -38,7 +38,7 @@ const {getChannelBalance} = require('lightning');
|
|
|
38
38
|
const {getChannels} = require('lightning');
|
|
39
39
|
const {getClosedChannels} = require('lightning');
|
|
40
40
|
const {getConnectedWatchtowers} = require('lightning');
|
|
41
|
-
const {getFailedPayments} = require('lightning
|
|
41
|
+
const {getFailedPayments} = require('lightning');
|
|
42
42
|
const {getFeeRates} = require('lightning');
|
|
43
43
|
const {getForwardingConfidence} = require('lightning');
|
|
44
44
|
const {getForwardingReputations} = require('lightning');
|
|
@@ -78,7 +78,7 @@ const {parsePaymentRequest} = require('invoices');
|
|
|
78
78
|
const {pay} = require('lightning');
|
|
79
79
|
const {payViaPaymentDetails} = require('lightning');
|
|
80
80
|
const {payViaPaymentRequest} = require('lightning');
|
|
81
|
-
const {payViaRoutes} = require('lightning
|
|
81
|
+
const {payViaRoutes} = require('lightning');
|
|
82
82
|
const {prepareForChannelProposal} = require('lightning');
|
|
83
83
|
const {probeForRoute} = require('lightning');
|
|
84
84
|
const {proposeChannel} = require('lightning');
|
|
@@ -89,6 +89,7 @@ const {requestChainFeeIncrease} = require('lightning');
|
|
|
89
89
|
const {restrictMacaroon} = require('./macaroons');
|
|
90
90
|
const {revokeAccess} = require('lightning');
|
|
91
91
|
const {routeFromChannels} = require('bolt07');
|
|
92
|
+
const {sendMessageToPeer} = require('lightning/lnd_methods');
|
|
92
93
|
const {sendToChainAddress} = require('lightning');
|
|
93
94
|
const {sendToChainAddresses} = require('lightning');
|
|
94
95
|
const {sendToChainOutputScripts} = require('lightning');
|
|
@@ -115,9 +116,10 @@ const {subscribeToPastPayments} = require('lightning');
|
|
|
115
116
|
const {subscribeToPayViaDetails} = require('lightning');
|
|
116
117
|
const {subscribeToPayViaRequest} = require('lightning');
|
|
117
118
|
const {subscribeToPayViaRoutes} = require('lightning');
|
|
119
|
+
const {subscribeToPeerMessages} = require('lightning/lnd_methods');
|
|
118
120
|
const {subscribeToPeers} = require('lightning');
|
|
119
121
|
const {subscribeToProbeForRoute} = require('lightning');
|
|
120
|
-
const {subscribeToRpcRequests} = require('lightning
|
|
122
|
+
const {subscribeToRpcRequests} = require('lightning');
|
|
121
123
|
const {subscribeToTransactions} = require('lightning');
|
|
122
124
|
const {subscribeToWalletStatus} = require('lightning');
|
|
123
125
|
const {unauthenticatedLndGrpc} = require('lightning');
|
|
@@ -225,6 +227,7 @@ module.exports = {
|
|
|
225
227
|
restrictMacaroon,
|
|
226
228
|
revokeAccess,
|
|
227
229
|
routeFromChannels,
|
|
230
|
+
sendMessageToPeer,
|
|
228
231
|
sendToChainAddress,
|
|
229
232
|
sendToChainAddresses,
|
|
230
233
|
sendToChainOutputScripts,
|
|
@@ -251,6 +254,7 @@ module.exports = {
|
|
|
251
254
|
subscribeToPayViaDetails,
|
|
252
255
|
subscribeToPayViaRequest,
|
|
253
256
|
subscribeToPayViaRoutes,
|
|
257
|
+
subscribeToPeerMessages,
|
|
254
258
|
subscribeToPeers,
|
|
255
259
|
subscribeToProbeForRoute,
|
|
256
260
|
subscribeToRpcRequests,
|
package/package.json
CHANGED
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
"url": "https://github.com/alexbosworth/ln-service/issues"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"bolt07": "1.7.
|
|
10
|
+
"bolt07": "1.7.4",
|
|
11
11
|
"cors": "2.8.5",
|
|
12
12
|
"express": "4.17.1",
|
|
13
13
|
"invoices": "2.0.0",
|
|
14
|
-
"lightning": "4.
|
|
14
|
+
"lightning": "4.12.1",
|
|
15
15
|
"macaroon": "3.0.4",
|
|
16
16
|
"morgan": "1.10.0",
|
|
17
17
|
"ws": "8.2.3"
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@alexbosworth/tap": "15.0.10",
|
|
22
22
|
"@alexbosworth/node-fetch": "2.6.2",
|
|
23
|
-
"async": "3.2.
|
|
23
|
+
"async": "3.2.2",
|
|
24
24
|
"asyncjs-util": "1.2.6",
|
|
25
25
|
"bip66": "1.1.5",
|
|
26
26
|
"bitcoinjs-lib": "5.2.0",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"tower_server-integration-tests": "tap --no-coverage test/tower_serverrpc-integration/*.js",
|
|
62
62
|
"wallet-integration-tests": "tap --no-coverage test/walletrpc-integration/*.js"
|
|
63
63
|
},
|
|
64
|
-
"version": "52.
|
|
64
|
+
"version": "52.14.1"
|
|
65
65
|
}
|
|
@@ -9,8 +9,7 @@ const {deleteForwardingReputations} = require('./../../');
|
|
|
9
9
|
const {getFailedPayments} = require('./../../');
|
|
10
10
|
const {getPayment} = require('./../../');
|
|
11
11
|
const {getPayments} = require('./../../');
|
|
12
|
-
const {
|
|
13
|
-
const {probeForRoute} = require('./../../');
|
|
12
|
+
const {pay} = require('./../../');
|
|
14
13
|
const {sendToChainAddress} = require('./../../');
|
|
15
14
|
const {setupChannel} = require('./../macros');
|
|
16
15
|
|
|
@@ -59,21 +58,16 @@ test('Get failed payments', async ({end, equal, strictSame}) => {
|
|
|
59
58
|
|
|
60
59
|
const invoice = await createInvoice({tokens, lnd: cluster.remote.lnd});
|
|
61
60
|
|
|
61
|
+
const bigInvoice = await createInvoice({
|
|
62
|
+
tokens: (channelCapacityTokens / 2) + (channelCapacityTokens / 4),
|
|
63
|
+
lnd: cluster.remote.lnd,
|
|
64
|
+
});
|
|
65
|
+
|
|
62
66
|
await delay(1000);
|
|
63
67
|
|
|
64
68
|
try {
|
|
65
|
-
await
|
|
66
|
-
lnd,
|
|
67
|
-
destination: cluster.remote_node_public_key,
|
|
68
|
-
is_ignoring_past_failures: true,
|
|
69
|
-
tokens: invoice.tokens,
|
|
70
|
-
});
|
|
69
|
+
await pay({lnd, request: bigInvoice.request});
|
|
71
70
|
} catch (err) {
|
|
72
|
-
const [code, message, {failure}] = err;
|
|
73
|
-
|
|
74
|
-
equal(code, 503, 'Failed to find route');
|
|
75
|
-
equal(message, 'RoutingFailure', 'Hit a routing failure');
|
|
76
|
-
equal(failure.reason, 'TemporaryChannelFailure', 'Temporary failure');
|
|
77
71
|
}
|
|
78
72
|
|
|
79
73
|
// Create a new channel to increase total edge liquidity
|
|
@@ -88,32 +82,7 @@ test('Get failed payments', async ({end, equal, strictSame}) => {
|
|
|
88
82
|
await deleteForwardingReputations({lnd});
|
|
89
83
|
|
|
90
84
|
try {
|
|
91
|
-
const {
|
|
92
|
-
lnd,
|
|
93
|
-
destination: cluster.remote.public_key,
|
|
94
|
-
payment: invoice.payment,
|
|
95
|
-
tokens: invoice.tokens,
|
|
96
|
-
total_mtokens: !!invoice.payment ? invoice.mtokens : undefined,
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
if (!route) {
|
|
100
|
-
throw new Error('ExpectedRouteFromProbe');
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
equal(route.fee, 1, 'Found route fee');
|
|
104
|
-
equal(route.fee_mtokens, '1500', 'Found route fee mtokens');
|
|
105
|
-
strictSame(route.hops.length, 2, 'Found route hops returned');
|
|
106
|
-
equal(route.mtokens, '500001500', 'Found route mtokens');
|
|
107
|
-
equal(route.timeout, 586, 'Found route timeout');
|
|
108
|
-
equal(route.tokens, 500001, 'Found route tokens');
|
|
109
|
-
|
|
110
|
-
const {secret} = await payViaRoutes({
|
|
111
|
-
lnd,
|
|
112
|
-
id: invoice.id,
|
|
113
|
-
routes: [route],
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
equal(secret, invoice.secret, 'Route works');
|
|
85
|
+
const {secret} = await pay({lnd, request: invoice.request});
|
|
117
86
|
} catch (err) {
|
|
118
87
|
equal(err, null, 'No error when probing for route');
|
|
119
88
|
}
|
|
@@ -128,17 +97,16 @@ test('Get failed payments', async ({end, equal, strictSame}) => {
|
|
|
128
97
|
equal(!!payment.created_at, true, 'Got payment created date');
|
|
129
98
|
equal(payment.fee, undefined, 'No fee when not paid');
|
|
130
99
|
equal(payment.fee_mtokens, undefined, 'No fee mtokens when not paid');
|
|
131
|
-
strictSame(payment.hops, [cluster.target.public_key], 'Got hops');
|
|
132
100
|
equal(!!payment.id, true, 'Got a payment id');
|
|
133
101
|
equal(!!payment.index, true, 'Got payment index');
|
|
134
102
|
equal(payment.is_confirmed, false, 'Failed payment is not confirmed');
|
|
135
103
|
equal(payment.is_outgoing, true, 'Failed payment is outgoing');
|
|
136
|
-
equal(payment.mtokens,
|
|
137
|
-
equal(payment.request,
|
|
104
|
+
equal(payment.mtokens, bigInvoice.mtokens, 'Payment has mtokens');
|
|
105
|
+
equal(payment.request, bigInvoice.request, 'Probe has a request');
|
|
138
106
|
equal(payment.secret, undefined, 'Failed has no secret');
|
|
139
107
|
equal(payment.safe_fee, undefined, 'Failed has no fee');
|
|
140
|
-
equal(payment.safe_tokens,
|
|
141
|
-
equal(payment.tokens,
|
|
108
|
+
equal(payment.safe_tokens, bigInvoice.tokens, 'Failed has safe tokens');
|
|
109
|
+
equal(payment.tokens, bigInvoice.tokens, 'Failed has tokens');
|
|
142
110
|
|
|
143
111
|
const gotFailed = await getPayment({lnd, id: payment.id});
|
|
144
112
|
|
|
@@ -147,9 +115,9 @@ test('Get failed payments', async ({end, equal, strictSame}) => {
|
|
|
147
115
|
{
|
|
148
116
|
failed: {
|
|
149
117
|
is_insufficient_balance: false,
|
|
150
|
-
is_invalid_payment:
|
|
118
|
+
is_invalid_payment: false,
|
|
151
119
|
is_pathfinding_timeout: false,
|
|
152
|
-
is_route_not_found:
|
|
120
|
+
is_route_not_found: true,
|
|
153
121
|
},
|
|
154
122
|
is_confirmed: false,
|
|
155
123
|
is_failed: true,
|
|
@@ -176,7 +144,7 @@ test('Get failed payments', async ({end, equal, strictSame}) => {
|
|
|
176
144
|
equal(payment.is_confirmed, true, 'Failed payment is not confirmed');
|
|
177
145
|
equal(payment.is_outgoing, true, 'Failed payment is outgoing');
|
|
178
146
|
equal(payment.mtokens, invoice.mtokens, 'Payment has mtokens');
|
|
179
|
-
equal(payment.request,
|
|
147
|
+
equal(payment.request, invoice.request, 'Payment has a request');
|
|
180
148
|
equal(!!payment.secret, true, 'Failed has no secret');
|
|
181
149
|
equal(payment.safe_fee, 2, 'Failed has no fee');
|
|
182
150
|
equal(payment.safe_tokens, invoice.tokens, 'Failed has safe tokens');
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const asyncRetry = require('async/retry');
|
|
2
|
+
const {test} = require('@alexbosworth/tap');
|
|
3
|
+
|
|
4
|
+
const {createCluster} = require('./../macros');
|
|
5
|
+
const {sendMessageToPeer} = require('./../../');
|
|
6
|
+
const {subscribeToPeerMessages} = require('./../../');
|
|
7
|
+
|
|
8
|
+
const interval = 10;
|
|
9
|
+
const times = 1000;
|
|
10
|
+
|
|
11
|
+
// Sending a message to a peer should result in the message received
|
|
12
|
+
test(`Send peer message`, async ({end, equal, strictSame}) => {
|
|
13
|
+
const cluster = await createCluster({is_remote_skipped: true});
|
|
14
|
+
|
|
15
|
+
const {lnd} = cluster.control;
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
await sendMessageToPeer({
|
|
19
|
+
lnd,
|
|
20
|
+
message: Buffer.from('message').toString('hex'),
|
|
21
|
+
public_key: cluster.target.public_key,
|
|
22
|
+
});
|
|
23
|
+
} catch (err) {
|
|
24
|
+
const [code] = err;
|
|
25
|
+
|
|
26
|
+
// Send message to peer is not supported on LND 0.13.3 or lower
|
|
27
|
+
if (code === 501) {
|
|
28
|
+
await cluster.kill({});
|
|
29
|
+
|
|
30
|
+
return end();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const sub = subscribeToPeerMessages({lnd: cluster.target.lnd});
|
|
35
|
+
|
|
36
|
+
const messages = [];
|
|
37
|
+
|
|
38
|
+
sub.on('message_received', message => messages.push(message));
|
|
39
|
+
|
|
40
|
+
await sendMessageToPeer({
|
|
41
|
+
lnd,
|
|
42
|
+
message: Buffer.from('message').toString('hex'),
|
|
43
|
+
public_key: cluster.target.public_key,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
await asyncRetry({interval, times}, async () => {
|
|
47
|
+
if (!messages.length) {
|
|
48
|
+
throw new Error('ExpectedMessage');
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
strictSame(
|
|
53
|
+
messages,
|
|
54
|
+
[{
|
|
55
|
+
message: Buffer.from('message').toString('hex'),
|
|
56
|
+
public_key: cluster.control.public_key,
|
|
57
|
+
type: 32768,
|
|
58
|
+
}],
|
|
59
|
+
'Message successfully sent to peer'
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
await cluster.kill({});
|
|
63
|
+
|
|
64
|
+
return end();
|
|
65
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const asyncRetry = require('async/retry');
|
|
2
|
+
const {test} = require('@alexbosworth/tap');
|
|
3
|
+
|
|
4
|
+
const {createCluster} = require('./../macros');
|
|
5
|
+
const {sendMessageToPeer} = require('./../../');
|
|
6
|
+
const {subscribeToPeerMessages} = require('./../../');
|
|
7
|
+
|
|
8
|
+
const interval = 10;
|
|
9
|
+
const times = 1000;
|
|
10
|
+
|
|
11
|
+
// Messages should be received from peers
|
|
12
|
+
test(`Subscribe to peer messages`, async ({end, equal, strictSame}) => {
|
|
13
|
+
const cluster = await createCluster({});
|
|
14
|
+
|
|
15
|
+
const {lnd} = cluster.control;
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
await sendMessageToPeer({
|
|
19
|
+
lnd,
|
|
20
|
+
message: Buffer.from('message').toString('hex'),
|
|
21
|
+
public_key: cluster.target.public_key,
|
|
22
|
+
});
|
|
23
|
+
} catch (err) {
|
|
24
|
+
const [code] = err;
|
|
25
|
+
|
|
26
|
+
// Send message to peer is not supported on LND 0.13.3 or lower
|
|
27
|
+
if (code === 501) {
|
|
28
|
+
await cluster.kill({});
|
|
29
|
+
|
|
30
|
+
return end();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const targetSub = subscribeToPeerMessages({lnd: cluster.target.lnd});
|
|
35
|
+
const remoteSub = subscribeToPeerMessages({lnd: cluster.remote.lnd});
|
|
36
|
+
|
|
37
|
+
const messages = [];
|
|
38
|
+
|
|
39
|
+
remoteSub.on('message_received', message => messages.push(message));
|
|
40
|
+
|
|
41
|
+
targetSub.on('message_received', async ({message, type}) => {
|
|
42
|
+
if (type !== 40805) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Relay message from control to remote
|
|
47
|
+
return await sendMessageToPeer({
|
|
48
|
+
message,
|
|
49
|
+
type,
|
|
50
|
+
lnd: cluster.target.lnd,
|
|
51
|
+
public_key: cluster.remote.public_key,
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Control send a message to target peer
|
|
56
|
+
await sendMessageToPeer({
|
|
57
|
+
lnd,
|
|
58
|
+
message: Buffer.from('message to remote').toString('hex'),
|
|
59
|
+
public_key: cluster.target.public_key,
|
|
60
|
+
type: 40805,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Wait for message to appear
|
|
64
|
+
await asyncRetry({interval, times}, async () => {
|
|
65
|
+
if (!messages.length) {
|
|
66
|
+
throw new Error('ExpectedMessage');
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
strictSame(
|
|
71
|
+
messages,
|
|
72
|
+
[{
|
|
73
|
+
message: Buffer.from('message to remote').toString('hex'),
|
|
74
|
+
public_key: cluster.target.public_key,
|
|
75
|
+
type: 40805,
|
|
76
|
+
}],
|
|
77
|
+
'Message successfully relayed through target'
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
await cluster.kill({});
|
|
81
|
+
|
|
82
|
+
return end();
|
|
83
|
+
});
|
|
@@ -6,6 +6,8 @@ const {createCluster} = require('./../macros');
|
|
|
6
6
|
const {createInvoice} = require('./../../');
|
|
7
7
|
const {delay} = require('./../macros');
|
|
8
8
|
const {deleteForwardingReputations} = require('./../../');
|
|
9
|
+
const {getFailedPayments} = require('./../../');
|
|
10
|
+
const {getWalletVersion} = require('./../../');
|
|
9
11
|
const {payViaRoutes} = require('./../../');
|
|
10
12
|
const {probeForRoute} = require('./../../');
|
|
11
13
|
const {sendToChainAddress} = require('./../../');
|
|
@@ -75,6 +77,16 @@ test('Probe for route', async ({end, equal, strictSame}) => {
|
|
|
75
77
|
equal(failure.reason, 'TemporaryChannelFailure', 'Temporary failure');
|
|
76
78
|
}
|
|
77
79
|
|
|
80
|
+
const {version} = await getWalletVersion({lnd});
|
|
81
|
+
|
|
82
|
+
const [, minor] = (version || '').split('.');
|
|
83
|
+
|
|
84
|
+
if (!version || parseInt(minor) > 13) {
|
|
85
|
+
const {payments} = await getFailedPayments({lnd});
|
|
86
|
+
|
|
87
|
+
strictSame(payments, [], 'Probes do not leave a failed state behind');
|
|
88
|
+
}
|
|
89
|
+
|
|
78
90
|
// Create a new channel to increase total edge liquidity
|
|
79
91
|
await setupChannel({
|
|
80
92
|
capacity: channelCapacityTokens,
|