Skip to content

Commit f2bb931

Browse files
committed
Rewrite failure payment retry tests to avoid perm-fail storage
Two tests in the payment tests currently rely on failing to persist ChannelMonitorUpdates as their method of failing payments before they even get out the door. In the coming commits we'll drop the persist failure error codes, so here rewrite these tests to rely on trying to send more than is available in a channel.
1 parent a7e3575 commit f2bb931

File tree

1 file changed

+39
-40
lines changed

1 file changed

+39
-40
lines changed

lightning/src/ln/payment_tests.rs

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,12 +2258,14 @@ fn auto_retry_partial_failure() {
22582258
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
22592259
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
22602260

2261+
// Open three channels, the first has plenty of liquidity, the second and third have ~no
2262+
// available liquidity, causing any outbound payments routed over it to fail immediately.
22612263
let chan_1_id = create_announced_chan_between_nodes(&nodes, 0, 1).0.contents.short_channel_id;
2262-
let chan_2_id = create_announced_chan_between_nodes(&nodes, 0, 1).0.contents.short_channel_id;
2263-
let chan_3_id = create_announced_chan_between_nodes(&nodes, 0, 1).0.contents.short_channel_id;
2264+
let chan_2_id = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 989_000_000).0.contents.short_channel_id;
2265+
let chan_3_id = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 989_000_000).0.contents.short_channel_id;
22642266

22652267
// Marshall data to send the payment
2266-
let amt_msat = 20_000;
2268+
let amt_msat = 10_000_000;
22672269
let (_, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(&nodes[0], nodes[1], amt_msat);
22682270
#[cfg(feature = "std")]
22692271
let payment_expiry_secs = SystemTime::UNIX_EPOCH.elapsed().unwrap().as_secs() + 60 * 60;
@@ -2278,16 +2280,6 @@ fn auto_retry_partial_failure() {
22782280
.with_bolt11_features(invoice_features).unwrap();
22792281
let route_params = RouteParameters::from_payment_params_and_value(payment_params, amt_msat);
22802282

2281-
// Ensure the first monitor update (for the initial send path1 over chan_1) succeeds, but the
2282-
// second (for the initial send path2 over chan_2) fails.
2283-
chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed);
2284-
chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::PermanentFailure);
2285-
// Ensure third monitor update (for the retry1's path1 over chan_1) succeeds, but the fourth (for
2286-
// the retry1's path2 over chan_3) fails, and monitor updates succeed after that.
2287-
chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed);
2288-
chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::PermanentFailure);
2289-
chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed);
2290-
22912283
// Configure the initial send, retry1 and retry2's paths.
22922284
let send_route = Route {
22932285
paths: vec![
@@ -2364,32 +2356,23 @@ fn auto_retry_partial_failure() {
23642356
// Send a payment that will partially fail on send, then partially fail on retry, then succeed.
23652357
nodes[0].node.send_payment(payment_hash, RecipientOnionFields::secret_only(payment_secret),
23662358
PaymentId(payment_hash.0), route_params, Retry::Attempts(3)).unwrap();
2367-
let closed_chan_events = nodes[0].node.get_and_clear_pending_events();
2368-
assert_eq!(closed_chan_events.len(), 4);
2369-
match closed_chan_events[0] {
2370-
Event::ChannelClosed { .. } => {},
2371-
_ => panic!("Unexpected event"),
2372-
}
2373-
match closed_chan_events[1] {
2359+
let payment_failed_events = nodes[0].node.get_and_clear_pending_events();
2360+
assert_eq!(payment_failed_events.len(), 2);
2361+
match payment_failed_events[0] {
23742362
Event::PaymentPathFailed { .. } => {},
23752363
_ => panic!("Unexpected event"),
23762364
}
2377-
match closed_chan_events[2] {
2378-
Event::ChannelClosed { .. } => {},
2379-
_ => panic!("Unexpected event"),
2380-
}
2381-
match closed_chan_events[3] {
2365+
match payment_failed_events[1] {
23822366
Event::PaymentPathFailed { .. } => {},
23832367
_ => panic!("Unexpected event"),
23842368
}
23852369

23862370
// Pass the first part of the payment along the path.
2387-
check_added_monitors!(nodes[0], 5); // three outbound channel updates succeeded, two permanently failed
2371+
check_added_monitors!(nodes[0], 1); // only one HTLC actually made it out
23882372
let mut msg_events = nodes[0].node.get_and_clear_pending_msg_events();
23892373

2390-
// First message is the first update_add, remaining messages are broadcasting channel updates and
2391-
// errors for the permfailed channels
2392-
assert_eq!(msg_events.len(), 5);
2374+
// Only one HTLC/channel update actually made it out
2375+
assert_eq!(msg_events.len(), 1);
23932376
let mut payment_event = SendEvent::from_event(msg_events.remove(0));
23942377

23952378
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]);
@@ -2478,12 +2461,13 @@ fn auto_retry_zero_attempts_send_error() {
24782461
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
24792462
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
24802463

2481-
create_announced_chan_between_nodes(&nodes, 0, 1).0.contents.short_channel_id;
2482-
create_announced_chan_between_nodes(&nodes, 0, 1).0.contents.short_channel_id;
2464+
// Open a single channel that does not have sufficient liquidity for the payment we want to
2465+
// send.
2466+
let chan_id = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 989_000_000).0.contents.short_channel_id;
24832467

24842468
// Marshall data to send the payment
2485-
let amt_msat = 20_000;
2486-
let (_, payment_hash, _, payment_secret) = get_route_and_payment_hash!(&nodes[0], nodes[1], amt_msat);
2469+
let amt_msat = 10_000_000;
2470+
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[1], Some(amt_msat), None);
24872471
#[cfg(feature = "std")]
24882472
let payment_expiry_secs = SystemTime::UNIX_EPOCH.elapsed().unwrap().as_secs() + 60 * 60;
24892473
#[cfg(not(feature = "std"))]
@@ -2497,16 +2481,31 @@ fn auto_retry_zero_attempts_send_error() {
24972481
.with_bolt11_features(invoice_features).unwrap();
24982482
let route_params = RouteParameters::from_payment_params_and_value(payment_params, amt_msat);
24992483

2500-
chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::PermanentFailure);
2484+
// Override the route search to return a route, rather than failing at the route-finding step.
2485+
let send_route = Route {
2486+
paths: vec![
2487+
Path { hops: vec![RouteHop {
2488+
pubkey: nodes[1].node.get_our_node_id(),
2489+
node_features: nodes[1].node.node_features(),
2490+
short_channel_id: chan_id,
2491+
channel_features: nodes[1].node.channel_features(),
2492+
fee_msat: amt_msat,
2493+
cltv_expiry_delta: 100,
2494+
maybe_announced_channel: true,
2495+
}], blinded_tail: None },
2496+
],
2497+
route_params: Some(route_params.clone()),
2498+
};
2499+
nodes[0].router.expect_find_route(route_params.clone(), Ok(send_route));
2500+
25012501
nodes[0].node.send_payment(payment_hash, RecipientOnionFields::secret_only(payment_secret),
25022502
PaymentId(payment_hash.0), route_params, Retry::Attempts(0)).unwrap();
2503-
assert_eq!(nodes[0].node.get_and_clear_pending_msg_events().len(), 2); // channel close messages
2503+
assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
25042504
let events = nodes[0].node.get_and_clear_pending_events();
2505-
assert_eq!(events.len(), 3);
2506-
if let Event::ChannelClosed { .. } = events[0] { } else { panic!(); }
2507-
if let Event::PaymentPathFailed { .. } = events[1] { } else { panic!(); }
2508-
if let Event::PaymentFailed { .. } = events[2] { } else { panic!(); }
2509-
check_added_monitors!(nodes[0], 2);
2505+
assert_eq!(events.len(), 2);
2506+
if let Event::PaymentPathFailed { .. } = events[0] { } else { panic!(); }
2507+
if let Event::PaymentFailed { .. } = events[1] { } else { panic!(); }
2508+
check_added_monitors!(nodes[0], 0);
25102509
}
25112510

25122511
#[test]

0 commit comments

Comments
 (0)