@@ -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
payment_params : Option < PaymentParameters > ,
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, payment_params } => {
511
+ HTLCSource :: OutboundRoute { path, session_priv, payment_id, payment_secret, payment_metadata , first_hop_htlc_msat, payment_params } => {
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
payment_params. 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
payment_params : None ,
532
535
}
533
536
}
@@ -739,6 +742,7 @@ pub(crate) enum PendingOutboundPayment {
739
742
session_privs : HashSet < [ u8 ; 32 ] > ,
740
743
payment_hash : PaymentHash ,
741
744
payment_secret : Option < PaymentSecret > ,
745
+ payment_metadata : Option < Vec < u8 > > ,
742
746
pending_amt_msat : u64 ,
743
747
/// Used to track the fee paid. Only present if the payment was serialized on 0.0.103+.
744
748
pending_fee_msat : Option < u64 > ,
@@ -2433,15 +2437,15 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2433
2437
}
2434
2438
2435
2439
// Only public for testing, this should otherwise never be called direcly
2436
- pub ( crate ) fn send_payment_along_path ( & self , path : & Vec < RouteHop > , payment_params : & Option < PaymentParameters > , payment_hash : & PaymentHash , payment_secret : & Option < PaymentSecret > , total_value : u64 , cur_height : u32 , payment_id : PaymentId , keysend_preimage : & Option < PaymentPreimage > ) -> Result < ( ) , APIError > {
2440
+ pub ( crate ) fn send_payment_along_path ( & self , path : & Vec < RouteHop > , payment_params : & Option < PaymentParameters > , 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 > {
2437
2441
log_trace ! ( self . logger, "Attempting to send payment for path with next hop {}" , path. first( ) . unwrap( ) . short_channel_id) ;
2438
2442
let prng_seed = self . keys_manager . get_secure_random_bytes ( ) ;
2439
2443
let session_priv_bytes = self . keys_manager . get_secure_random_bytes ( ) ;
2440
2444
let session_priv = SecretKey :: from_slice ( & session_priv_bytes[ ..] ) . expect ( "RNG is busted" ) ;
2441
2445
2442
2446
let onion_keys = onion_utils:: construct_onion_keys ( & self . secp_ctx , & path, & session_priv)
2443
2447
. map_err ( |_| APIError :: RouteError { err : "Pubkey along hop was maliciously selected" } ) ?;
2444
- let ( onion_payloads, htlc_msat, htlc_cltv) = onion_utils:: build_onion_payloads ( path, total_value, payment_secret, cur_height, keysend_preimage) ?;
2448
+ let ( onion_payloads, htlc_msat, htlc_cltv) = onion_utils:: build_onion_payloads ( path, total_value, payment_secret, payment_metadata . clone ( ) , cur_height, keysend_preimage) ?;
2445
2449
if onion_utils:: route_size_insane ( & onion_payloads) {
2446
2450
return Err ( APIError :: RouteError { err : "Route size too large considering onion data" } ) ;
2447
2451
}
@@ -2475,6 +2479,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2475
2479
pending_fee_msat: Some ( 0 ) ,
2476
2480
payment_hash: * payment_hash,
2477
2481
payment_secret: * payment_secret,
2482
+ payment_metadata: payment_metadata. clone( ) ,
2478
2483
starting_block_height: self . best_block. read( ) . unwrap( ) . height( ) ,
2479
2484
total_msat: total_value,
2480
2485
} ) ;
@@ -2498,6 +2503,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2498
2503
first_hop_htlc_msat: htlc_msat,
2499
2504
payment_id,
2500
2505
payment_secret: payment_secret. clone( ) ,
2506
+ payment_metadata: payment_metadata. clone( ) ,
2501
2507
payment_params: payment_params. clone( ) ,
2502
2508
} , onion_packet, & self . logger) ,
2503
2509
channel_state, chan)
@@ -2582,10 +2588,10 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2582
2588
/// bit set (either as required or as available). If multiple paths are present in the Route,
2583
2589
/// we assume the invoice had the basic_mpp feature set.
2584
2590
pub fn send_payment ( & self , route : & Route , payment_hash : PaymentHash , payment_secret : & Option < PaymentSecret > ) -> Result < PaymentId , PaymentSendFailure > {
2585
- self . send_payment_internal ( route, payment_hash, payment_secret, None , None , None )
2591
+ self . send_payment_internal ( route, payment_hash, payment_secret, None , None , None , None )
2586
2592
}
2587
2593
2588
- 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 > {
2594
+ 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 > {
2589
2595
if route. paths . len ( ) < 1 {
2590
2596
return Err ( PaymentSendFailure :: ParameterError ( APIError :: RouteError { err : "There must be at least one path to send over" } ) ) ;
2591
2597
}
@@ -2627,7 +2633,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2627
2633
let cur_height = self . best_block . read ( ) . unwrap ( ) . height ( ) + 1 ;
2628
2634
let mut results = Vec :: new ( ) ;
2629
2635
for path in route. paths . iter ( ) {
2630
- results. push ( self . send_payment_along_path ( & path, & route. payment_params , & payment_hash, payment_secret, total_value, cur_height, payment_id, & keysend_preimage) ) ;
2636
+ results. push ( self . send_payment_along_path ( & path, & route. payment_params , & payment_hash, payment_secret, & payment_metadata , total_value, cur_height, payment_id, & keysend_preimage) ) ;
2631
2637
}
2632
2638
let mut has_ok = false ;
2633
2639
let mut has_err = false ;
@@ -2690,20 +2696,20 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2690
2696
}
2691
2697
}
2692
2698
2693
- let ( total_msat, payment_hash, payment_secret) = {
2699
+ let ( total_msat, payment_hash, payment_secret, payment_metadata ) = {
2694
2700
let outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
2695
2701
if let Some ( payment) = outbounds. get ( & payment_id) {
2696
2702
match payment {
2697
2703
PendingOutboundPayment :: Retryable {
2698
- total_msat, payment_hash, payment_secret, pending_amt_msat, ..
2704
+ total_msat, payment_hash, payment_secret, pending_amt_msat, payment_metadata , ..
2699
2705
} => {
2700
2706
let retry_amt_msat: u64 = route. paths . iter ( ) . map ( |path| path. last ( ) . unwrap ( ) . fee_msat ) . sum ( ) ;
2701
2707
if retry_amt_msat + * pending_amt_msat > * total_msat * ( 100 + RETRY_OVERFLOW_PERCENTAGE ) / 100 {
2702
2708
return Err ( PaymentSendFailure :: ParameterError ( APIError :: APIMisuseError {
2703
2709
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 ( )
2704
2710
} ) )
2705
2711
}
2706
- ( * total_msat, * payment_hash, * payment_secret)
2712
+ ( * total_msat, * payment_hash, * payment_secret, payment_metadata . clone ( ) )
2707
2713
} ,
2708
2714
PendingOutboundPayment :: Legacy { .. } => {
2709
2715
return Err ( PaymentSendFailure :: ParameterError ( APIError :: APIMisuseError {
@@ -2727,7 +2733,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2727
2733
} ) )
2728
2734
}
2729
2735
} ;
2730
- return self . send_payment_internal ( route, payment_hash, & payment_secret, None , Some ( payment_id) , Some ( total_msat) ) . map ( |_| ( ) )
2736
+ return self . send_payment_internal ( route, payment_hash, & payment_secret, payment_metadata , None , Some ( payment_id) , Some ( total_msat) ) . map ( |_| ( ) )
2731
2737
}
2732
2738
2733
2739
/// Signals that no further retries for the given payment will occur.
@@ -2781,7 +2787,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2781
2787
None => PaymentPreimage ( self . keys_manager . get_secure_random_bytes ( ) ) ,
2782
2788
} ;
2783
2789
let payment_hash = PaymentHash ( Sha256 :: hash ( & preimage. 0 ) . into_inner ( ) ) ;
2784
- match self . send_payment_internal ( route, payment_hash, & None , Some ( preimage) , None , None ) {
2790
+ match self . send_payment_internal ( route, payment_hash, & None , None , Some ( preimage) , None , None ) {
2785
2791
Ok ( payment_id) => Ok ( ( payment_hash, payment_id) ) ,
2786
2792
Err ( e) => Err ( e)
2787
2793
}
@@ -6006,13 +6012,15 @@ impl Readable for HTLCSource {
6006
6012
let mut payment_id = None ;
6007
6013
let mut payment_secret = None ;
6008
6014
let mut payment_params = None ;
6015
+ let mut payment_metadata = None ;
6009
6016
read_tlv_fields ! ( reader, {
6010
6017
( 0 , session_priv, required) ,
6011
6018
( 1 , payment_id, option) ,
6012
6019
( 2 , first_hop_htlc_msat, required) ,
6013
6020
( 3 , payment_secret, option) ,
6014
6021
( 4 , path, vec_type) ,
6015
6022
( 5 , payment_params, option) ,
6023
+ ( 7 , payment_metadata, option) ,
6016
6024
} ) ;
6017
6025
if payment_id. is_none ( ) {
6018
6026
// For backwards compat, if there was no payment_id written, use the session_priv bytes
@@ -6026,6 +6034,7 @@ impl Readable for HTLCSource {
6026
6034
payment_id : payment_id. unwrap ( ) ,
6027
6035
payment_secret,
6028
6036
payment_params,
6037
+ payment_metadata,
6029
6038
} )
6030
6039
}
6031
6040
1 => Ok ( HTLCSource :: PreviousHopData ( Readable :: read ( reader) ?) ) ,
@@ -6037,7 +6046,7 @@ impl Readable for HTLCSource {
6037
6046
impl Writeable for HTLCSource {
6038
6047
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: io:: Error > {
6039
6048
match self {
6040
- HTLCSource :: OutboundRoute { ref session_priv, ref first_hop_htlc_msat, ref path, payment_id, payment_secret, payment_params } => {
6049
+ HTLCSource :: OutboundRoute { ref session_priv, ref first_hop_htlc_msat, ref path, payment_id, payment_secret, ref payment_metadata , payment_params } => {
6041
6050
0u8 . write ( writer) ?;
6042
6051
let payment_id_opt = Some ( payment_id) ;
6043
6052
write_tlv_fields ! ( writer, {
@@ -6047,6 +6056,7 @@ impl Writeable for HTLCSource {
6047
6056
( 3 , payment_secret, option) ,
6048
6057
( 4 , path, vec_type) ,
6049
6058
( 5 , payment_params, option) ,
6059
+ ( 7 , payment_metadata, option) ,
6050
6060
} ) ;
6051
6061
}
6052
6062
HTLCSource :: PreviousHopData ( ref field) => {
@@ -6101,6 +6111,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
6101
6111
( 0 , session_privs, required) ,
6102
6112
( 1 , pending_fee_msat, option) ,
6103
6113
( 2 , payment_hash, required) ,
6114
+ ( 3 , payment_metadata, option) ,
6104
6115
( 4 , payment_secret, option) ,
6105
6116
( 6 , total_msat, required) ,
6106
6117
( 8 , pending_amt_msat, required) ,
@@ -6557,7 +6568,7 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
6557
6568
for ( _, monitor) in args. channel_monitors {
6558
6569
if by_id. get ( & monitor. get_funding_txo ( ) . 0 . to_channel_id ( ) ) . is_none ( ) {
6559
6570
for ( htlc_source, htlc) in monitor. get_pending_outbound_htlcs ( ) {
6560
- if let HTLCSource :: OutboundRoute { payment_id, session_priv, path, payment_secret, .. } = htlc_source {
6571
+ if let HTLCSource :: OutboundRoute { payment_id, session_priv, path, payment_secret, payment_metadata , .. } = htlc_source {
6561
6572
if path. is_empty ( ) {
6562
6573
log_error ! ( args. logger, "Got an empty path for a pending payment" ) ;
6563
6574
return Err ( DecodeError :: InvalidValue ) ;
@@ -6577,6 +6588,7 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
6577
6588
session_privs : [ session_priv_bytes] . iter ( ) . map ( |a| * a) . collect ( ) ,
6578
6589
payment_hash : htlc. payment_hash ,
6579
6590
payment_secret,
6591
+ payment_metadata,
6580
6592
pending_amt_msat : path_amt,
6581
6593
pending_fee_msat : Some ( path_fee) ,
6582
6594
total_msat : path_amt,
@@ -6818,7 +6830,7 @@ mod tests {
6818
6830
// Use the utility function send_payment_along_path to send the payment with MPP data which
6819
6831
// indicates there are more HTLCs coming.
6820
6832
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.
6821
- nodes[ 0 ] . node . send_payment_along_path ( & route. paths [ 0 ] , & route. payment_params , & our_payment_hash, & Some ( payment_secret) , 200_000 , cur_height, payment_id, & None ) . unwrap ( ) ;
6833
+ nodes[ 0 ] . node . send_payment_along_path ( & route. paths [ 0 ] , & route. payment_params , & our_payment_hash, & Some ( payment_secret) , & None , 200_000 , cur_height, payment_id, & None ) . unwrap ( ) ;
6822
6834
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
6823
6835
let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
6824
6836
assert_eq ! ( events. len( ) , 1 ) ;
@@ -6848,7 +6860,7 @@ mod tests {
6848
6860
expect_payment_failed ! ( nodes[ 0 ] , our_payment_hash, true ) ;
6849
6861
6850
6862
// Send the second half of the original MPP payment.
6851
- nodes[ 0 ] . node . send_payment_along_path ( & route. paths [ 0 ] , & route. payment_params , & our_payment_hash, & Some ( payment_secret) , 200_000 , cur_height, payment_id, & None ) . unwrap ( ) ;
6863
+ nodes[ 0 ] . node . send_payment_along_path ( & route. paths [ 0 ] , & route. payment_params , & our_payment_hash, & Some ( payment_secret) , & None , 200_000 , cur_height, payment_id, & None ) . unwrap ( ) ;
6852
6864
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
6853
6865
let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
6854
6866
assert_eq ! ( events. len( ) , 1 ) ;
@@ -7040,7 +7052,7 @@ mod tests {
7040
7052
7041
7053
let test_preimage = PaymentPreimage ( [ 42 ; 32 ] ) ;
7042
7054
let mismatch_payment_hash = PaymentHash ( [ 43 ; 32 ] ) ;
7043
- let _ = nodes[ 0 ] . node . send_payment_internal ( & route, mismatch_payment_hash, & None , Some ( test_preimage) , None , None ) . unwrap ( ) ;
7055
+ let _ = nodes[ 0 ] . node . send_payment_internal ( & route, mismatch_payment_hash, & None , None , Some ( test_preimage) , None , None ) . unwrap ( ) ;
7044
7056
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
7045
7057
7046
7058
let updates = get_htlc_update_msgs ! ( nodes[ 0 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
@@ -7084,7 +7096,7 @@ mod tests {
7084
7096
let test_preimage = PaymentPreimage ( [ 42 ; 32 ] ) ;
7085
7097
let test_secret = PaymentSecret ( [ 43 ; 32 ] ) ;
7086
7098
let payment_hash = PaymentHash ( Sha256 :: hash ( & test_preimage. 0 ) . into_inner ( ) ) ;
7087
- let _ = nodes[ 0 ] . node . send_payment_internal ( & route, payment_hash, & Some ( test_secret) , Some ( test_preimage) , None , None ) . unwrap ( ) ;
7099
+ let _ = nodes[ 0 ] . node . send_payment_internal ( & route, payment_hash, & Some ( test_secret) , None , Some ( test_preimage) , None , None ) . unwrap ( ) ;
7088
7100
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
7089
7101
7090
7102
let updates = get_htlc_update_msgs ! ( nodes[ 0 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
0 commit comments