@@ -474,8 +474,8 @@ impl PendingOutboundPayment {
474
474
* self = PendingOutboundPayment :: Fulfilled { session_privs } ;
475
475
}
476
476
477
- /// panics if part_amt_msat is None and !self.is_fulfilled
478
- fn remove ( & mut self , session_priv : & [ u8 ; 32 ] , part_amt_msat : Option < u64 > ) -> bool {
477
+ /// panics if path is None and !self.is_fulfilled
478
+ fn remove ( & mut self , session_priv : & [ u8 ; 32 ] , path : Option < & Vec < RouteHop > > ) -> bool {
479
479
let remove_res = match self {
480
480
PendingOutboundPayment :: Legacy { session_privs } |
481
481
PendingOutboundPayment :: Retryable { session_privs, .. } |
@@ -485,13 +485,15 @@ impl PendingOutboundPayment {
485
485
} ;
486
486
if remove_res {
487
487
if let PendingOutboundPayment :: Retryable { ref mut pending_amt_msat, .. } = self {
488
- * pending_amt_msat -= part_amt_msat. expect ( "We must only not provide an amount if the payment was already fulfilled" ) ;
488
+ let path = path. expect ( "Fulfilling a payment should always come with a path" ) ;
489
+ let path_last_hop = path. last ( ) . expect ( "Outbound payments must have had a valid path" ) ;
490
+ * pending_amt_msat -= path_last_hop. fee_msat ;
489
491
}
490
492
}
491
493
remove_res
492
494
}
493
495
494
- fn insert ( & mut self , session_priv : [ u8 ; 32 ] , part_amt_msat : u64 ) -> bool {
496
+ fn insert ( & mut self , session_priv : [ u8 ; 32 ] , path : & Vec < RouteHop > ) -> bool {
495
497
let insert_res = match self {
496
498
PendingOutboundPayment :: Legacy { session_privs } |
497
499
PendingOutboundPayment :: Retryable { session_privs, .. } => {
@@ -501,7 +503,8 @@ impl PendingOutboundPayment {
501
503
} ;
502
504
if insert_res {
503
505
if let PendingOutboundPayment :: Retryable { ref mut pending_amt_msat, .. } = self {
504
- * pending_amt_msat += part_amt_msat;
506
+ let path_last_hop = path. last ( ) . expect ( "Outbound payments must have had a valid path" ) ;
507
+ * pending_amt_msat += path_last_hop. fee_msat ;
505
508
}
506
509
}
507
510
insert_res
@@ -2086,7 +2089,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
2086
2089
starting_block_height : self . best_block . read ( ) . unwrap ( ) . height ( ) ,
2087
2090
total_msat : total_value,
2088
2091
} ) ;
2089
- assert ! ( payment. insert( session_priv_bytes, path. last ( ) . unwrap ( ) . fee_msat ) ) ;
2092
+ assert ! ( payment. insert( session_priv_bytes, path) ) ;
2090
2093
2091
2094
send_res
2092
2095
} {
@@ -3107,11 +3110,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3107
3110
session_priv_bytes. copy_from_slice ( & session_priv[ ..] ) ;
3108
3111
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
3109
3112
if let hash_map:: Entry :: Occupied ( mut payment) = outbounds. entry ( payment_id) {
3110
- let path_last_hop = path. last ( ) . expect ( "Outbound payments must have had a valid path" ) ;
3111
- if payment. get_mut ( ) . remove ( & session_priv_bytes, Some ( path_last_hop. fee_msat ) ) &&
3112
- !payment. get ( ) . is_fulfilled ( )
3113
- {
3113
+ if payment. get_mut ( ) . remove ( & session_priv_bytes, Some ( & path) ) && !payment. get ( ) . is_fulfilled ( ) {
3114
3114
let retry = if let Some ( payee_data) = payee {
3115
+ let path_last_hop = path. last ( ) . expect ( "Outbound payments must have had a valid path" ) ;
3115
3116
Some ( RouteParameters {
3116
3117
payee : payee_data,
3117
3118
final_value_msat : path_last_hop. fee_msat ,
@@ -3164,9 +3165,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3164
3165
session_priv_bytes. copy_from_slice ( & session_priv[ ..] ) ;
3165
3166
let mut outbounds = self . pending_outbound_payments . lock ( ) . unwrap ( ) ;
3166
3167
let mut all_paths_failed = false ;
3167
- let path_last_hop = path. last ( ) . expect ( "Outbound payments must have had a valid path" ) ;
3168
3168
if let hash_map:: Entry :: Occupied ( mut payment) = outbounds. entry ( payment_id) {
3169
- if !payment. get_mut ( ) . remove ( & session_priv_bytes, Some ( path_last_hop . fee_msat ) ) {
3169
+ if !payment. get_mut ( ) . remove ( & session_priv_bytes, Some ( & path ) ) {
3170
3170
log_trace ! ( self . logger, "Received duplicative fail for HTLC with payment_hash {}" , log_bytes!( payment_hash. 0 ) ) ;
3171
3171
return ;
3172
3172
}
@@ -3183,6 +3183,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3183
3183
}
3184
3184
mem:: drop ( channel_state_lock) ;
3185
3185
let retry = if let Some ( payee_data) = payee {
3186
+ let path_last_hop = path. last ( ) . expect ( "Outbound payments must have had a valid path" ) ;
3186
3187
Some ( RouteParameters {
3187
3188
payee : payee_data. clone ( ) ,
3188
3189
final_value_msat : path_last_hop. fee_msat ,
@@ -3467,7 +3468,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3467
3468
// restart.
3468
3469
// TODO: We should have a second monitor event that informs us of payments
3469
3470
// irrevocably fulfilled.
3470
- payment. get_mut ( ) . remove ( & session_priv_bytes, Some ( path. last ( ) . unwrap ( ) . fee_msat ) ) ;
3471
+ payment. get_mut ( ) . remove ( & session_priv_bytes, Some ( & path) ) ;
3471
3472
if payment. get ( ) . remaining_parts ( ) == 0 {
3472
3473
payment. remove ( ) ;
3473
3474
}
@@ -5951,7 +5952,7 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
5951
5952
session_priv_bytes[ ..] . copy_from_slice ( & session_priv[ ..] ) ;
5952
5953
match pending_outbound_payments. as_mut ( ) . unwrap ( ) . entry ( payment_id) {
5953
5954
hash_map:: Entry :: Occupied ( mut entry) => {
5954
- let newly_added = entry. get_mut ( ) . insert ( session_priv_bytes, path_amt ) ;
5955
+ let newly_added = entry. get_mut ( ) . insert ( session_priv_bytes, & path ) ;
5955
5956
log_info ! ( args. logger, "{} a pending payment path for {} msat for session priv {} on an existing pending payment with payment hash {}" ,
5956
5957
if newly_added { "Added" } else { "Had" } , path_amt, log_bytes!( session_priv_bytes) , log_bytes!( htlc. payment_hash. 0 ) ) ;
5957
5958
} ,
0 commit comments