Skip to content

Commit 73f601f

Browse files
committed
Add PaymentId to PaymentPathFailed event
The PaymentId is needed when retrying payments. Include it in the PaymentPathFailed event so it can be used in that manner.
1 parent 3410f18 commit 73f601f

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3120,6 +3120,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31203120
} else { None };
31213121
self.pending_events.lock().unwrap().push(
31223122
events::Event::PaymentPathFailed {
3123+
payment_id: Some(payment_id),
31233124
payment_hash,
31243125
rejected_by_dest: false,
31253126
network_update: None,
@@ -3200,6 +3201,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
32003201
// next-hop is needlessly blaming us!
32013202
self.pending_events.lock().unwrap().push(
32023203
events::Event::PaymentPathFailed {
3204+
payment_id: Some(payment_id),
32033205
payment_hash: payment_hash.clone(),
32043206
rejected_by_dest: !payment_retryable,
32053207
network_update,
@@ -3229,6 +3231,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
32293231
// channel here as we apparently can't relay through them anyway.
32303232
self.pending_events.lock().unwrap().push(
32313233
events::Event::PaymentPathFailed {
3234+
payment_id: Some(payment_id),
32323235
payment_hash: payment_hash.clone(),
32333236
rejected_by_dest: path.len() == 1,
32343237
network_update: None,

lightning/src/ln/functional_tests.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5844,7 +5844,7 @@ fn test_fail_holding_cell_htlc_upon_free() {
58445844
let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], max_can_send);
58455845

58465846
// Send a payment which passes reserve checks but gets stuck in the holding cell.
5847-
nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret)).unwrap();
5847+
let our_payment_id = nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret)).unwrap();
58485848
chan_stat = get_channel_value_stat!(nodes[0], chan.2);
58495849
assert_eq!(chan_stat.holding_cell_outbound_amount_msat, max_can_send);
58505850

@@ -5869,7 +5869,8 @@ fn test_fail_holding_cell_htlc_upon_free() {
58695869
let events = nodes[0].node.get_and_clear_pending_events();
58705870
assert_eq!(events.len(), 1);
58715871
match &events[0] {
5872-
&Event::PaymentPathFailed { ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed, path: _, ref short_channel_id, retry: _, ref error_code, ref error_data } => {
5872+
&Event::PaymentPathFailed { ref payment_id, ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed, ref short_channel_id, ref error_code, ref error_data, .. } => {
5873+
assert_eq!(our_payment_id, *payment_id.as_ref().unwrap());
58735874
assert_eq!(our_payment_hash.clone(), *payment_hash);
58745875
assert_eq!(*rejected_by_dest, false);
58755876
assert_eq!(*all_paths_failed, true);
@@ -5927,7 +5928,7 @@ fn test_free_and_fail_holding_cell_htlcs() {
59275928
nodes[0].node.send_payment(&route_1, payment_hash_1, &Some(payment_secret_1)).unwrap();
59285929
chan_stat = get_channel_value_stat!(nodes[0], chan.2);
59295930
assert_eq!(chan_stat.holding_cell_outbound_amount_msat, amt_1);
5930-
nodes[0].node.send_payment(&route_2, payment_hash_2, &Some(payment_secret_2)).unwrap();
5931+
let payment_id_2 = nodes[0].node.send_payment(&route_2, payment_hash_2, &Some(payment_secret_2)).unwrap();
59315932
chan_stat = get_channel_value_stat!(nodes[0], chan.2);
59325933
assert_eq!(chan_stat.holding_cell_outbound_amount_msat, amt_1 + amt_2);
59335934

@@ -5953,7 +5954,8 @@ fn test_free_and_fail_holding_cell_htlcs() {
59535954
let events = nodes[0].node.get_and_clear_pending_events();
59545955
assert_eq!(events.len(), 1);
59555956
match &events[0] {
5956-
&Event::PaymentPathFailed { ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed, path: _, ref short_channel_id, retry: _, ref error_code, ref error_data } => {
5957+
&Event::PaymentPathFailed { ref payment_id, ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed, ref short_channel_id, ref error_code, ref error_data, .. } => {
5958+
assert_eq!(payment_id_2, *payment_id.as_ref().unwrap());
59575959
assert_eq!(payment_hash_2.clone(), *payment_hash);
59585960
assert_eq!(*rejected_by_dest, false);
59595961
assert_eq!(*all_paths_failed, true);

lightning/src/ln/onion_route_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ fn run_onion_failure_test_with_fail_intercept<F1,F2,F3>(_name: &str, test_case:
162162

163163
let events = nodes[0].node.get_and_clear_pending_events();
164164
assert_eq!(events.len(), 1);
165-
if let &Event::PaymentPathFailed { payment_hash: _, ref rejected_by_dest, ref network_update, ref all_paths_failed, path: _, ref short_channel_id, retry: _, ref error_code, error_data: _ } = &events[0] {
165+
if let &Event::PaymentPathFailed { ref rejected_by_dest, ref network_update, ref all_paths_failed, ref short_channel_id, ref error_code, .. } = &events[0] {
166166
assert_eq!(*rejected_by_dest, !expected_retryable);
167167
assert_eq!(*all_paths_failed, true);
168168
assert_eq!(*error_code, expected_error_code);

lightning/src/routing/network_graph.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,6 +1806,7 @@ mod tests {
18061806
assert!(network_graph.read_only().channels().get(&short_channel_id).unwrap().one_to_two.is_none());
18071807

18081808
net_graph_msg_handler.handle_event(&Event::PaymentPathFailed {
1809+
payment_id: None,
18091810
payment_hash: PaymentHash([0; 32]),
18101811
rejected_by_dest: false,
18111812
all_paths_failed: true,
@@ -1832,6 +1833,7 @@ mod tests {
18321833
};
18331834

18341835
net_graph_msg_handler.handle_event(&Event::PaymentPathFailed {
1836+
payment_id: None,
18351837
payment_hash: PaymentHash([0; 32]),
18361838
rejected_by_dest: false,
18371839
all_paths_failed: true,
@@ -1857,6 +1859,7 @@ mod tests {
18571859
// Permanent closing deletes a channel
18581860
{
18591861
net_graph_msg_handler.handle_event(&Event::PaymentPathFailed {
1862+
payment_id: None,
18601863
payment_hash: PaymentHash([0; 32]),
18611864
rejected_by_dest: false,
18621865
all_paths_failed: true,

lightning/src/util/events.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ pub enum Event {
197197
/// Indicates an outbound payment we made failed. Probably some intermediary node dropped
198198
/// something. You may wish to retry with a different route.
199199
PaymentPathFailed {
200+
/// The id returned by [`ChannelManager::send_payment`] and used with
201+
/// [`ChannelManager::retry_payment`].
202+
///
203+
/// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
204+
/// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment
205+
payment_id: Option<PaymentId>,
200206
/// The hash which was given to ChannelManager::send_payment.
201207
payment_hash: PaymentHash,
202208
/// Indicates the payment was rejected for some reason by the recipient. This implies that
@@ -338,7 +344,7 @@ impl Writeable for Event {
338344
});
339345
},
340346
&Event::PaymentPathFailed {
341-
ref payment_hash, ref rejected_by_dest, ref network_update,
347+
ref payment_id, ref payment_hash, ref rejected_by_dest, ref network_update,
342348
ref all_paths_failed, ref path, ref short_channel_id, ref retry,
343349
#[cfg(test)]
344350
ref error_code,
@@ -358,6 +364,7 @@ impl Writeable for Event {
358364
(5, path, vec_type),
359365
(7, short_channel_id, option),
360366
(9, retry, option),
367+
(11, payment_id, option),
361368
});
362369
},
363370
&Event::PendingHTLCsForwardable { time_forwardable: _ } => {
@@ -473,6 +480,7 @@ impl MaybeReadable for Event {
473480
let mut path: Option<Vec<RouteHop>> = Some(vec![]);
474481
let mut short_channel_id = None;
475482
let mut retry = None;
483+
let mut payment_id = None;
476484
read_tlv_fields!(reader, {
477485
(0, payment_hash, required),
478486
(1, network_update, ignorable),
@@ -481,8 +489,10 @@ impl MaybeReadable for Event {
481489
(5, path, vec_type),
482490
(7, short_channel_id, option),
483491
(9, retry, option),
492+
(11, payment_id, option),
484493
});
485494
Ok(Some(Event::PaymentPathFailed {
495+
payment_id,
486496
payment_hash,
487497
rejected_by_dest,
488498
network_update,

0 commit comments

Comments
 (0)