Skip to content

Commit 202acd9

Browse files
committed
Add failing short channel id to PaymentPathFailed
This will be useful for scoring channels when a payment fails.
1 parent 1e2ca52 commit 202acd9

File tree

6 files changed

+124
-59
lines changed

6 files changed

+124
-59
lines changed

lightning/src/ln/channelmanager.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -2888,6 +2888,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
28882888
network_update: None,
28892889
all_paths_failed: sessions.get().len() == 0,
28902890
path: path.clone(),
2891+
short_channel_id: None,
28912892
#[cfg(test)]
28922893
error_code: None,
28932894
#[cfg(test)]
@@ -2945,9 +2946,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
29452946
match &onion_error {
29462947
&HTLCFailReason::LightningError { ref err } => {
29472948
#[cfg(test)]
2948-
let (network_update, payment_retryable, onion_error_code, onion_error_data) = onion_utils::process_onion_failure(&self.secp_ctx, &self.logger, &source, err.data.clone());
2949+
let (network_update, short_channel_id, payment_retryable, onion_error_code, onion_error_data) = onion_utils::process_onion_failure(&self.secp_ctx, &self.logger, &source, err.data.clone());
29492950
#[cfg(not(test))]
2950-
let (network_update, payment_retryable, _, _) = onion_utils::process_onion_failure(&self.secp_ctx, &self.logger, &source, err.data.clone());
2951+
let (network_update, short_channel_id, payment_retryable, _, _) = onion_utils::process_onion_failure(&self.secp_ctx, &self.logger, &source, err.data.clone());
29512952
// TODO: If we decided to blame ourselves (or one of our channels) in
29522953
// process_onion_failure we should close that channel as it implies our
29532954
// next-hop is needlessly blaming us!
@@ -2958,6 +2959,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
29582959
network_update,
29592960
all_paths_failed,
29602961
path: path.clone(),
2962+
short_channel_id,
29612963
#[cfg(test)]
29622964
error_code: onion_error_code,
29632965
#[cfg(test)]
@@ -2985,6 +2987,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
29852987
network_update: None,
29862988
all_paths_failed,
29872989
path: path.clone(),
2990+
short_channel_id: Some(path.first().unwrap().short_channel_id),
29882991
#[cfg(test)]
29892992
error_code: Some(*failure_code),
29902993
#[cfg(test)]

lightning/src/ln/functional_tests.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -6068,11 +6068,12 @@ 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, path: _ } => {
6071+
&Event::PaymentPathFailed { ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed, path: _, ref short_channel_id, ref error_code, ref error_data } => {
60726072
assert_eq!(our_payment_hash.clone(), *payment_hash);
60736073
assert_eq!(*rejected_by_dest, false);
60746074
assert_eq!(*all_paths_failed, true);
60756075
assert_eq!(*network_update, None);
6076+
assert_eq!(*short_channel_id, None);
60766077
assert_eq!(*error_code, None);
60776078
assert_eq!(*error_data, None);
60786079
},
@@ -6155,11 +6156,12 @@ fn test_free_and_fail_holding_cell_htlcs() {
61556156
let events = nodes[0].node.get_and_clear_pending_events();
61566157
assert_eq!(events.len(), 1);
61576158
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, path: _ } => {
6159+
&Event::PaymentPathFailed { ref payment_hash, ref rejected_by_dest, ref network_update, ref all_paths_failed, path: _, ref short_channel_id, ref error_code, ref error_data } => {
61596160
assert_eq!(payment_hash_2.clone(), *payment_hash);
61606161
assert_eq!(*rejected_by_dest, false);
61616162
assert_eq!(*all_paths_failed, true);
61626163
assert_eq!(*network_update, None);
6164+
assert_eq!(*short_channel_id, None);
61636165
assert_eq!(*error_code, None);
61646166
assert_eq!(*error_data, None);
61656167
},

0 commit comments

Comments
 (0)