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