Skip to content

Commit af94db8

Browse files
committed
Pass the failing/succeeding Path to PendingOutboundPayment meths
This will make the next commit much simpler
1 parent 517a154 commit af94db8

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

lightning/src/ln/channelmanager.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,8 @@ impl PendingOutboundPayment {
474474
*self = PendingOutboundPayment::Fulfilled { session_privs };
475475
}
476476

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 {
479479
let remove_res = match self {
480480
PendingOutboundPayment::Legacy { session_privs } |
481481
PendingOutboundPayment::Retryable { session_privs, .. } |
@@ -485,13 +485,15 @@ impl PendingOutboundPayment {
485485
};
486486
if remove_res {
487487
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;
489491
}
490492
}
491493
remove_res
492494
}
493495

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 {
495497
let insert_res = match self {
496498
PendingOutboundPayment::Legacy { session_privs } |
497499
PendingOutboundPayment::Retryable { session_privs, .. } => {
@@ -501,7 +503,8 @@ impl PendingOutboundPayment {
501503
};
502504
if insert_res {
503505
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;
505508
}
506509
}
507510
insert_res
@@ -2086,7 +2089,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
20862089
starting_block_height: self.best_block.read().unwrap().height(),
20872090
total_msat: total_value,
20882091
});
2089-
assert!(payment.insert(session_priv_bytes, path.last().unwrap().fee_msat));
2092+
assert!(payment.insert(session_priv_bytes, path));
20902093

20912094
send_res
20922095
} {
@@ -3107,11 +3110,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31073110
session_priv_bytes.copy_from_slice(&session_priv[..]);
31083111
let mut outbounds = self.pending_outbound_payments.lock().unwrap();
31093112
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() {
31143114
let retry = if let Some(payee_data) = payee {
3115+
let path_last_hop = path.last().expect("Outbound payments must have had a valid path");
31153116
Some(RouteParameters {
31163117
payee: payee_data,
31173118
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
31643165
session_priv_bytes.copy_from_slice(&session_priv[..]);
31653166
let mut outbounds = self.pending_outbound_payments.lock().unwrap();
31663167
let mut all_paths_failed = false;
3167-
let path_last_hop = path.last().expect("Outbound payments must have had a valid path");
31683168
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)) {
31703170
log_trace!(self.logger, "Received duplicative fail for HTLC with payment_hash {}", log_bytes!(payment_hash.0));
31713171
return;
31723172
}
@@ -3183,6 +3183,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31833183
}
31843184
mem::drop(channel_state_lock);
31853185
let retry = if let Some(payee_data) = payee {
3186+
let path_last_hop = path.last().expect("Outbound payments must have had a valid path");
31863187
Some(RouteParameters {
31873188
payee: payee_data.clone(),
31883189
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
34673468
// restart.
34683469
// TODO: We should have a second monitor event that informs us of payments
34693470
// 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));
34713472
if payment.get().remaining_parts() == 0 {
34723473
payment.remove();
34733474
}
@@ -5951,7 +5952,7 @@ impl<'a, Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
59515952
session_priv_bytes[..].copy_from_slice(&session_priv[..]);
59525953
match pending_outbound_payments.as_mut().unwrap().entry(payment_id) {
59535954
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);
59555956
log_info!(args.logger, "{} a pending payment path for {} msat for session priv {} on an existing pending payment with payment hash {}",
59565957
if newly_added { "Added" } else { "Had" }, path_amt, log_bytes!(session_priv_bytes), log_bytes!(htlc.payment_hash.0));
59575958
},

0 commit comments

Comments
 (0)