Skip to content

Commit 01c7a2a

Browse files
Abandon payment on behalf of the user on payment path failure
Removed retry_single_path_payment, it's replaced by automatic_retries with AutoRetry::Success
1 parent e2fec45 commit 01c7a2a

8 files changed

+194
-229
lines changed

fuzz/src/chanmon_consistency.rs

+1
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,7 @@ pub fn do_test<Out: Output>(data: &[u8], underlying_out: Out) {
918918
events::Event::PaymentClaimed { .. } => {},
919919
events::Event::PaymentPathSuccessful { .. } => {},
920920
events::Event::PaymentPathFailed { .. } => {},
921+
events::Event::PaymentFailed { .. } => {},
921922
events::Event::ProbeSuccessful { .. } | events::Event::ProbeFailed { .. } => {
922923
// Even though we don't explicitly send probes, because probes are
923924
// detected based on hashing the payment hash+preimage, its rather

lightning/src/ln/chanmon_update_fail_tests.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1752,12 +1752,18 @@ fn test_monitor_update_on_pending_forwards() {
17521752
commitment_signed_dance!(nodes[0], nodes[1], bs_updates.commitment_signed, false, true);
17531753

17541754
let events = nodes[0].node.get_and_clear_pending_events();
1755-
assert_eq!(events.len(), 2);
1755+
assert_eq!(events.len(), 3);
17561756
if let Event::PaymentPathFailed { payment_hash, payment_failed_permanently, .. } = events[0] {
17571757
assert_eq!(payment_hash, payment_hash_1);
17581758
assert!(payment_failed_permanently);
17591759
} else { panic!("Unexpected event!"); }
17601760
match events[1] {
1761+
Event::PaymentFailed { payment_hash, .. } => {
1762+
assert_eq!(payment_hash, payment_hash_1);
1763+
},
1764+
_ => panic!("Unexpected event"),
1765+
}
1766+
match events[2] {
17611767
Event::PendingHTLCsForwardable { .. } => { },
17621768
_ => panic!("Unexpected event"),
17631769
};

lightning/src/ln/functional_test_utils.rs

+22-35
Original file line numberDiff line numberDiff line change
@@ -1796,17 +1796,17 @@ macro_rules! expect_payment_failed {
17961796
}
17971797

17981798
pub fn expect_payment_failed_conditions_event<'a, 'b, 'c, 'd, 'e>(
1799-
node: &'a Node<'b, 'c, 'd>, payment_failed_event: Event, expected_payment_hash: PaymentHash,
1799+
payment_failed_events: Vec<Event>, expected_payment_hash: PaymentHash,
18001800
expected_payment_failed_permanently: bool, conditions: PaymentFailedConditions<'e>
18011801
) {
1802-
let expected_payment_id = match payment_failed_event {
1802+
let expected_payment_id = match &payment_failed_events[0] {
18031803
Event::PaymentPathFailed { payment_hash, payment_failed_permanently, path, retry, payment_id, network_update, short_channel_id,
18041804
#[cfg(test)]
18051805
error_code,
18061806
#[cfg(test)]
18071807
error_data, .. } => {
1808-
assert_eq!(payment_hash, expected_payment_hash, "unexpected payment_hash");
1809-
assert_eq!(payment_failed_permanently, expected_payment_failed_permanently, "unexpected payment_failed_permanently value");
1808+
assert_eq!(*payment_hash, expected_payment_hash, "unexpected payment_hash");
1809+
assert_eq!(*payment_failed_permanently, expected_payment_failed_permanently, "unexpected payment_failed_permanently value");
18101810
assert!(retry.is_some(), "expected retry.is_some()");
18111811
assert_eq!(retry.as_ref().unwrap().final_value_msat, path.last().unwrap().fee_msat, "Retry amount should match last hop in path");
18121812
assert_eq!(retry.as_ref().unwrap().payment_params.payee_pubkey, path.last().unwrap().pubkey, "Retry payee node_id should match last hop in path");
@@ -1835,7 +1835,7 @@ pub fn expect_payment_failed_conditions_event<'a, 'b, 'c, 'd, 'e>(
18351835
},
18361836
Some(NetworkUpdate::ChannelFailure { short_channel_id, is_permanent }) if chan_closed => {
18371837
if let Some(scid) = conditions.expected_blamed_scid {
1838-
assert_eq!(short_channel_id, scid);
1838+
assert_eq!(*short_channel_id, scid);
18391839
}
18401840
assert!(is_permanent);
18411841
},
@@ -1849,10 +1849,7 @@ pub fn expect_payment_failed_conditions_event<'a, 'b, 'c, 'd, 'e>(
18491849
_ => panic!("Unexpected event"),
18501850
};
18511851
if !conditions.expected_mpp_parts_remain {
1852-
node.node.abandon_payment(expected_payment_id);
1853-
let events = node.node.get_and_clear_pending_events();
1854-
assert_eq!(events.len(), 1);
1855-
match events[0] {
1852+
match &payment_failed_events[1] {
18561853
Event::PaymentFailed { ref payment_hash, ref payment_id } => {
18571854
assert_eq!(*payment_hash, expected_payment_hash, "unexpected second payment_hash");
18581855
assert_eq!(*payment_id, expected_payment_id);
@@ -1866,9 +1863,9 @@ pub fn expect_payment_failed_conditions<'a, 'b, 'c, 'd, 'e>(
18661863
node: &'a Node<'b, 'c, 'd>, expected_payment_hash: PaymentHash, expected_payment_failed_permanently: bool,
18671864
conditions: PaymentFailedConditions<'e>
18681865
) {
1869-
let mut events = node.node.get_and_clear_pending_events();
1870-
assert_eq!(events.len(), 1);
1871-
expect_payment_failed_conditions_event(node, events.pop().unwrap(), expected_payment_hash, expected_payment_failed_permanently, conditions);
1866+
let events = node.node.get_and_clear_pending_events();
1867+
if conditions.expected_mpp_parts_remain { assert_eq!(events.len(), 1); } else { assert_eq!(events.len(), 2); }
1868+
expect_payment_failed_conditions_event(events, expected_payment_hash, expected_payment_failed_permanently, conditions);
18721869
}
18731870

18741871
pub fn send_along_route_with_secret<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, route: Route, expected_paths: &[&[&Node<'a, 'b, 'c>]], recv_value: u64, our_payment_hash: PaymentHash, our_payment_secret: PaymentSecret) -> PaymentId {
@@ -2155,22 +2152,6 @@ pub fn fail_payment_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expe
21552152
}
21562153

21572154
pub fn pass_failed_payment_back<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_paths_slice: &[&[&Node<'a, 'b, 'c>]], skip_last: bool, our_payment_hash: PaymentHash) {
2158-
let expected_payment_id = pass_failed_payment_back_no_abandon(origin_node, expected_paths_slice, skip_last, our_payment_hash);
2159-
if !skip_last {
2160-
origin_node.node.abandon_payment(expected_payment_id.unwrap());
2161-
let events = origin_node.node.get_and_clear_pending_events();
2162-
assert_eq!(events.len(), 1);
2163-
match events[0] {
2164-
Event::PaymentFailed { ref payment_hash, ref payment_id } => {
2165-
assert_eq!(*payment_hash, our_payment_hash, "unexpected second payment_hash");
2166-
assert_eq!(*payment_id, expected_payment_id.unwrap());
2167-
}
2168-
_ => panic!("Unexpected second event"),
2169-
}
2170-
}
2171-
}
2172-
2173-
pub fn pass_failed_payment_back_no_abandon<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_paths_slice: &[&[&Node<'a, 'b, 'c>]], skip_last: bool, our_payment_hash: PaymentHash) -> Option<PaymentId> {
21742155
let mut expected_paths: Vec<_> = expected_paths_slice.iter().collect();
21752156
check_added_monitors!(expected_paths[0].last().unwrap(), expected_paths.len());
21762157

@@ -2194,8 +2175,6 @@ pub fn pass_failed_payment_back_no_abandon<'a, 'b, 'c>(origin_node: &Node<'a, 'b
21942175
per_path_msgs.sort_unstable_by(|(_, node_id_a), (_, node_id_b)| node_id_a.cmp(node_id_b));
21952176
expected_paths.sort_unstable_by(|path_a, path_b| path_a[path_a.len() - 2].node.get_our_node_id().cmp(&path_b[path_b.len() - 2].node.get_our_node_id()));
21962177

2197-
let mut expected_payment_id = None;
2198-
21992178
for (i, (expected_route, (path_msgs, next_hop))) in expected_paths.iter().zip(per_path_msgs.drain(..)).enumerate() {
22002179
let mut next_msgs = Some(path_msgs);
22012180
let mut expected_next_node = next_hop;
@@ -2243,8 +2222,9 @@ pub fn pass_failed_payment_back_no_abandon<'a, 'b, 'c>(origin_node: &Node<'a, 'b
22432222
assert!(origin_node.node.get_and_clear_pending_msg_events().is_empty());
22442223
commitment_signed_dance!(origin_node, prev_node, next_msgs.as_ref().unwrap().1, false);
22452224
let events = origin_node.node.get_and_clear_pending_events();
2246-
assert_eq!(events.len(), 1);
2247-
expected_payment_id = Some(match events[0] {
2225+
if i == expected_paths.len() - 1 { assert_eq!(events.len(), 2); } else { assert_eq!(events.len(), 1); }
2226+
2227+
let expected_payment_id = match events[0] {
22482228
Event::PaymentPathFailed { payment_hash, payment_failed_permanently, all_paths_failed, ref path, ref payment_id, .. } => {
22492229
assert_eq!(payment_hash, our_payment_hash);
22502230
assert!(payment_failed_permanently);
@@ -2255,7 +2235,16 @@ pub fn pass_failed_payment_back_no_abandon<'a, 'b, 'c>(origin_node: &Node<'a, 'b
22552235
payment_id.unwrap()
22562236
},
22572237
_ => panic!("Unexpected event"),
2258-
});
2238+
};
2239+
if i == expected_paths.len() - 1 {
2240+
match events[1] {
2241+
Event::PaymentFailed { ref payment_hash, ref payment_id } => {
2242+
assert_eq!(*payment_hash, our_payment_hash, "unexpected second payment_hash");
2243+
assert_eq!(*payment_id, expected_payment_id);
2244+
}
2245+
_ => panic!("Unexpected second event"),
2246+
}
2247+
}
22592248
}
22602249
}
22612250

@@ -2264,8 +2253,6 @@ pub fn pass_failed_payment_back_no_abandon<'a, 'b, 'c>(origin_node: &Node<'a, 'b
22642253
assert!(expected_paths[0].last().unwrap().node.get_and_clear_pending_events().is_empty());
22652254
assert!(expected_paths[0].last().unwrap().node.get_and_clear_pending_msg_events().is_empty());
22662255
check_added_monitors!(expected_paths[0].last().unwrap(), 0);
2267-
2268-
expected_payment_id
22692256
}
22702257

22712258
pub fn fail_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_path: &[&Node<'a, 'b, 'c>], our_payment_hash: PaymentHash) {

0 commit comments

Comments
 (0)