@@ -211,6 +211,7 @@ pub(crate) enum HTLCSource {
211
211
first_hop_htlc_msat : u64 ,
212
212
payment_id : PaymentId ,
213
213
payment_secret : Option < PaymentSecret > ,
214
+ payment_metadata : Option < Vec < u8 > > ,
214
215
payment_params : Option < PaymentParameters > ,
215
216
} ,
216
217
}
@@ -222,12 +223,13 @@ impl core::hash::Hash for HTLCSource {
222
223
0u8 . hash ( hasher) ;
223
224
prev_hop_data. hash ( hasher) ;
224
225
} ,
225
- HTLCSource :: OutboundRoute { path, session_priv, payment_id, payment_secret, first_hop_htlc_msat, payment_params } => {
226
+ HTLCSource :: OutboundRoute { path, session_priv, payment_id, payment_secret, payment_metadata , first_hop_htlc_msat, payment_params } => {
226
227
1u8 . hash ( hasher) ;
227
228
path. hash ( hasher) ;
228
229
session_priv[ ..] . hash ( hasher) ;
229
230
payment_id. hash ( hasher) ;
230
231
payment_secret. hash ( hasher) ;
232
+ payment_metadata. hash ( hasher) ;
231
233
first_hop_htlc_msat. hash ( hasher) ;
232
234
payment_params. hash ( hasher) ;
233
235
} ,
@@ -244,6 +246,7 @@ impl HTLCSource {
244
246
first_hop_htlc_msat : 0 ,
245
247
payment_id : PaymentId ( [ 2 ; 32 ] ) ,
246
248
payment_secret : None ,
249
+ payment_metadata : None ,
247
250
payment_params : None ,
248
251
}
249
252
}
@@ -469,6 +472,7 @@ pub(crate) enum PendingOutboundPayment {
469
472
session_privs : HashSet < [ u8 ; 32 ] > ,
470
473
payment_hash : PaymentHash ,
471
474
payment_secret : Option < PaymentSecret > ,
475
+ payment_metadata : Option < Vec < u8 > > ,
472
476
pending_amt_msat : u64 ,
473
477
/// Used to track the fee paid. Only present if the payment was serialized on 0.0.103+.
474
478
pending_fee_msat : Option < u64 > ,
@@ -2329,15 +2333,15 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2329
2333
}
2330
2334
2331
2335
// Only public for testing, this should otherwise never be called direcly
2332
- 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 > {
2336
+ 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 > {
2333
2337
log_trace ! ( self . logger, "Attempting to send payment for path with next hop {}" , path. first( ) . unwrap( ) . short_channel_id) ;
2334
2338
let prng_seed = self . keys_manager . get_secure_random_bytes ( ) ;
2335
2339
let session_priv_bytes = self . keys_manager . get_secure_random_bytes ( ) ;
2336
2340
let session_priv = SecretKey :: from_slice ( & session_priv_bytes[ ..] ) . expect ( "RNG is busted" ) ;
2337
2341
2338
2342
let onion_keys = onion_utils:: construct_onion_keys ( & self . secp_ctx , & path, & session_priv)
2339
2343
. map_err ( |_| APIError :: RouteError { err : "Pubkey along hop was maliciously selected" } ) ?;
2340
- let ( onion_payloads, htlc_msat, htlc_cltv) = onion_utils:: build_onion_payloads ( path, total_value, payment_secret, cur_height, keysend_preimage) ?;
2344
+ let ( onion_payloads, htlc_msat, htlc_cltv) = onion_utils:: build_onion_payloads ( path, total_value, payment_secret, payment_metadata . clone ( ) , cur_height, keysend_preimage) ?;
2341
2345
if onion_utils:: route_size_insane ( & onion_payloads) {
2342
2346
return Err ( APIError :: RouteError { err : "Route size too large considering onion data" } ) ;
2343
2347
}
@@ -2371,6 +2375,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2371
2375
pending_fee_msat: Some ( 0 ) ,
2372
2376
payment_hash: * payment_hash,
2373
2377
payment_secret: * payment_secret,
2378
+ payment_metadata: payment_metadata. clone( ) ,
2374
2379
starting_block_height: self . best_block. read( ) . unwrap( ) . height( ) ,
2375
2380
total_msat: total_value,
2376
2381
} ) ;
@@ -2394,6 +2399,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2394
2399
first_hop_htlc_msat: htlc_msat,
2395
2400
payment_id,
2396
2401
payment_secret: payment_secret. clone( ) ,
2402
+ payment_metadata: payment_metadata. clone( ) ,
2397
2403
payment_params: payment_params. clone( ) ,
2398
2404
} , onion_packet, & self . logger) ,
2399
2405
channel_state, chan)
@@ -2478,10 +2484,10 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2478
2484
/// bit set (either as required or as available). If multiple paths are present in the Route,
2479
2485
/// we assume the invoice had the basic_mpp feature set.
2480
2486
pub fn send_payment ( & self , route : & Route , payment_hash : PaymentHash , payment_secret : & Option < PaymentSecret > ) -> Result < PaymentId , PaymentSendFailure > {
2481
- self . send_payment_internal ( route, payment_hash, payment_secret, None , None , None )
2487
+ self . send_payment_internal ( route, payment_hash, payment_secret, None , None , None , None )
2482
2488
}
2483
2489
2484
- 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 > {
2490
+ 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 > {
2485
2491
if route. paths . len ( ) < 1 {
2486
2492
return Err ( PaymentSendFailure :: ParameterError ( APIError :: RouteError { err : "There must be at least one path to send over" } ) ) ;
2487
2493
}
@@ -2523,7 +2529,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2523
2529
let cur_height = self . best_block . read ( ) . unwrap ( ) . height ( ) + 1 ;
2524
2530
let mut results = Vec :: new ( ) ;
2525
2531
for path in route. paths . iter ( ) {
2526
- results. push ( self . send_payment_along_path ( & path, & route. payment_params , & payment_hash, payment_secret, total_value, cur_height, payment_id, & keysend_preimage) ) ;
2532
+ 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) ) ;
2527
2533
}
2528
2534
let mut has_ok = false ;
2529
2535
let mut has_err = false ;
@@ -2586,20 +2592,20 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2586
2592
}
2587
2593
}
2588
2594
2589
- let ( total_msat, payment_hash, payment_secret) = {
2595
+ let ( total_msat, payment_hash, payment_secret, payment_metadata ) = {
2590
2596
let outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
2591
2597
if let Some ( payment) = outbounds. get ( & payment_id) {
2592
2598
match payment {
2593
2599
PendingOutboundPayment :: Retryable {
2594
- total_msat, payment_hash, payment_secret, pending_amt_msat, ..
2600
+ total_msat, payment_hash, payment_secret, pending_amt_msat, payment_metadata , ..
2595
2601
} => {
2596
2602
let retry_amt_msat: u64 = route. paths . iter ( ) . map ( |path| path. last ( ) . unwrap ( ) . fee_msat ) . sum ( ) ;
2597
2603
if retry_amt_msat + * pending_amt_msat > * total_msat * ( 100 + RETRY_OVERFLOW_PERCENTAGE ) / 100 {
2598
2604
return Err ( PaymentSendFailure :: ParameterError ( APIError :: APIMisuseError {
2599
2605
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 ( )
2600
2606
} ) )
2601
2607
}
2602
- ( * total_msat, * payment_hash, * payment_secret)
2608
+ ( * total_msat, * payment_hash, * payment_secret, payment_metadata . clone ( ) )
2603
2609
} ,
2604
2610
PendingOutboundPayment :: Legacy { .. } => {
2605
2611
return Err ( PaymentSendFailure :: ParameterError ( APIError :: APIMisuseError {
@@ -2623,7 +2629,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2623
2629
} ) )
2624
2630
}
2625
2631
} ;
2626
- return self . send_payment_internal ( route, payment_hash, & payment_secret, None , Some ( payment_id) , Some ( total_msat) ) . map ( |_| ( ) )
2632
+ return self . send_payment_internal ( route, payment_hash, & payment_secret, payment_metadata , None , Some ( payment_id) , Some ( total_msat) ) . map ( |_| ( ) )
2627
2633
}
2628
2634
2629
2635
/// Signals that no further retries for the given payment will occur.
@@ -2677,7 +2683,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2677
2683
None => PaymentPreimage ( self . keys_manager . get_secure_random_bytes ( ) ) ,
2678
2684
} ;
2679
2685
let payment_hash = PaymentHash ( Sha256 :: hash ( & preimage. 0 ) . into_inner ( ) ) ;
2680
- match self . send_payment_internal ( route, payment_hash, & None , Some ( preimage) , None , None ) {
2686
+ match self . send_payment_internal ( route, payment_hash, & None , None , Some ( preimage) , None , None ) {
2681
2687
Ok ( payment_id) => Ok ( ( payment_hash, payment_id) ) ,
2682
2688
Err ( e) => Err ( e)
2683
2689
}
@@ -6149,13 +6155,15 @@ impl Readable for HTLCSource {
6149
6155
let mut payment_id = None ;
6150
6156
let mut payment_secret = None ;
6151
6157
let mut payment_params = None ;
6158
+ let mut payment_metadata = None ;
6152
6159
read_tlv_fields ! ( reader, {
6153
6160
( 0 , session_priv, required) ,
6154
6161
( 1 , payment_id, option) ,
6155
6162
( 2 , first_hop_htlc_msat, required) ,
6156
6163
( 3 , payment_secret, option) ,
6157
6164
( 4 , path, vec_type) ,
6158
6165
( 5 , payment_params, option) ,
6166
+ ( 7 , payment_metadata, option) ,
6159
6167
} ) ;
6160
6168
if payment_id. is_none ( ) {
6161
6169
// For backwards compat, if there was no payment_id written, use the session_priv bytes
@@ -6169,6 +6177,7 @@ impl Readable for HTLCSource {
6169
6177
payment_id : payment_id. unwrap ( ) ,
6170
6178
payment_secret,
6171
6179
payment_params,
6180
+ payment_metadata,
6172
6181
} )
6173
6182
}
6174
6183
1 => Ok ( HTLCSource :: PreviousHopData ( Readable :: read ( reader) ?) ) ,
@@ -6180,7 +6189,7 @@ impl Readable for HTLCSource {
6180
6189
impl Writeable for HTLCSource {
6181
6190
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: io:: Error > {
6182
6191
match self {
6183
- HTLCSource :: OutboundRoute { ref session_priv, ref first_hop_htlc_msat, ref path, payment_id, payment_secret, payment_params } => {
6192
+ HTLCSource :: OutboundRoute { ref session_priv, ref first_hop_htlc_msat, ref path, payment_id, payment_secret, ref payment_metadata , payment_params } => {
6184
6193
0u8 . write ( writer) ?;
6185
6194
let payment_id_opt = Some ( payment_id) ;
6186
6195
write_tlv_fields ! ( writer, {
@@ -6190,6 +6199,7 @@ impl Writeable for HTLCSource {
6190
6199
( 3 , payment_secret, option) ,
6191
6200
( 4 , path, vec_type) ,
6192
6201
( 5 , payment_params, option) ,
6202
+ ( 7 , payment_metadata, option) ,
6193
6203
} ) ;
6194
6204
}
6195
6205
HTLCSource :: PreviousHopData ( ref field) => {
@@ -6244,6 +6254,7 @@ impl_writeable_tlv_based_enum_upgradable!(PendingOutboundPayment,
6244
6254
( 0 , session_privs, required) ,
6245
6255
( 1 , pending_fee_msat, option) ,
6246
6256
( 2 , payment_hash, required) ,
6257
+ ( 3 , payment_metadata, option) ,
6247
6258
( 4 , payment_secret, option) ,
6248
6259
( 6 , total_msat, required) ,
6249
6260
( 8 , pending_amt_msat, required) ,
@@ -6706,7 +6717,7 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
6706
6717
for ( _, monitor) in args. channel_monitors {
6707
6718
if by_id. get ( & monitor. get_funding_txo ( ) . 0 . to_channel_id ( ) ) . is_none ( ) {
6708
6719
for ( htlc_source, htlc) in monitor. get_pending_outbound_htlcs ( ) {
6709
- if let HTLCSource :: OutboundRoute { payment_id, session_priv, path, payment_secret, .. } = htlc_source {
6720
+ if let HTLCSource :: OutboundRoute { payment_id, session_priv, path, payment_secret, payment_metadata , .. } = htlc_source {
6710
6721
if path. is_empty ( ) {
6711
6722
log_error ! ( args. logger, "Got an empty path for a pending payment" ) ;
6712
6723
return Err ( DecodeError :: InvalidValue ) ;
@@ -6726,6 +6737,7 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
6726
6737
session_privs : [ session_priv_bytes] . iter ( ) . map ( |a| * a) . collect ( ) ,
6727
6738
payment_hash : htlc. payment_hash ,
6728
6739
payment_secret,
6740
+ payment_metadata,
6729
6741
pending_amt_msat : path_amt,
6730
6742
pending_fee_msat : Some ( path_fee) ,
6731
6743
total_msat : path_amt,
@@ -7001,7 +7013,7 @@ mod tests {
7001
7013
// Use the utility function send_payment_along_path to send the payment with MPP data which
7002
7014
// indicates there are more HTLCs coming.
7003
7015
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.
7004
- 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 ( ) ;
7016
+ 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 ( ) ;
7005
7017
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
7006
7018
let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
7007
7019
assert_eq ! ( events. len( ) , 1 ) ;
@@ -7031,7 +7043,7 @@ mod tests {
7031
7043
expect_payment_failed ! ( nodes[ 0 ] , our_payment_hash, true ) ;
7032
7044
7033
7045
// Send the second half of the original MPP payment.
7034
- 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 ( ) ;
7046
+ 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 ( ) ;
7035
7047
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
7036
7048
let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
7037
7049
assert_eq ! ( events. len( ) , 1 ) ;
@@ -7225,7 +7237,7 @@ mod tests {
7225
7237
7226
7238
let test_preimage = PaymentPreimage ( [ 42 ; 32 ] ) ;
7227
7239
let mismatch_payment_hash = PaymentHash ( [ 43 ; 32 ] ) ;
7228
- let _ = nodes[ 0 ] . node . send_payment_internal ( & route, mismatch_payment_hash, & None , Some ( test_preimage) , None , None ) . unwrap ( ) ;
7240
+ let _ = nodes[ 0 ] . node . send_payment_internal ( & route, mismatch_payment_hash, & None , None , Some ( test_preimage) , None , None ) . unwrap ( ) ;
7229
7241
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
7230
7242
7231
7243
let updates = get_htlc_update_msgs ! ( nodes[ 0 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
@@ -7270,7 +7282,7 @@ mod tests {
7270
7282
let test_preimage = PaymentPreimage ( [ 42 ; 32 ] ) ;
7271
7283
let test_secret = PaymentSecret ( [ 43 ; 32 ] ) ;
7272
7284
let payment_hash = PaymentHash ( Sha256 :: hash ( & test_preimage. 0 ) . into_inner ( ) ) ;
7273
- let _ = nodes[ 0 ] . node . send_payment_internal ( & route, payment_hash, & Some ( test_secret) , Some ( test_preimage) , None , None ) . unwrap ( ) ;
7285
+ let _ = nodes[ 0 ] . node . send_payment_internal ( & route, payment_hash, & Some ( test_secret) , None , Some ( test_preimage) , None , None ) . unwrap ( ) ;
7274
7286
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
7275
7287
7276
7288
let updates = get_htlc_update_msgs ! ( nodes[ 0 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
0 commit comments