@@ -45,7 +45,7 @@ use chain::transaction::{OutPoint, TransactionData};
45
45
use ln:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
46
46
use ln:: channel:: { Channel , ChannelError , ChannelUpdateStatus , UpdateFulfillCommitFetch } ;
47
47
use ln:: features:: { InitFeatures , NodeFeatures } ;
48
- use routing:: router:: { Route , RouteHop } ;
48
+ use routing:: router:: { Payee , PaymentPathRetry , Route , RouteHop } ;
49
49
use ln:: msgs;
50
50
use ln:: msgs:: NetAddress ;
51
51
use ln:: onion_utils;
@@ -201,6 +201,7 @@ pub(crate) enum HTLCSource {
201
201
first_hop_htlc_msat : u64 ,
202
202
payment_id : PaymentId ,
203
203
payment_secret : Option < PaymentSecret > ,
204
+ payee : Option < Payee > ,
204
205
} ,
205
206
}
206
207
#[ allow( clippy:: derive_hash_xor_eq) ] // Our Hash is faithful to the data, we just don't have SecretKey::hash
@@ -211,13 +212,14 @@ impl core::hash::Hash for HTLCSource {
211
212
0u8 . hash ( hasher) ;
212
213
prev_hop_data. hash ( hasher) ;
213
214
} ,
214
- HTLCSource :: OutboundRoute { path, session_priv, payment_id, payment_secret, first_hop_htlc_msat } => {
215
+ HTLCSource :: OutboundRoute { path, session_priv, payment_id, payment_secret, first_hop_htlc_msat, payee } => {
215
216
1u8 . hash ( hasher) ;
216
217
path. hash ( hasher) ;
217
218
session_priv[ ..] . hash ( hasher) ;
218
219
payment_id. hash ( hasher) ;
219
220
payment_secret. hash ( hasher) ;
220
221
first_hop_htlc_msat. hash ( hasher) ;
222
+ payee. hash ( hasher) ;
221
223
} ,
222
224
}
223
225
}
@@ -231,6 +233,7 @@ impl HTLCSource {
231
233
first_hop_htlc_msat : 0 ,
232
234
payment_id : PaymentId ( [ 2 ; 32 ] ) ,
233
235
payment_secret : None ,
236
+ payee : None ,
234
237
}
235
238
}
236
239
}
@@ -2021,7 +2024,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2021
2024
}
2022
2025
2023
2026
// Only public for testing, this should otherwise never be called direcly
2024
- pub ( crate ) fn send_payment_along_path ( & self , path : & Vec < RouteHop > , payment_hash : & PaymentHash , payment_secret : & Option < PaymentSecret > , total_value : u64 , cur_height : u32 , payment_id : PaymentId , keysend_preimage : & Option < PaymentPreimage > ) -> Result < ( ) , APIError > {
2027
+ 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 > {
2025
2028
log_trace ! ( self . logger, "Attempting to send payment for path with next hop {}" , path. first( ) . unwrap( ) . short_channel_id) ;
2026
2029
let prng_seed = self . keys_manager . get_secure_random_bytes ( ) ;
2027
2030
let session_priv_bytes = self . keys_manager . get_secure_random_bytes ( ) ;
@@ -2071,6 +2074,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2071
2074
first_hop_htlc_msat: htlc_msat,
2072
2075
payment_id,
2073
2076
payment_secret: payment_secret. clone( ) ,
2077
+ payee: payee. clone( ) ,
2074
2078
} , onion_packet, & self . logger) ,
2075
2079
channel_state, chan) ;
2076
2080
@@ -2209,7 +2213,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2209
2213
let cur_height = self . best_block . read ( ) . unwrap ( ) . height ( ) + 1 ;
2210
2214
let mut results = Vec :: new ( ) ;
2211
2215
for path in route. paths . iter ( ) {
2212
- results. push ( self . send_payment_along_path ( & path, & payment_hash, payment_secret, total_value, cur_height, payment_id, & keysend_preimage) ) ;
2216
+ results. push ( self . send_payment_along_path ( & path, & route . payee , & payment_hash, payment_secret, total_value, cur_height, payment_id, & keysend_preimage) ) ;
2213
2217
}
2214
2218
let mut has_ok = false ;
2215
2219
let mut has_err = false ;
@@ -3098,14 +3102,21 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3098
3102
self . fail_htlc_backwards_internal ( channel_state,
3099
3103
htlc_src, & payment_hash, HTLCFailReason :: Reason { failure_code, data : onion_failure_data} ) ;
3100
3104
} ,
3101
- HTLCSource :: OutboundRoute { session_priv, payment_id, path, .. } => {
3105
+ HTLCSource :: OutboundRoute { session_priv, payment_id, path, payee , .. } => {
3102
3106
let mut session_priv_bytes = [ 0 ; 32 ] ;
3103
3107
session_priv_bytes. copy_from_slice ( & session_priv[ ..] ) ;
3104
3108
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
3105
3109
if let hash_map:: Entry :: Occupied ( mut payment) = outbounds. entry ( payment_id) {
3106
3110
if payment. get_mut ( ) . remove ( & session_priv_bytes, Some ( path. last ( ) . unwrap ( ) . fee_msat ) ) &&
3107
3111
!payment. get ( ) . is_fulfilled ( )
3108
3112
{
3113
+ let retry = if let Some ( payee_data) = payee {
3114
+ Some ( PaymentPathRetry {
3115
+ payee : payee_data,
3116
+ final_value_msat : path. last ( ) . expect ( "XXX" ) . fee_msat ,
3117
+ final_cltv : path. last ( ) . expect ( "XXX" ) . cltv_expiry_delta ,
3118
+ } )
3119
+ } else { None } ;
3109
3120
self . pending_events . lock ( ) . unwrap ( ) . push (
3110
3121
events:: Event :: PaymentPathFailed {
3111
3122
payment_hash,
@@ -3114,7 +3125,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3114
3125
all_paths_failed : payment. get ( ) . remaining_parts ( ) == 0 ,
3115
3126
path : path. clone ( ) ,
3116
3127
short_channel_id : None ,
3117
- retry : None ,
3128
+ retry,
3118
3129
#[ cfg( test) ]
3119
3130
error_code : None ,
3120
3131
#[ cfg( test) ]
@@ -3146,7 +3157,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3146
3157
// from block_connected which may run during initialization prior to the chain_monitor
3147
3158
// being fully configured. See the docs for `ChannelManagerReadArgs` for more.
3148
3159
match source {
3149
- HTLCSource :: OutboundRoute { ref path, session_priv, payment_id, .. } => {
3160
+ HTLCSource :: OutboundRoute { ref path, session_priv, payment_id, ref payee , .. } => {
3150
3161
let mut session_priv_bytes = [ 0 ; 32 ] ;
3151
3162
session_priv_bytes. copy_from_slice ( & session_priv[ ..] ) ;
3152
3163
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
@@ -3167,8 +3178,15 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3167
3178
log_trace ! ( self . logger, "Received duplicative fail for HTLC with payment_hash {}" , log_bytes!( payment_hash. 0 ) ) ;
3168
3179
return ;
3169
3180
}
3170
- log_trace ! ( self . logger, "Failing outbound payment HTLC with payment_hash {}" , log_bytes!( payment_hash. 0 ) ) ;
3171
3181
mem:: drop ( channel_state_lock) ;
3182
+ let retry = if let Some ( payee_data) = payee {
3183
+ Some ( PaymentPathRetry {
3184
+ payee : payee_data. clone ( ) ,
3185
+ final_value_msat : path. last ( ) . expect ( "XXX" ) . fee_msat ,
3186
+ final_cltv : path. last ( ) . expect ( "XXX" ) . cltv_expiry_delta ,
3187
+ } )
3188
+ } else { None } ;
3189
+ log_trace ! ( self . logger, "Failing outbound payment HTLC with payment_hash {}" , log_bytes!( payment_hash. 0 ) ) ;
3172
3190
match & onion_error {
3173
3191
& HTLCFailReason :: LightningError { ref err } => {
3174
3192
#[ cfg( test) ]
@@ -3186,7 +3204,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3186
3204
all_paths_failed,
3187
3205
path : path. clone ( ) ,
3188
3206
short_channel_id,
3189
- retry : None ,
3207
+ retry,
3190
3208
#[ cfg( test) ]
3191
3209
error_code : onion_error_code,
3192
3210
#[ cfg( test) ]
@@ -3215,7 +3233,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3215
3233
all_paths_failed,
3216
3234
path : path. clone ( ) ,
3217
3235
short_channel_id : Some ( path. first ( ) . unwrap ( ) . short_channel_id ) ,
3218
- retry : None ,
3236
+ retry,
3219
3237
#[ cfg( test) ]
3220
3238
error_code : Some ( * failure_code) ,
3221
3239
#[ cfg( test) ]
@@ -5378,12 +5396,14 @@ impl Readable for HTLCSource {
5378
5396
let mut path = Some ( Vec :: new ( ) ) ;
5379
5397
let mut payment_id = None ;
5380
5398
let mut payment_secret = None ;
5399
+ let mut payee = None ;
5381
5400
read_tlv_fields ! ( reader, {
5382
5401
( 0 , session_priv, required) ,
5383
5402
( 1 , payment_id, option) ,
5384
5403
( 2 , first_hop_htlc_msat, required) ,
5385
5404
( 3 , payment_secret, option) ,
5386
5405
( 4 , path, vec_type) ,
5406
+ ( 5 , payee, option) ,
5387
5407
} ) ;
5388
5408
if payment_id. is_none ( ) {
5389
5409
// For backwards compat, if there was no payment_id written, use the session_priv bytes
@@ -5396,6 +5416,7 @@ impl Readable for HTLCSource {
5396
5416
path : path. unwrap ( ) ,
5397
5417
payment_id : payment_id. unwrap ( ) ,
5398
5418
payment_secret,
5419
+ payee,
5399
5420
} )
5400
5421
}
5401
5422
1 => Ok ( HTLCSource :: PreviousHopData ( Readable :: read ( reader) ?) ) ,
@@ -5407,7 +5428,7 @@ impl Readable for HTLCSource {
5407
5428
impl Writeable for HTLCSource {
5408
5429
fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , :: io:: Error > {
5409
5430
match self {
5410
- HTLCSource :: OutboundRoute { ref session_priv, ref first_hop_htlc_msat, ref path, payment_id, payment_secret } => {
5431
+ HTLCSource :: OutboundRoute { ref session_priv, ref first_hop_htlc_msat, ref path, payment_id, payment_secret, payee } => {
5411
5432
0u8 . write ( writer) ?;
5412
5433
let payment_id_opt = Some ( payment_id) ;
5413
5434
write_tlv_fields ! ( writer, {
@@ -5416,6 +5437,7 @@ impl Writeable for HTLCSource {
5416
5437
( 2 , first_hop_htlc_msat, required) ,
5417
5438
( 3 , payment_secret, option) ,
5418
5439
( 4 , path, vec_type) ,
5440
+ ( 5 , payee, option) ,
5419
5441
} ) ;
5420
5442
}
5421
5443
HTLCSource :: PreviousHopData ( ref field) => {
@@ -6160,7 +6182,7 @@ mod tests {
6160
6182
// Use the utility function send_payment_along_path to send the payment with MPP data which
6161
6183
// indicates there are more HTLCs coming.
6162
6184
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.
6163
- nodes[ 0 ] . node . send_payment_along_path ( & route. paths [ 0 ] , & our_payment_hash, & Some ( payment_secret) , 200_000 , cur_height, payment_id, & None ) . unwrap ( ) ;
6185
+ 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 ( ) ;
6164
6186
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
6165
6187
let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
6166
6188
assert_eq ! ( events. len( ) , 1 ) ;
@@ -6190,7 +6212,7 @@ mod tests {
6190
6212
expect_payment_failed ! ( nodes[ 0 ] , our_payment_hash, true ) ;
6191
6213
6192
6214
// Send the second half of the original MPP payment.
6193
- nodes[ 0 ] . node . send_payment_along_path ( & route. paths [ 0 ] , & our_payment_hash, & Some ( payment_secret) , 200_000 , cur_height, payment_id, & None ) . unwrap ( ) ;
6215
+ 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 ( ) ;
6194
6216
check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
6195
6217
let mut events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
6196
6218
assert_eq ! ( events. len( ) , 1 ) ;
0 commit comments