From e5310dd5f0347fcaaf21b2742a1084f97fc84bd8 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Mon, 20 Sep 2021 12:56:33 -0400 Subject: [PATCH] Add path field to PaymentPathFailed event --- lightning/src/ln/channelmanager.rs | 5 ++++- lightning/src/ln/functional_test_utils.rs | 5 ++++- lightning/src/ln/functional_tests.rs | 4 ++-- lightning/src/ln/onion_route_tests.rs | 2 +- lightning/src/routing/network_graph.rs | 3 +++ lightning/src/routing/router.rs | 2 +- lightning/src/util/events.rs | 10 +++++++++- 7 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index a3b8715f..a4684bfe 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -2875,7 +2875,7 @@ impl ChannelMana self.fail_htlc_backwards_internal(channel_state, htlc_src, &payment_hash, HTLCFailReason::Reason { failure_code, data: onion_failure_data}); }, - HTLCSource::OutboundRoute { session_priv, mpp_id, .. } => { + HTLCSource::OutboundRoute { session_priv, mpp_id, path, .. } => { let mut session_priv_bytes = [0; 32]; session_priv_bytes.copy_from_slice(&session_priv[..]); let mut outbounds = self.pending_outbound_payments.lock().unwrap(); @@ -2887,6 +2887,7 @@ impl ChannelMana rejected_by_dest: false, network_update: None, all_paths_failed: sessions.get().len() == 0, + path: path.clone(), #[cfg(test)] error_code: None, #[cfg(test)] @@ -2956,6 +2957,7 @@ impl ChannelMana rejected_by_dest: !payment_retryable, network_update, all_paths_failed, + path: path.clone(), #[cfg(test)] error_code: onion_error_code, #[cfg(test)] @@ -2982,6 +2984,7 @@ impl ChannelMana rejected_by_dest: path.len() == 1, network_update: None, all_paths_failed, + path: path.clone(), #[cfg(test)] error_code: Some(*failure_code), #[cfg(test)] diff --git a/lightning/src/ln/functional_test_utils.rs b/lightning/src/ln/functional_test_utils.rs index e30046c9..9fbbcfff 100644 --- a/lightning/src/ln/functional_test_utils.rs +++ b/lightning/src/ln/functional_test_utils.rs @@ -1399,10 +1399,13 @@ pub fn fail_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expe let events = origin_node.node.get_and_clear_pending_events(); assert_eq!(events.len(), 1); match events[0] { - Event::PaymentPathFailed { payment_hash, rejected_by_dest, all_paths_failed, .. } => { + Event::PaymentPathFailed { payment_hash, rejected_by_dest, all_paths_failed, ref path, .. } => { assert_eq!(payment_hash, our_payment_hash); assert!(rejected_by_dest); assert_eq!(all_paths_failed, i == expected_paths.len() - 1); + for (idx, hop) in expected_route.iter().enumerate() { + assert_eq!(hop.node.get_our_node_id(), path[idx].pubkey); + } }, _ => panic!("Unexpected event"), } diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index 00dacc42..03b62ac1 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -6068,7 +6068,7 @@ fn test_fail_holding_cell_htlc_upon_free() { let events = nodes[0].node.get_and_clear_pending_events(); assert_eq!(events.len(), 1); match &events[0] { - &Event::PaymentPathFailed { ref payment_hash, ref rejected_by_dest, ref network_update, ref error_code, ref error_data, ref all_paths_failed } => { + &Event::PaymentPathFailed { ref payment_hash, ref rejected_by_dest, ref network_update, ref error_code, ref error_data, ref all_paths_failed, path: _ } => { assert_eq!(our_payment_hash.clone(), *payment_hash); assert_eq!(*rejected_by_dest, false); assert_eq!(*all_paths_failed, true); @@ -6155,7 +6155,7 @@ fn test_free_and_fail_holding_cell_htlcs() { let events = nodes[0].node.get_and_clear_pending_events(); assert_eq!(events.len(), 1); match &events[0] { - &Event::PaymentPathFailed { ref payment_hash, ref rejected_by_dest, ref network_update, ref error_code, ref error_data, ref all_paths_failed } => { + &Event::PaymentPathFailed { ref payment_hash, ref rejected_by_dest, ref network_update, ref error_code, ref error_data, ref all_paths_failed, path: _ } => { assert_eq!(payment_hash_2.clone(), *payment_hash); assert_eq!(*rejected_by_dest, false); assert_eq!(*all_paths_failed, true); diff --git a/lightning/src/ln/onion_route_tests.rs b/lightning/src/ln/onion_route_tests.rs index 09020085..0e2d081c 100644 --- a/lightning/src/ln/onion_route_tests.rs +++ b/lightning/src/ln/onion_route_tests.rs @@ -163,7 +163,7 @@ fn run_onion_failure_test_with_fail_intercept(_name: &str, test_case: let events = nodes[0].node.get_and_clear_pending_events(); assert_eq!(events.len(), 1); - if let &Event::PaymentPathFailed { payment_hash:_, ref rejected_by_dest, ref network_update, ref error_code, error_data: _, ref all_paths_failed } = &events[0] { + 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] { assert_eq!(*rejected_by_dest, !expected_retryable); assert_eq!(*all_paths_failed, true); assert_eq!(*error_code, expected_error_code); diff --git a/lightning/src/routing/network_graph.rs b/lightning/src/routing/network_graph.rs index c39dde7b..29bbc580 100644 --- a/lightning/src/routing/network_graph.rs +++ b/lightning/src/routing/network_graph.rs @@ -1729,6 +1729,7 @@ mod tests { payment_hash: PaymentHash([0; 32]), rejected_by_dest: false, all_paths_failed: true, + path: vec![], network_update: Some(NetworkUpdate::ChannelUpdateMessage { msg: valid_channel_update, }), @@ -1752,6 +1753,7 @@ mod tests { payment_hash: PaymentHash([0; 32]), rejected_by_dest: false, all_paths_failed: true, + path: vec![], network_update: Some(NetworkUpdate::ChannelClosed { short_channel_id, is_permanent: false, @@ -1774,6 +1776,7 @@ mod tests { payment_hash: PaymentHash([0; 32]), rejected_by_dest: false, all_paths_failed: true, + path: vec![], network_update: Some(NetworkUpdate::ChannelClosed { short_channel_id, is_permanent: true, diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index 98b3d8f5..03ec1b33 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -28,7 +28,7 @@ use core::cmp; use core::ops::Deref; /// A hop in a route -#[derive(Clone, Hash, PartialEq, Eq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct RouteHop { /// The node_id of the node at this hop. pub pubkey: PublicKey, diff --git a/lightning/src/util/events.rs b/lightning/src/util/events.rs index a2f48e06..1319f7d2 100644 --- a/lightning/src/util/events.rs +++ b/lightning/src/util/events.rs @@ -20,6 +20,7 @@ use ln::msgs::DecodeError; use ln::{PaymentPreimage, PaymentHash, PaymentSecret}; use routing::network_graph::NetworkUpdate; use util::ser::{BigSize, FixedLengthReader, Writeable, Writer, MaybeReadable, Readable, VecReadWrapper, VecWriteWrapper}; +use routing::router::RouteHop; use bitcoin::blockdata::script::Script; @@ -200,6 +201,8 @@ pub enum Event { /// failed. This will be set to false if (1) this is an MPP payment and (2) other parts of the /// larger MPP payment were still in flight when this event was generated. all_paths_failed: bool, + /// The payment path that failed. + path: Vec, #[cfg(test)] error_code: Option, #[cfg(test)] @@ -291,7 +294,8 @@ impl Writeable for Event { (0, payment_preimage, required), }); }, - &Event::PaymentPathFailed { ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed, + &Event::PaymentPathFailed { ref payment_hash, ref rejected_by_dest, ref network_update, + ref all_paths_failed, ref path, #[cfg(test)] ref error_code, #[cfg(test)] @@ -307,6 +311,7 @@ impl Writeable for Event { (1, network_update, option), (2, rejected_by_dest, required), (3, all_paths_failed, required), + (5, path, vec_type), }); }, &Event::PendingHTLCsForwardable { time_forwardable: _ } => { @@ -403,17 +408,20 @@ impl MaybeReadable for Event { let mut rejected_by_dest = false; let mut network_update = None; let mut all_paths_failed = Some(true); + let mut path: Option> = Some(vec![]); read_tlv_fields!(reader, { (0, payment_hash, required), (1, network_update, ignorable), (2, rejected_by_dest, required), (3, all_paths_failed, option), + (5, path, vec_type), }); Ok(Some(Event::PaymentPathFailed { payment_hash, rejected_by_dest, network_update, all_paths_failed: all_paths_failed.unwrap(), + path: path.unwrap(), #[cfg(test)] error_code, #[cfg(test)] -- 2.30.2