@@ -13,7 +13,7 @@ use crate::blinded_path::BlindedPath;
1313use crate :: sign:: { NodeSigner , Recipient } ;
1414use crate :: ln:: features:: InitFeatures ;
1515use 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 } ;
1717use crate :: util:: ser:: { Writeable , Writer } ;
1818use crate :: util:: test_utils;
1919
@@ -146,7 +146,11 @@ fn one_hop() {
146146 let nodes = create_nodes ( 2 ) ;
147147 let test_msg = OnionMessageContents :: Custom ( TestCustomMessage { } ) ;
148148
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 ( ) ;
150154 pass_along_path ( & nodes) ;
151155}
152156
@@ -155,7 +159,11 @@ fn two_unblinded_hops() {
155159 let nodes = create_nodes ( 3 ) ;
156160 let test_msg = OnionMessageContents :: Custom ( TestCustomMessage { } ) ;
157161
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 ( ) ;
159167 pass_along_path ( & nodes) ;
160168}
161169
@@ -166,8 +174,12 @@ fn two_unblinded_two_blinded() {
166174
167175 let secp_ctx = Secp256k1 :: new ( ) ;
168176 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+ } ;
169181
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 ( ) ;
171183 pass_along_path ( & nodes) ;
172184}
173185
@@ -178,8 +190,12 @@ fn three_blinded_hops() {
178190
179191 let secp_ctx = Secp256k1 :: new ( ) ;
180192 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+ } ;
181197
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 ( ) ;
183199 pass_along_path ( & nodes) ;
184200}
185201
@@ -190,8 +206,12 @@ fn too_big_packet_error() {
190206 let test_msg = OnionMessageContents :: Custom ( TestCustomMessage { } ) ;
191207
192208 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 ( ) ;
195215 assert_eq ! ( err, SendError :: TooBigPacket ) ;
196216}
197217
@@ -204,13 +224,21 @@ fn we_are_intro_node() {
204224
205225 let secp_ctx = Secp256k1 :: new ( ) ;
206226 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+ } ;
207231
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 ( ) ;
209233 pass_along_path ( & nodes) ;
210234
211235 // Try with a two-hop blinded path where we are the introduction node.
212236 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 ( ) ;
214242 nodes. remove ( 2 ) ;
215243 pass_along_path ( & nodes) ;
216244}
@@ -225,14 +253,22 @@ fn invalid_blinded_path_error() {
225253 let secp_ctx = Secp256k1 :: new ( ) ;
226254 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 ( ) ;
227255 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 ( ) ;
229261 assert_eq ! ( err, SendError :: TooFewBlindedHops ) ;
230262
231263 // 1 hop
232264 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 ( ) ;
233265 blinded_path. blinded_hops . remove ( 0 ) ;
234266 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 ( ) ;
236272 assert_eq ! ( err, SendError :: TooFewBlindedHops ) ;
237273}
238274
@@ -243,8 +279,12 @@ fn reply_path() {
243279 let secp_ctx = Secp256k1 :: new ( ) ;
244280
245281 // 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+ } ;
246286 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 ( ) ;
248288 pass_along_path ( & nodes) ;
249289 // Make sure the last node successfully decoded the reply path.
250290 nodes[ 3 ] . logger . assert_log_contains (
@@ -253,9 +293,13 @@ fn reply_path() {
253293
254294 // Destination::BlindedPath
255295 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+ } ;
256300 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 ( ) ;
257301
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 ( ) ;
259303 pass_along_path ( & nodes) ;
260304 nodes[ 3 ] . logger . assert_log_contains (
261305 "lightning::onion_message::messenger" ,
@@ -279,18 +323,26 @@ fn invalid_custom_message_type() {
279323 }
280324
281325 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 ( ) ;
283331 assert_eq ! ( err, SendError :: InvalidMessage ) ;
284332}
285333
286334#[ test]
287335fn peer_buffer_full ( ) {
288336 let nodes = create_nodes ( 2 ) ;
289337 let test_msg = TestCustomMessage { } ;
338+ let path = OnionMessagePath {
339+ intermediate_nodes : vec ! [ ] ,
340+ destination : Destination :: Node ( nodes[ 1 ] . get_node_pk ( ) ) ,
341+ } ;
290342 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 ( ) ;
292344 }
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 ( ) ;
294346 assert_eq ! ( err, SendError :: BufferFull ) ;
295347}
296348
@@ -302,11 +354,15 @@ fn many_hops() {
302354 let nodes = create_nodes ( num_nodes as u8 ) ;
303355 let test_msg = OnionMessageContents :: Custom ( TestCustomMessage { } ) ;
304356
305- let mut intermediates = vec ! [ ] ;
357+ let mut intermediate_nodes = vec ! [ ] ;
306358 for i in 1 ..( num_nodes-1 ) {
307- intermediates . push ( nodes[ i] . get_node_pk ( ) ) ;
359+ intermediate_nodes . push ( nodes[ i] . get_node_pk ( ) ) ;
308360 }
309361
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 ( ) ;
311367 pass_along_path ( & nodes) ;
312368}
0 commit comments