@@ -13,7 +13,7 @@ use crate::blinded_path::BlindedPath;
13
13
use crate :: sign:: { NodeSigner , Recipient } ;
14
14
use crate :: ln:: features:: InitFeatures ;
15
15
use crate :: ln:: msgs:: { self , DecodeError , OnionMessageHandler } ;
16
- use super :: { CustomOnionMessageContents , CustomOnionMessageHandler , Destination , OffersMessage , OffersMessageHandler , OnionMessageContents , OnionMessenger , SendError } ;
16
+ use super :: { CustomOnionMessageContents , CustomOnionMessageHandler , Destination , OffersMessage , OffersMessageHandler , OnionMessageContents , OnionMessagePath , OnionMessenger , SendError } ;
17
17
use crate :: util:: ser:: { Writeable , Writer } ;
18
18
use crate :: util:: test_utils;
19
19
@@ -146,7 +146,11 @@ fn one_hop() {
146
146
let nodes = create_nodes ( 2 ) ;
147
147
let test_msg = OnionMessageContents :: Custom ( TestCustomMessage { } ) ;
148
148
149
- nodes[ 0 ] . messenger . send_onion_message ( & [ ] , Destination :: Node ( nodes[ 1 ] . get_node_pk ( ) ) , test_msg, None ) . unwrap ( ) ;
149
+ let path = OnionMessagePath {
150
+ intermediate_nodes : vec ! [ ] ,
151
+ destination : Destination :: Node ( nodes[ 1 ] . get_node_pk ( ) ) ,
152
+ } ;
153
+ nodes[ 0 ] . messenger . send_onion_message ( path, test_msg, None ) . unwrap ( ) ;
150
154
pass_along_path ( & nodes) ;
151
155
}
152
156
@@ -155,7 +159,11 @@ fn two_unblinded_hops() {
155
159
let nodes = create_nodes ( 3 ) ;
156
160
let test_msg = OnionMessageContents :: Custom ( TestCustomMessage { } ) ;
157
161
158
- nodes[ 0 ] . messenger . send_onion_message ( & [ nodes[ 1 ] . get_node_pk ( ) ] , Destination :: Node ( nodes[ 2 ] . get_node_pk ( ) ) , test_msg, None ) . unwrap ( ) ;
162
+ let path = OnionMessagePath {
163
+ intermediate_nodes : vec ! [ nodes[ 1 ] . get_node_pk( ) ] ,
164
+ destination : Destination :: Node ( nodes[ 2 ] . get_node_pk ( ) ) ,
165
+ } ;
166
+ nodes[ 0 ] . messenger . send_onion_message ( path, test_msg, None ) . unwrap ( ) ;
159
167
pass_along_path ( & nodes) ;
160
168
}
161
169
@@ -166,8 +174,12 @@ fn two_unblinded_two_blinded() {
166
174
167
175
let secp_ctx = Secp256k1 :: new ( ) ;
168
176
let blinded_path = BlindedPath :: new_for_message ( & [ nodes[ 3 ] . get_node_pk ( ) , nodes[ 4 ] . get_node_pk ( ) ] , & * nodes[ 4 ] . keys_manager , & secp_ctx) . unwrap ( ) ;
177
+ let path = OnionMessagePath {
178
+ intermediate_nodes : vec ! [ nodes[ 1 ] . get_node_pk( ) , nodes[ 2 ] . get_node_pk( ) ] ,
179
+ destination : Destination :: BlindedPath ( blinded_path) ,
180
+ } ;
169
181
170
- nodes[ 0 ] . messenger . send_onion_message ( & [ nodes [ 1 ] . get_node_pk ( ) , nodes [ 2 ] . get_node_pk ( ) ] , Destination :: BlindedPath ( blinded_path ) , test_msg, None ) . unwrap ( ) ;
182
+ nodes[ 0 ] . messenger . send_onion_message ( path , test_msg, None ) . unwrap ( ) ;
171
183
pass_along_path ( & nodes) ;
172
184
}
173
185
@@ -178,8 +190,12 @@ fn three_blinded_hops() {
178
190
179
191
let secp_ctx = Secp256k1 :: new ( ) ;
180
192
let blinded_path = BlindedPath :: new_for_message ( & [ nodes[ 1 ] . get_node_pk ( ) , nodes[ 2 ] . get_node_pk ( ) , nodes[ 3 ] . get_node_pk ( ) ] , & * nodes[ 3 ] . keys_manager , & secp_ctx) . unwrap ( ) ;
193
+ let path = OnionMessagePath {
194
+ intermediate_nodes : vec ! [ ] ,
195
+ destination : Destination :: BlindedPath ( blinded_path) ,
196
+ } ;
181
197
182
- nodes[ 0 ] . messenger . send_onion_message ( & [ ] , Destination :: BlindedPath ( blinded_path ) , test_msg, None ) . unwrap ( ) ;
198
+ nodes[ 0 ] . messenger . send_onion_message ( path , test_msg, None ) . unwrap ( ) ;
183
199
pass_along_path ( & nodes) ;
184
200
}
185
201
@@ -190,8 +206,12 @@ fn too_big_packet_error() {
190
206
let test_msg = OnionMessageContents :: Custom ( TestCustomMessage { } ) ;
191
207
192
208
let hop_node_id = nodes[ 1 ] . get_node_pk ( ) ;
193
- let hops = [ hop_node_id; 400 ] ;
194
- let err = nodes[ 0 ] . messenger . send_onion_message ( & hops, Destination :: Node ( hop_node_id) , test_msg, None ) . unwrap_err ( ) ;
209
+ let hops = vec ! [ hop_node_id; 400 ] ;
210
+ let path = OnionMessagePath {
211
+ intermediate_nodes : hops,
212
+ destination : Destination :: Node ( hop_node_id) ,
213
+ } ;
214
+ let err = nodes[ 0 ] . messenger . send_onion_message ( path, test_msg, None ) . unwrap_err ( ) ;
195
215
assert_eq ! ( err, SendError :: TooBigPacket ) ;
196
216
}
197
217
@@ -204,13 +224,21 @@ fn we_are_intro_node() {
204
224
205
225
let secp_ctx = Secp256k1 :: new ( ) ;
206
226
let blinded_path = BlindedPath :: new_for_message ( & [ nodes[ 0 ] . get_node_pk ( ) , nodes[ 1 ] . get_node_pk ( ) , nodes[ 2 ] . get_node_pk ( ) ] , & * nodes[ 2 ] . keys_manager , & secp_ctx) . unwrap ( ) ;
227
+ let path = OnionMessagePath {
228
+ intermediate_nodes : vec ! [ ] ,
229
+ destination : Destination :: BlindedPath ( blinded_path) ,
230
+ } ;
207
231
208
- nodes[ 0 ] . messenger . send_onion_message ( & [ ] , Destination :: BlindedPath ( blinded_path ) , OnionMessageContents :: Custom ( test_msg. clone ( ) ) , None ) . unwrap ( ) ;
232
+ nodes[ 0 ] . messenger . send_onion_message ( path , OnionMessageContents :: Custom ( test_msg. clone ( ) ) , None ) . unwrap ( ) ;
209
233
pass_along_path ( & nodes) ;
210
234
211
235
// Try with a two-hop blinded path where we are the introduction node.
212
236
let blinded_path = BlindedPath :: new_for_message ( & [ nodes[ 0 ] . get_node_pk ( ) , nodes[ 1 ] . get_node_pk ( ) ] , & * nodes[ 1 ] . keys_manager , & secp_ctx) . unwrap ( ) ;
213
- nodes[ 0 ] . messenger . send_onion_message ( & [ ] , Destination :: BlindedPath ( blinded_path) , OnionMessageContents :: Custom ( test_msg) , None ) . unwrap ( ) ;
237
+ let path = OnionMessagePath {
238
+ intermediate_nodes : vec ! [ ] ,
239
+ destination : Destination :: BlindedPath ( blinded_path) ,
240
+ } ;
241
+ nodes[ 0 ] . messenger . send_onion_message ( path, OnionMessageContents :: Custom ( test_msg) , None ) . unwrap ( ) ;
214
242
nodes. remove ( 2 ) ;
215
243
pass_along_path ( & nodes) ;
216
244
}
@@ -225,14 +253,22 @@ fn invalid_blinded_path_error() {
225
253
let secp_ctx = Secp256k1 :: new ( ) ;
226
254
let mut blinded_path = BlindedPath :: new_for_message ( & [ nodes[ 1 ] . get_node_pk ( ) , nodes[ 2 ] . get_node_pk ( ) ] , & * nodes[ 2 ] . keys_manager , & secp_ctx) . unwrap ( ) ;
227
255
blinded_path. blinded_hops . clear ( ) ;
228
- let err = nodes[ 0 ] . messenger . send_onion_message ( & [ ] , Destination :: BlindedPath ( blinded_path) , OnionMessageContents :: Custom ( test_msg. clone ( ) ) , None ) . unwrap_err ( ) ;
256
+ let path = OnionMessagePath {
257
+ intermediate_nodes : vec ! [ ] ,
258
+ destination : Destination :: BlindedPath ( blinded_path) ,
259
+ } ;
260
+ let err = nodes[ 0 ] . messenger . send_onion_message ( path, OnionMessageContents :: Custom ( test_msg. clone ( ) ) , None ) . unwrap_err ( ) ;
229
261
assert_eq ! ( err, SendError :: TooFewBlindedHops ) ;
230
262
231
263
// 1 hop
232
264
let mut blinded_path = BlindedPath :: new_for_message ( & [ nodes[ 1 ] . get_node_pk ( ) , nodes[ 2 ] . get_node_pk ( ) ] , & * nodes[ 2 ] . keys_manager , & secp_ctx) . unwrap ( ) ;
233
265
blinded_path. blinded_hops . remove ( 0 ) ;
234
266
assert_eq ! ( blinded_path. blinded_hops. len( ) , 1 ) ;
235
- let err = nodes[ 0 ] . messenger . send_onion_message ( & [ ] , Destination :: BlindedPath ( blinded_path) , OnionMessageContents :: Custom ( test_msg) , None ) . unwrap_err ( ) ;
267
+ let path = OnionMessagePath {
268
+ intermediate_nodes : vec ! [ ] ,
269
+ destination : Destination :: BlindedPath ( blinded_path) ,
270
+ } ;
271
+ let err = nodes[ 0 ] . messenger . send_onion_message ( path, OnionMessageContents :: Custom ( test_msg) , None ) . unwrap_err ( ) ;
236
272
assert_eq ! ( err, SendError :: TooFewBlindedHops ) ;
237
273
}
238
274
@@ -243,8 +279,12 @@ fn reply_path() {
243
279
let secp_ctx = Secp256k1 :: new ( ) ;
244
280
245
281
// Destination::Node
282
+ let path = OnionMessagePath {
283
+ intermediate_nodes : vec ! [ nodes[ 1 ] . get_node_pk( ) , nodes[ 2 ] . get_node_pk( ) ] ,
284
+ destination : Destination :: Node ( nodes[ 3 ] . get_node_pk ( ) ) ,
285
+ } ;
246
286
let reply_path = BlindedPath :: new_for_message ( & [ nodes[ 2 ] . get_node_pk ( ) , nodes[ 1 ] . get_node_pk ( ) , nodes[ 0 ] . get_node_pk ( ) ] , & * nodes[ 0 ] . keys_manager , & secp_ctx) . unwrap ( ) ;
247
- nodes[ 0 ] . messenger . send_onion_message ( & [ nodes [ 1 ] . get_node_pk ( ) , nodes [ 2 ] . get_node_pk ( ) ] , Destination :: Node ( nodes [ 3 ] . get_node_pk ( ) ) , OnionMessageContents :: Custom ( test_msg. clone ( ) ) , Some ( reply_path) ) . unwrap ( ) ;
287
+ nodes[ 0 ] . messenger . send_onion_message ( path , OnionMessageContents :: Custom ( test_msg. clone ( ) ) , Some ( reply_path) ) . unwrap ( ) ;
248
288
pass_along_path ( & nodes) ;
249
289
// Make sure the last node successfully decoded the reply path.
250
290
nodes[ 3 ] . logger . assert_log_contains (
@@ -253,9 +293,13 @@ fn reply_path() {
253
293
254
294
// Destination::BlindedPath
255
295
let blinded_path = BlindedPath :: new_for_message ( & [ nodes[ 1 ] . get_node_pk ( ) , nodes[ 2 ] . get_node_pk ( ) , nodes[ 3 ] . get_node_pk ( ) ] , & * nodes[ 3 ] . keys_manager , & secp_ctx) . unwrap ( ) ;
296
+ let path = OnionMessagePath {
297
+ intermediate_nodes : vec ! [ ] ,
298
+ destination : Destination :: BlindedPath ( blinded_path) ,
299
+ } ;
256
300
let reply_path = BlindedPath :: new_for_message ( & [ nodes[ 2 ] . get_node_pk ( ) , nodes[ 1 ] . get_node_pk ( ) , nodes[ 0 ] . get_node_pk ( ) ] , & * nodes[ 0 ] . keys_manager , & secp_ctx) . unwrap ( ) ;
257
301
258
- nodes[ 0 ] . messenger . send_onion_message ( & [ ] , Destination :: BlindedPath ( blinded_path ) , OnionMessageContents :: Custom ( test_msg) , Some ( reply_path) ) . unwrap ( ) ;
302
+ nodes[ 0 ] . messenger . send_onion_message ( path , OnionMessageContents :: Custom ( test_msg) , Some ( reply_path) ) . unwrap ( ) ;
259
303
pass_along_path ( & nodes) ;
260
304
nodes[ 3 ] . logger . assert_log_contains (
261
305
"lightning::onion_message::messenger" ,
@@ -279,18 +323,26 @@ fn invalid_custom_message_type() {
279
323
}
280
324
281
325
let test_msg = OnionMessageContents :: Custom ( InvalidCustomMessage { } ) ;
282
- let err = nodes[ 0 ] . messenger . send_onion_message ( & [ ] , Destination :: Node ( nodes[ 1 ] . get_node_pk ( ) ) , test_msg, None ) . unwrap_err ( ) ;
326
+ let path = OnionMessagePath {
327
+ intermediate_nodes : vec ! [ ] ,
328
+ destination : Destination :: Node ( nodes[ 1 ] . get_node_pk ( ) ) ,
329
+ } ;
330
+ let err = nodes[ 0 ] . messenger . send_onion_message ( path, test_msg, None ) . unwrap_err ( ) ;
283
331
assert_eq ! ( err, SendError :: InvalidMessage ) ;
284
332
}
285
333
286
334
#[ test]
287
335
fn peer_buffer_full ( ) {
288
336
let nodes = create_nodes ( 2 ) ;
289
337
let test_msg = TestCustomMessage { } ;
338
+ let path = OnionMessagePath {
339
+ intermediate_nodes : vec ! [ ] ,
340
+ destination : Destination :: Node ( nodes[ 1 ] . get_node_pk ( ) ) ,
341
+ } ;
290
342
for _ in 0 ..188 { // Based on MAX_PER_PEER_BUFFER_SIZE in OnionMessenger
291
- nodes[ 0 ] . messenger . send_onion_message ( & [ ] , Destination :: Node ( nodes [ 1 ] . get_node_pk ( ) ) , OnionMessageContents :: Custom ( test_msg. clone ( ) ) , None ) . unwrap ( ) ;
343
+ nodes[ 0 ] . messenger . send_onion_message ( path . clone ( ) , OnionMessageContents :: Custom ( test_msg. clone ( ) ) , None ) . unwrap ( ) ;
292
344
}
293
- let err = nodes[ 0 ] . messenger . send_onion_message ( & [ ] , Destination :: Node ( nodes [ 1 ] . get_node_pk ( ) ) , OnionMessageContents :: Custom ( test_msg) , None ) . unwrap_err ( ) ;
345
+ let err = nodes[ 0 ] . messenger . send_onion_message ( path , OnionMessageContents :: Custom ( test_msg) , None ) . unwrap_err ( ) ;
294
346
assert_eq ! ( err, SendError :: BufferFull ) ;
295
347
}
296
348
@@ -302,11 +354,15 @@ fn many_hops() {
302
354
let nodes = create_nodes ( num_nodes as u8 ) ;
303
355
let test_msg = OnionMessageContents :: Custom ( TestCustomMessage { } ) ;
304
356
305
- let mut intermediates = vec ! [ ] ;
357
+ let mut intermediate_nodes = vec ! [ ] ;
306
358
for i in 1 ..( num_nodes-1 ) {
307
- intermediates . push ( nodes[ i] . get_node_pk ( ) ) ;
359
+ intermediate_nodes . push ( nodes[ i] . get_node_pk ( ) ) ;
308
360
}
309
361
310
- nodes[ 0 ] . messenger . send_onion_message ( & intermediates, Destination :: Node ( nodes[ num_nodes-1 ] . get_node_pk ( ) ) , test_msg, None ) . unwrap ( ) ;
362
+ let path = OnionMessagePath {
363
+ intermediate_nodes,
364
+ destination : Destination :: Node ( nodes[ num_nodes-1 ] . get_node_pk ( ) ) ,
365
+ } ;
366
+ nodes[ 0 ] . messenger . send_onion_message ( path, test_msg, None ) . unwrap ( ) ;
311
367
pass_along_path ( & nodes) ;
312
368
}
0 commit comments