@@ -476,6 +476,7 @@ pub trait SimNetwork: Send + Sync {
476476 & mut self ,
477477 source : PublicKey ,
478478 route : Route ,
479+ custom_records : Option < CustomRecords > ,
479480 payment_hash : PaymentHash ,
480481 sender : Sender < Result < PaymentResult , LightningError > > ,
481482 ) ;
@@ -529,14 +530,18 @@ impl<'a, T: SimNetwork> SimNode<'a, T> {
529530 }
530531 }
531532
532- /// Dispatches a payment to a specified route.
533+ /// Dispatches a payment to a specified route. If `custom_records` is `Some`, they will be attached to the outgoing
534+ /// update_add_htlc, otherwise [`SimGraph::default_custom_records`] will be used if `None`. If default custom records
535+ /// are configured, but you want to send a payment without them specify `Some(CustomRecords::default())`.
536+ ///
533537 /// The [`lightning::routing::router::build_route_from_hops`] function can be used to build the route to be passed here.
534538 ///
535539 /// **Note:** The payment hash passed in here should be used in track_payment to track the payment outcome.
536540 pub async fn send_to_route (
537541 & mut self ,
538542 route : Route ,
539543 payment_hash : PaymentHash ,
544+ custom_records : Option < CustomRecords > ,
540545 ) -> Result < ( ) , LightningError > {
541546 let ( sender, receiver) = channel ( ) ;
542547
@@ -552,10 +557,13 @@ impl<'a, T: SimNetwork> SimNode<'a, T> {
552557 } ,
553558 }
554559
555- self . network
556- . lock ( )
557- . await
558- . dispatch_payment ( self . info . pubkey , route, payment_hash, sender) ;
560+ self . network . lock ( ) . await . dispatch_payment (
561+ self . info . pubkey ,
562+ route,
563+ custom_records,
564+ payment_hash,
565+ sender,
566+ ) ;
559567
560568 Ok ( ( ) )
561569 }
@@ -666,10 +674,13 @@ impl<T: SimNetwork> LightningNode for SimNode<'_, T> {
666674 } ;
667675
668676 // If we did successfully obtain a route, dispatch the payment through the network and then report success.
669- self . network
670- . lock ( )
671- . await
672- . dispatch_payment ( self . info . pubkey , route, payment_hash, sender) ;
677+ self . network . lock ( ) . await . dispatch_payment (
678+ self . info . pubkey ,
679+ route,
680+ None , // Default custom records.
681+ payment_hash,
682+ sender,
683+ ) ;
673684
674685 Ok ( payment_hash)
675686 }
@@ -1092,11 +1103,13 @@ impl SimNetwork for SimGraph {
10921103 /// dispatch_payment asynchronously propagates a payment through the simulated network, returning a tracking
10931104 /// channel that can be used to obtain the result of the payment. At present, MPP payments are not supported.
10941105 /// In future, we'll allow multiple paths for a single payment, so we allow the trait to accept a route with
1095- /// multiple paths to avoid future refactoring.
1106+ /// multiple paths to avoid future refactoring. If custom records are not provided,
1107+ /// [`SimGraph::default_custom_records`] will be sent with the payment.
10961108 fn dispatch_payment (
10971109 & mut self ,
10981110 source : PublicKey ,
10991111 route : Route ,
1112+ custom_records : Option < CustomRecords > ,
11001113 payment_hash : PaymentHash ,
11011114 sender : Sender < Result < PaymentResult , LightningError > > ,
11021115 ) {
@@ -1124,7 +1137,7 @@ impl SimNetwork for SimGraph {
11241137 payment_hash,
11251138 sender,
11261139 interceptors : self . interceptors . clone ( ) ,
1127- custom_records : self . default_custom_records . clone ( ) ,
1140+ custom_records : custom_records . unwrap_or ( self . default_custom_records . clone ( ) ) ,
11281141 shutdown_signal : self . shutdown_signal . clone ( ) ,
11291142 } ) ) ;
11301143 }
@@ -1874,6 +1887,7 @@ mod tests {
18741887 & mut self ,
18751888 source: PublicKey ,
18761889 route: Route ,
1890+ custom_records: Option <CustomRecords >,
18771891 payment_hash: PaymentHash ,
18781892 sender: Sender <Result <PaymentResult , LightningError >>,
18791893 ) ;
@@ -1924,7 +1938,11 @@ mod tests {
19241938 . await
19251939 . expect_dispatch_payment ( )
19261940 . returning (
1927- move |_, route : Route , _, sender : Sender < Result < PaymentResult , LightningError > > | {
1941+ move |_,
1942+ route : Route ,
1943+ _: Option < CustomRecords > ,
1944+ _,
1945+ sender : Sender < Result < PaymentResult , LightningError > > | {
19281946 // If we've reached dispatch, we must have at least one path, grab the last hop to match the
19291947 // receiver.
19301948 let receiver = route. paths [ 0 ] . hops . last ( ) . unwrap ( ) . pubkey ;
@@ -2085,7 +2103,7 @@ mod tests {
20852103
20862104 let ( sender, receiver) = oneshot:: channel ( ) ;
20872105 self . graph
2088- . dispatch_payment ( source, route. clone ( ) , PaymentHash ( [ 1 ; 32 ] ) , sender) ;
2106+ . dispatch_payment ( source, route. clone ( ) , None , PaymentHash ( [ 1 ; 32 ] ) , sender) ;
20892107
20902108 let payment_result = timeout ( Duration :: from_millis ( 10 ) , receiver) . await ;
20912109 // Assert that we receive from the channel or fail.
@@ -2312,7 +2330,7 @@ mod tests {
23122330
23132331 let preimage = PaymentPreimage ( rand:: random ( ) ) ;
23142332 let payment_hash = preimage. into ( ) ;
2315- node. send_to_route ( route, payment_hash) . await . unwrap ( ) ;
2333+ node. send_to_route ( route, payment_hash, None ) . await . unwrap ( ) ;
23162334
23172335 let ( _, shutdown_listener) = triggered:: trigger ( ) ;
23182336 let result = node
0 commit comments