@@ -496,6 +496,7 @@ pub(crate) enum HTLCSource {
496
496
first_hop_htlc_msat : u64 ,
497
497
payment_id : PaymentId ,
498
498
payment_secret : Option < PaymentSecret > ,
499
+ payment_metadata : Option < Vec < u8 > > ,
499
500
payee : Option < Payee > ,
500
501
} ,
501
502
}
@@ -507,12 +508,13 @@ impl core::hash::Hash for HTLCSource {
507
508
0u8 . hash ( hasher) ;
508
509
prev_hop_data. hash ( hasher) ;
509
510
} ,
510
- HTLCSource :: OutboundRoute { path, session_priv, payment_id, payment_secret, first_hop_htlc_msat, payee } => {
511
+ HTLCSource :: OutboundRoute { path, session_priv, payment_id, payment_secret, payment_metadata , first_hop_htlc_msat, payee } => {
511
512
1u8 . hash ( hasher) ;
512
513
path. hash ( hasher) ;
513
514
session_priv[ ..] . hash ( hasher) ;
514
515
payment_id. hash ( hasher) ;
515
516
payment_secret. hash ( hasher) ;
517
+ payment_metadata. hash ( hasher) ;
516
518
first_hop_htlc_msat. hash ( hasher) ;
517
519
payee. hash ( hasher) ;
518
520
} ,
@@ -528,6 +530,7 @@ impl HTLCSource {
528
530
first_hop_htlc_msat : 0 ,
529
531
payment_id : PaymentId ( [ 2 ; 32 ] ) ,
530
532
payment_secret : None ,
533
+ payment_metadata : None ,
531
534
payee : None ,
532
535
}
533
536
}
@@ -733,6 +736,7 @@ pub(crate) enum PendingOutboundPayment {
733
736
session_privs : HashSet < [ u8 ; 32 ] > ,
734
737
payment_hash : PaymentHash ,
735
738
payment_secret : Option < PaymentSecret > ,
739
+ payment_metadata : Option < Vec < u8 > > ,
736
740
pending_amt_msat : u64 ,
737
741
/// Used to track the fee paid. Only present if the payment was serialized on 0.0.103+.
738
742
pending_fee_msat : Option < u64 > ,
@@ -2429,15 +2433,15 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2429
2433
}
2430
2434
2431
2435
// Only public for testing, this should otherwise never be called direcly
2432
- pub ( crate ) fn send_payment_along_path ( & self , path : & Vec < RouteHop > , payee : & Option < Payee > , payment_hash : & PaymentHash , payment_secret : & Option < PaymentSecret > , total_value : u64 , cur_height : u32 , payment_id : PaymentId , keysend_preimage : & Option < PaymentPreimage > ) -> Result < ( ) , APIError > {
2436
+ pub ( crate ) fn send_payment_along_path ( & self , path : & Vec < RouteHop > , payee : & Option < Payee > , payment_hash : & PaymentHash , payment_secret : & Option < PaymentSecret > , payment_metadata : & Option < Vec < u8 > > , total_value : u64 , cur_height : u32 , payment_id : PaymentId , keysend_preimage : & Option < PaymentPreimage > ) -> Result < ( ) , APIError > {
2433
2437
log_trace ! ( self . logger, "Attempting to send payment for path with next hop {}" , path. first( ) . unwrap( ) . short_channel_id) ;
2434
2438
let prng_seed = self . keys_manager . get_secure_random_bytes ( ) ;
2435
2439
let session_priv_bytes = self . keys_manager . get_secure_random_bytes ( ) ;
2436
2440
let session_priv = SecretKey :: from_slice ( & session_priv_bytes[ ..] ) . expect ( "RNG is busted" ) ;
2437
2441
2438
2442
let onion_keys = onion_utils:: construct_onion_keys ( & self . secp_ctx , & path, & session_priv)
2439
2443
. map_err ( |_| APIError :: RouteError { err : "Pubkey along hop was maliciously selected" } ) ?;
2440
- let ( onion_payloads, htlc_msat, htlc_cltv) = onion_utils:: build_onion_payloads ( path, total_value, payment_secret, cur_height, keysend_preimage) ?;
2444
+ let ( onion_payloads, htlc_msat, htlc_cltv) = onion_utils:: build_onion_payloads ( path, total_value, payment_secret, payment_metadata . clone ( ) , cur_height, keysend_preimage) ?;
2441
2445
if onion_utils:: route_size_insane ( & onion_payloads) {
2442
2446
return Err ( APIError :: RouteError { err : "Route size too large considering onion data" } ) ;
2443
2447
}
@@ -2471,6 +2475,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2471
2475
pending_fee_msat: Some ( 0 ) ,
2472
2476
payment_hash: * payment_hash,
2473
2477
payment_secret: * payment_secret,
2478
+ payment_metadata: payment_metadata. clone( ) ,
2474
2479
starting_block_height: self . best_block. read( ) . unwrap( ) . height( ) ,
2475
2480
total_msat: total_value,
2476
2481
} ) ;
@@ -2494,6 +2499,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2494
2499
first_hop_htlc_msat: htlc_msat,
2495
2500
payment_id,
2496
2501
payment_secret: payment_secret. clone( ) ,
2502
+ payment_metadata: payment_metadata. clone( ) ,
2497
2503
payee: payee. clone( ) ,
2498
2504
} , onion_packet, & self . logger) ,
2499
2505
channel_state, chan)
@@ -2581,7 +2587,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2581
2587
self . send_payment_internal ( route, payment_hash, payment_secret, None , None , None )
2582
2588
}
2583
2589
2584
- fn send_payment_internal ( & self , route : & Route , payment_hash : PaymentHash , payment_secret : & Option < PaymentSecret > , keysend_preimage : Option < PaymentPreimage > , payment_id : Option < PaymentId > , recv_value_msat : Option < u64 > ) -> Result < PaymentId , PaymentSendFailure > {
2590
+ fn send_payment_internal ( & self , route : & Route , payment_hash : PaymentHash , payment_secret : & Option < PaymentSecret > , payment_metadata : Option < Vec < u8 > > , keysend_preimage : Option < PaymentPreimage > , payment_id : Option < PaymentId > , recv_value_msat : Option < u64 > ) -> Result < PaymentId , PaymentSendFailure > {
2585
2591
if route. paths . len ( ) < 1 {
2586
2592
return Err ( PaymentSendFailure :: ParameterError ( APIError :: RouteError { err : "There must be at least one path to send over" } ) ) ;
2587
2593
}
@@ -2623,7 +2629,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2623
2629
let cur_height = self . best_block . read ( ) . unwrap ( ) . height ( ) + 1 ;
2624
2630
let mut results = Vec :: new ( ) ;
2625
2631
for path in route. paths . iter ( ) {
2626
- results. push ( self . send_payment_along_path ( & path, & route. payee , & payment_hash, payment_secret, total_value, cur_height, payment_id, & keysend_preimage) ) ;
2632
+ results. push ( self . send_payment_along_path ( & path, & route. payee , & payment_hash, payment_secret, & payment_metadata , total_value, cur_height, payment_id, & keysend_preimage) ) ;
2627
2633
}
2628
2634
let mut has_ok = false ;
2629
2635
let mut has_err = false ;
@@ -2686,20 +2692,20 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2686
2692
}
2687
2693
}
2688
2694
2689
- let ( total_msat, payment_hash, payment_secret) = {
2695
+ let ( total_msat, payment_hash, payment_secret, payment_metadata ) = {
2690
2696
let outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
2691
2697
if let Some ( payment) = outbounds. get ( & payment_id) {
2692
2698
match payment {
2693
2699
PendingOutboundPayment :: Retryable {
2694
- total_msat, payment_hash, payment_secret, pending_amt_msat, ..
2700
+ total_msat, payment_hash, payment_secret, pending_amt_msat, payment_metadata , ..
2695
2701
} => {
2696
2702
let retry_amt_msat: u64 = route. paths . iter ( ) . map ( |path| path. last ( ) . unwrap ( ) . fee_msat ) . sum ( ) ;
2697
2703
if retry_amt_msat + * pending_amt_msat > * total_msat * ( 100 + RETRY_OVERFLOW_PERCENTAGE ) / 100 {
2698
2704
return Err ( PaymentSendFailure :: ParameterError ( APIError :: APIMisuseError {
2699
2705
err : format ! ( "retry_amt_msat of {} will put pending_amt_msat (currently: {}) more than 10% over total_payment_amt_msat of {}" , retry_amt_msat, pending_amt_msat, total_msat) . to_string ( )
2700
2706
} ) )
2701
2707
}
2702
- ( * total_msat, * payment_hash, * payment_secret)
2708
+ ( * total_msat, * payment_hash, * payment_secret, payment_metadata . clone ( ) )
2703
2709
} ,
2704
2710
PendingOutboundPayment :: Legacy { .. } => {
2705
2711
return Err ( PaymentSendFailure :: ParameterError ( APIError :: APIMisuseError {
@@ -2723,7 +2729,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2723
2729
} ) )
2724
2730
}
2725
2731
} ;
2726
- return self . send_payment_internal ( route, payment_hash, & payment_secret, None , Some ( payment_id) , Some ( total_msat) ) . map ( |_| ( ) )
2732
+ return self . send_payment_internal ( route, payment_hash, & payment_secret, payment_metadata , None , Some ( payment_id) , Some ( total_msat) ) . map ( |_| ( ) )
2727
2733
}
2728
2734
2729
2735
/// Signals that no further retries for the given payment will occur.
@@ -2777,7 +2783,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2777
2783
None => PaymentPreimage ( self . keys_manager . get_secure_random_bytes ( ) ) ,
2778
2784
} ;
2779
2785
let payment_hash = PaymentHash ( Sha256 :: hash ( & preimage. 0 ) . into_inner ( ) ) ;
2780
- match self . send_payment_internal ( route, payment_hash, & None , Some ( preimage) , None , None ) {
2786
+ match self . send_payment_internal ( route, payment_hash, & None , None , Some ( preimage) , None , None ) {
2781
2787
Ok ( payment_id) => Ok ( ( payment_hash, payment_id) ) ,
2782
2788
Err ( e) => Err ( e)
2783
2789
}
@@ -6001,6 +6007,7 @@ impl Readable for HTLCSource {
6001
6007
let mut path = Some ( Vec :: new ( ) ) ;
6002
6008
let mut payment_id = None ;
6003
6009
let mut payment_secret = None ;
6010
+ let mut payment_metadata = None ;
6004
6011
let mut payee = None ;
6005
6012
read_tlv_fields ! ( reader, {
6006
6013
( 0 , session_priv, required) ,
@@ -6009,6 +6016,7 @@ impl Readable for HTLCSource {
6009
6016
( 3 , payment_secret, option) ,
6010
6017
( 4 , path, vec_type) ,
6011
6018
( 5 , payee, option) ,
6019
+ ( 7 , payment_metadata, option) ,
6012
6020
} ) ;
6013
6021
if payment_id. is_none ( ) {
6014
6022
// For backwards compat, if there was no payment_id written, use the session_priv bytes
@@ -6021,6 +6029,7 @@ impl Readable for HTLCSource {
6021
6029
path : path. unwrap ( ) ,
6022
6030
payment_id : payment_id. unwrap ( ) ,
6023
6031
payment_secret,
6032
+ payment_metadata,
6024
6033
payee,
6025
6034
} )
6026
6035
}
@@ -6033,7 +6042,7 @@ impl Readable for HTLCSource {
6033
6042
impl Writeable for HTLCSource {
6034
6043
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: io:: Error > {
6035
6044
match self {
6036
- HTLCSource :: OutboundRoute { ref session_priv, ref first_hop_htlc_msat, ref path, payment_id, payment_secret, payee } => {
6045
+ HTLCSource :: OutboundRoute { ref session_priv, ref first_hop_htlc_msat, ref path, payment_id, payment_secret, ref payment_metadata , payee } => {
6037
6046
0u8 . write ( writer) ?;
6038
6047
let payment_id_opt = Some ( payment_id) ;
6039
6048
write_tlv_fields ! ( writer, {
@@ -6043,6 +6052,7 @@ impl Writeable for HTLCSource {
6043
6052
( 3 , payment_secret, option) ,
6044
6053
( 4 , path, vec_type) ,
6045
6054
( 5 , payee, option) ,
6055
+ ( 7 , payment_metadata, option) ,
6046
6056
} ) ;
6047
6057
}
6048
6058
HTLCSource :: PreviousHopData ( ref field) => {
@@ -6097,6 +6107,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
6097
6107
( 0 , session_privs, required) ,
6098
6108
( 1 , pending_fee_msat, option) ,
6099
6109
( 2 , payment_hash, required) ,
6110
+ ( 3 , payment_metadata, option) ,
6100
6111
( 4 , payment_secret, option) ,
6101
6112
( 6 , total_msat, required) ,
6102
6113
( 8 , pending_amt_msat, required) ,
@@ -6549,7 +6560,7 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
6549
6560
for ( _, monitor) in args. channel_monitors {
6550
6561
if by_id. get ( & monitor. get_funding_txo ( ) . 0 . to_channel_id ( ) ) . is_none ( ) {
6551
6562
for ( htlc_source, htlc) in monitor. get_pending_outbound_htlcs ( ) {
6552
- if let HTLCSource :: OutboundRoute { payment_id, session_priv, path, payment_secret, .. } = htlc_source {
6563
+ if let HTLCSource :: OutboundRoute { payment_id, session_priv, path, payment_secret, payment_metadata , .. } = htlc_source {
6553
6564
if path. is_empty ( ) {
6554
6565
log_error ! ( args. logger, "Got an empty path for a pending payment" ) ;
6555
6566
return Err ( DecodeError :: InvalidValue ) ;
@@ -6569,6 +6580,7 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
6569
6580
session_privs : [ session_priv_bytes] . iter ( ) . map ( |a| * a) . collect ( ) ,
6570
6581
payment_hash : htlc. payment_hash ,
6571
6582
payment_secret,
6583
+ payment_metadata,
6572
6584
pending_amt_msat : path_amt,
6573
6585
pending_fee_msat : Some ( path_fee) ,
6574
6586
total_msat : path_amt,
@@ -6802,7 +6814,7 @@ mod tests {
6802
6814
// Use the utility function send_payment_along_path to send the payment with MPP data which
6803
6815
// indicates there are more HTLCs coming.
6804
6816
let cur_height = CHAN_CONFIRM_DEPTH + 1 ; // route_payment calls send_payment, which adds 1 to the current height. So we do the same here to match.
6805
- nodes[ 0 ] . node . send_payment_along_path ( & route. paths [ 0 ] , & route. payee , & our_payment_hash, & Some ( payment_secret) , 200_000 , cur_height, payment_id, & None ) . unwrap ( ) ;
6817
+ nodes[ 0 ] . node . send_payment_along_path ( & route. paths [ 0 ] , & route. payee , & our_payment_hash, & Some ( payment_secret) , & None , 200_000 , cur_height, payment_id, & None ) . unwrap ( ) ;
6806
6818
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
6807
6819
let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
6808
6820
assert_eq ! ( events. len( ) , 1 ) ;
@@ -6832,7 +6844,7 @@ mod tests {
6832
6844
expect_payment_failed ! ( nodes[ 0 ] , our_payment_hash, true ) ;
6833
6845
6834
6846
// Send the second half of the original MPP payment.
6835
- nodes[ 0 ] . node . send_payment_along_path ( & route. paths [ 0 ] , & route. payee , & our_payment_hash, & Some ( payment_secret) , 200_000 , cur_height, payment_id, & None ) . unwrap ( ) ;
6847
+ nodes[ 0 ] . node . send_payment_along_path ( & route. paths [ 0 ] , & route. payee , & our_payment_hash, & Some ( payment_secret) , & None , 200_000 , cur_height, payment_id, & None ) . unwrap ( ) ;
6836
6848
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
6837
6849
let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
6838
6850
assert_eq ! ( events. len( ) , 1 ) ;
@@ -7024,7 +7036,7 @@ mod tests {
7024
7036
7025
7037
let test_preimage = PaymentPreimage ( [ 42 ; 32 ] ) ;
7026
7038
let mismatch_payment_hash = PaymentHash ( [ 43 ; 32 ] ) ;
7027
- let _ = nodes[ 0 ] . node . send_payment_internal ( & route, mismatch_payment_hash, & None , Some ( test_preimage) , None , None ) . unwrap ( ) ;
7039
+ let _ = nodes[ 0 ] . node . send_payment_internal ( & route, mismatch_payment_hash, & None , None , Some ( test_preimage) , None , None ) . unwrap ( ) ;
7028
7040
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
7029
7041
7030
7042
let updates = get_htlc_update_msgs ! ( nodes[ 0 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
@@ -7068,7 +7080,7 @@ mod tests {
7068
7080
let test_preimage = PaymentPreimage ( [ 42 ; 32 ] ) ;
7069
7081
let test_secret = PaymentSecret ( [ 43 ; 32 ] ) ;
7070
7082
let payment_hash = PaymentHash ( Sha256 :: hash ( & test_preimage. 0 ) . into_inner ( ) ) ;
7071
- let _ = nodes[ 0 ] . node . send_payment_internal ( & route, payment_hash, & Some ( test_secret) , Some ( test_preimage) , None , None ) . unwrap ( ) ;
7083
+ let _ = nodes[ 0 ] . node . send_payment_internal ( & route, payment_hash, & Some ( test_secret) , None , Some ( test_preimage) , None , None ) . unwrap ( ) ;
7072
7084
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
7073
7085
7074
7086
let updates = get_htlc_update_msgs ! ( nodes[ 0 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
0 commit comments