Skip to content

Commit b6fc74d

Browse files
Add path field to PaymentPathFailed event
1 parent 88203a4 commit b6fc74d

File tree

7 files changed

+24
-7
lines changed

7 files changed

+24
-7
lines changed

lightning/src/ln/channelmanager.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2875,7 +2875,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
28752875
self.fail_htlc_backwards_internal(channel_state,
28762876
htlc_src, &payment_hash, HTLCFailReason::Reason { failure_code, data: onion_failure_data});
28772877
},
2878-
HTLCSource::OutboundRoute { session_priv, mpp_id, .. } => {
2878+
HTLCSource::OutboundRoute { session_priv, mpp_id, path, .. } => {
28792879
let mut session_priv_bytes = [0; 32];
28802880
session_priv_bytes.copy_from_slice(&session_priv[..]);
28812881
let mut outbounds = self.pending_outbound_payments.lock().unwrap();
@@ -2887,6 +2887,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
28872887
rejected_by_dest: false,
28882888
network_update: None,
28892889
all_paths_failed: sessions.get().len() == 0,
2890+
path: path.clone(),
28902891
#[cfg(test)]
28912892
error_code: None,
28922893
#[cfg(test)]
@@ -2956,6 +2957,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
29562957
rejected_by_dest: !payment_retryable,
29572958
network_update,
29582959
all_paths_failed,
2960+
path: path.clone(),
29592961
#[cfg(test)]
29602962
error_code: onion_error_code,
29612963
#[cfg(test)]
@@ -2982,6 +2984,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
29822984
rejected_by_dest: path.len() == 1,
29832985
network_update: None,
29842986
all_paths_failed,
2987+
path: path.clone(),
29852988
#[cfg(test)]
29862989
error_code: Some(*failure_code),
29872990
#[cfg(test)]

lightning/src/ln/functional_test_utils.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1399,10 +1399,13 @@ pub fn fail_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expe
13991399
let events = origin_node.node.get_and_clear_pending_events();
14001400
assert_eq!(events.len(), 1);
14011401
match events[0] {
1402-
Event::PaymentPathFailed { payment_hash, rejected_by_dest, all_paths_failed, .. } => {
1402+
Event::PaymentPathFailed { payment_hash, rejected_by_dest, all_paths_failed, ref path, .. } => {
14031403
assert_eq!(payment_hash, our_payment_hash);
14041404
assert!(rejected_by_dest);
14051405
assert_eq!(all_paths_failed, i == expected_paths.len() - 1);
1406+
for (idx, hop) in expected_route.iter().enumerate() {
1407+
assert_eq!(hop.node.get_our_node_id(), path[idx].pubkey);
1408+
}
14061409
},
14071410
_ => panic!("Unexpected event"),
14081411
}

lightning/src/ln/functional_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6068,7 +6068,7 @@ fn test_fail_holding_cell_htlc_upon_free() {
60686068
let events = nodes[0].node.get_and_clear_pending_events();
60696069
assert_eq!(events.len(), 1);
60706070
match &events[0] {
6071-
&Event::PaymentPathFailed { ref payment_hash, ref rejected_by_dest, ref network_update, ref error_code, ref error_data, ref all_paths_failed } => {
6071+
&Event::PaymentPathFailed { ref payment_hash, ref rejected_by_dest, ref network_update, ref error_code, ref error_data, ref all_paths_failed, path: _ } => {
60726072
assert_eq!(our_payment_hash.clone(), *payment_hash);
60736073
assert_eq!(*rejected_by_dest, false);
60746074
assert_eq!(*all_paths_failed, true);
@@ -6155,7 +6155,7 @@ fn test_free_and_fail_holding_cell_htlcs() {
61556155
let events = nodes[0].node.get_and_clear_pending_events();
61566156
assert_eq!(events.len(), 1);
61576157
match &events[0] {
6158-
&Event::PaymentPathFailed { ref payment_hash, ref rejected_by_dest, ref network_update, ref error_code, ref error_data, ref all_paths_failed } => {
6158+
&Event::PaymentPathFailed { ref payment_hash, ref rejected_by_dest, ref network_update, ref error_code, ref error_data, ref all_paths_failed, path: _ } => {
61596159
assert_eq!(payment_hash_2.clone(), *payment_hash);
61606160
assert_eq!(*rejected_by_dest, false);
61616161
assert_eq!(*all_paths_failed, true);

lightning/src/ln/onion_route_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ fn run_onion_failure_test_with_fail_intercept<F1,F2,F3>(_name: &str, test_case:
163163

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

lightning/src/routing/network_graph.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,7 @@ mod tests {
17291729
payment_hash: PaymentHash([0; 32]),
17301730
rejected_by_dest: false,
17311731
all_paths_failed: true,
1732+
path: vec![],
17321733
network_update: Some(NetworkUpdate::ChannelUpdateMessage {
17331734
msg: valid_channel_update,
17341735
}),
@@ -1752,6 +1753,7 @@ mod tests {
17521753
payment_hash: PaymentHash([0; 32]),
17531754
rejected_by_dest: false,
17541755
all_paths_failed: true,
1756+
path: vec![],
17551757
network_update: Some(NetworkUpdate::ChannelClosed {
17561758
short_channel_id,
17571759
is_permanent: false,
@@ -1774,6 +1776,7 @@ mod tests {
17741776
payment_hash: PaymentHash([0; 32]),
17751777
rejected_by_dest: false,
17761778
all_paths_failed: true,
1779+
path: vec![],
17771780
network_update: Some(NetworkUpdate::ChannelClosed {
17781781
short_channel_id,
17791782
is_permanent: true,

lightning/src/routing/router.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use core::cmp;
2828
use core::ops::Deref;
2929

3030
/// A hop in a route
31-
#[derive(Clone, Hash, PartialEq, Eq)]
31+
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
3232
pub struct RouteHop {
3333
/// The node_id of the node at this hop.
3434
pub pubkey: PublicKey,

lightning/src/util/events.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use ln::msgs;
1919
use ln::msgs::DecodeError;
2020
use ln::{PaymentPreimage, PaymentHash, PaymentSecret};
2121
use routing::network_graph::NetworkUpdate;
22+
use routing::router::RouteHop;
2223
use util::ser::{Writeable, Writer, MaybeReadable, Readable, VecReadWrapper, VecWriteWrapper};
2324

2425
use bitcoin::blockdata::script::Script;
@@ -200,6 +201,8 @@ pub enum Event {
200201
/// failed. This will be set to false if (1) this is an MPP payment and (2) other parts of the
201202
/// larger MPP payment were still in flight when this event was generated.
202203
all_paths_failed: bool,
204+
/// The payment path that failed.
205+
path: Vec<RouteHop>,
203206
#[cfg(test)]
204207
error_code: Option<u16>,
205208
#[cfg(test)]
@@ -291,7 +294,8 @@ impl Writeable for Event {
291294
(0, payment_preimage, required),
292295
});
293296
},
294-
&Event::PaymentPathFailed { ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed,
297+
&Event::PaymentPathFailed { ref payment_hash, ref rejected_by_dest, ref network_update,
298+
ref all_paths_failed, ref path,
295299
#[cfg(test)]
296300
ref error_code,
297301
#[cfg(test)]
@@ -307,6 +311,7 @@ impl Writeable for Event {
307311
(1, network_update, option),
308312
(2, rejected_by_dest, required),
309313
(3, all_paths_failed, required),
314+
(5, path, vec_type),
310315
});
311316
},
312317
&Event::PendingHTLCsForwardable { time_forwardable: _ } => {
@@ -398,17 +403,20 @@ impl MaybeReadable for Event {
398403
let mut rejected_by_dest = false;
399404
let mut network_update = None;
400405
let mut all_paths_failed = Some(true);
406+
let mut path: Option<Vec<RouteHop>> = Some(vec![]);
401407
read_tlv_fields!(reader, {
402408
(0, payment_hash, required),
403409
(1, network_update, ignorable),
404410
(2, rejected_by_dest, required),
405411
(3, all_paths_failed, option),
412+
(5, path, vec_type),
406413
});
407414
Ok(Some(Event::PaymentPathFailed {
408415
payment_hash,
409416
rejected_by_dest,
410417
network_update,
411418
all_paths_failed: all_paths_failed.unwrap(),
419+
path: path.unwrap(),
412420
#[cfg(test)]
413421
error_code,
414422
#[cfg(test)]

0 commit comments

Comments
 (0)