From: Jeffrey Czyz Date: Thu, 30 Sep 2021 22:29:44 +0000 (-0700) Subject: Add PaymentId to PaymentPathFailed event X-Git-Tag: v0.0.103~8^2~6 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=73f601fd3d1c9defe553392264ca6dbcc53e4334;p=rust-lightning 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. --- diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 8e911876f..b93e6671a 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -3120,6 +3120,7 @@ impl ChannelMana } else { None }; self.pending_events.lock().unwrap().push( events::Event::PaymentPathFailed { + payment_id: Some(payment_id), payment_hash, rejected_by_dest: false, network_update: None, @@ -3200,6 +3201,7 @@ impl ChannelMana // next-hop is needlessly blaming us! self.pending_events.lock().unwrap().push( events::Event::PaymentPathFailed { + payment_id: Some(payment_id), payment_hash: payment_hash.clone(), rejected_by_dest: !payment_retryable, network_update, @@ -3229,6 +3231,7 @@ impl ChannelMana // channel here as we apparently can't relay through them anyway. self.pending_events.lock().unwrap().push( events::Event::PaymentPathFailed { + payment_id: Some(payment_id), payment_hash: payment_hash.clone(), rejected_by_dest: path.len() == 1, network_update: None, diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index d92b914b0..798a6f443 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -5844,7 +5844,7 @@ fn test_fail_holding_cell_htlc_upon_free() { let (route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], max_can_send); // Send a payment which passes reserve checks but gets stuck in the holding cell. - nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret)).unwrap(); + let our_payment_id = nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret)).unwrap(); chan_stat = get_channel_value_stat!(nodes[0], chan.2); assert_eq!(chan_stat.holding_cell_outbound_amount_msat, max_can_send); @@ -5869,7 +5869,8 @@ 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 all_paths_failed, path: _, ref short_channel_id, retry: _, ref error_code, ref error_data } => { + &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, .. } => { + assert_eq!(our_payment_id, *payment_id.as_ref().unwrap()); assert_eq!(our_payment_hash.clone(), *payment_hash); assert_eq!(*rejected_by_dest, false); assert_eq!(*all_paths_failed, true); @@ -5927,7 +5928,7 @@ fn test_free_and_fail_holding_cell_htlcs() { nodes[0].node.send_payment(&route_1, payment_hash_1, &Some(payment_secret_1)).unwrap(); chan_stat = get_channel_value_stat!(nodes[0], chan.2); assert_eq!(chan_stat.holding_cell_outbound_amount_msat, amt_1); - nodes[0].node.send_payment(&route_2, payment_hash_2, &Some(payment_secret_2)).unwrap(); + let payment_id_2 = nodes[0].node.send_payment(&route_2, payment_hash_2, &Some(payment_secret_2)).unwrap(); chan_stat = get_channel_value_stat!(nodes[0], chan.2); assert_eq!(chan_stat.holding_cell_outbound_amount_msat, amt_1 + amt_2); @@ -5953,7 +5954,8 @@ 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 all_paths_failed, path: _, ref short_channel_id, retry: _, ref error_code, ref error_data } => { + &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, .. } => { + assert_eq!(payment_id_2, *payment_id.as_ref().unwrap()); 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 419d5c158..f3681946d 100644 --- a/lightning/src/ln/onion_route_tests.rs +++ b/lightning/src/ln/onion_route_tests.rs @@ -162,7 +162,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 all_paths_failed, path: _, ref short_channel_id, retry: _, ref error_code, error_data: _ } = &events[0] { + if let &Event::PaymentPathFailed { ref rejected_by_dest, ref network_update, ref all_paths_failed, ref short_channel_id, ref error_code, .. } = &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 216cb45d4..364c9fd88 100644 --- a/lightning/src/routing/network_graph.rs +++ b/lightning/src/routing/network_graph.rs @@ -1806,6 +1806,7 @@ mod tests { assert!(network_graph.read_only().channels().get(&short_channel_id).unwrap().one_to_two.is_none()); net_graph_msg_handler.handle_event(&Event::PaymentPathFailed { + payment_id: None, payment_hash: PaymentHash([0; 32]), rejected_by_dest: false, all_paths_failed: true, @@ -1832,6 +1833,7 @@ mod tests { }; net_graph_msg_handler.handle_event(&Event::PaymentPathFailed { + payment_id: None, payment_hash: PaymentHash([0; 32]), rejected_by_dest: false, all_paths_failed: true, @@ -1857,6 +1859,7 @@ mod tests { // Permanent closing deletes a channel { net_graph_msg_handler.handle_event(&Event::PaymentPathFailed { + payment_id: None, payment_hash: PaymentHash([0; 32]), rejected_by_dest: false, all_paths_failed: true, diff --git a/lightning/src/util/events.rs b/lightning/src/util/events.rs index a311bd52c..148bd096b 100644 --- a/lightning/src/util/events.rs +++ b/lightning/src/util/events.rs @@ -197,6 +197,12 @@ pub enum Event { /// Indicates an outbound payment we made failed. Probably some intermediary node dropped /// something. You may wish to retry with a different route. PaymentPathFailed { + /// The id returned by [`ChannelManager::send_payment`] and used with + /// [`ChannelManager::retry_payment`]. + /// + /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment + /// [`ChannelManager::retry_payment`]: crate::ln::channelmanager::ChannelManager::retry_payment + payment_id: Option, /// The hash which was given to ChannelManager::send_payment. payment_hash: PaymentHash, /// Indicates the payment was rejected for some reason by the recipient. This implies that @@ -338,7 +344,7 @@ impl Writeable for Event { }); }, &Event::PaymentPathFailed { - ref payment_hash, ref rejected_by_dest, ref network_update, + ref payment_id, ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed, ref path, ref short_channel_id, ref retry, #[cfg(test)] ref error_code, @@ -358,6 +364,7 @@ impl Writeable for Event { (5, path, vec_type), (7, short_channel_id, option), (9, retry, option), + (11, payment_id, option), }); }, &Event::PendingHTLCsForwardable { time_forwardable: _ } => { @@ -473,6 +480,7 @@ impl MaybeReadable for Event { let mut path: Option> = Some(vec![]); let mut short_channel_id = None; let mut retry = None; + let mut payment_id = None; read_tlv_fields!(reader, { (0, payment_hash, required), (1, network_update, ignorable), @@ -481,8 +489,10 @@ impl MaybeReadable for Event { (5, path, vec_type), (7, short_channel_id, option), (9, retry, option), + (11, payment_id, option), }); Ok(Some(Event::PaymentPathFailed { + payment_id, payment_hash, rejected_by_dest, network_update,