Skip to content

Commit fcf02f1

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 17bc1ee commit fcf02f1

File tree

1 file changed

+35
-36
lines changed

1 file changed

+35
-36
lines changed

lightning/src/ln/payment_tests.rs

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,12 +2161,14 @@ fn auto_retry_partial_failure() {
21612161
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
21622162
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
21632163

2164+
// Open three channels, the first has plenty of liquidity, the second and third have ~no
2165+
// available liquidity, causing any outbound payments routed over it to fail immediately.
21642166
let chan_1_id = create_announced_chan_between_nodes(&nodes, 0, 1).0.contents.short_channel_id;
2165-
let chan_2_id = create_announced_chan_between_nodes(&nodes, 0, 1).0.contents.short_channel_id;
2166-
let chan_3_id = create_announced_chan_between_nodes(&nodes, 0, 1).0.contents.short_channel_id;
2167+
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;
2168+
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;
21672169

21682170
// Marshall data to send the payment
2169-
let amt_msat = 20_000;
2171+
let amt_msat = 10_000_000;
21702172
let (_, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(&nodes[0], nodes[1], amt_msat);
21712173
#[cfg(feature = "std")]
21722174
let payment_expiry_secs = SystemTime::UNIX_EPOCH.elapsed().unwrap().as_secs() + 60 * 60;
@@ -2181,16 +2183,6 @@ fn auto_retry_partial_failure() {
21812183
.with_bolt11_features(invoice_features).unwrap();
21822184
let route_params = RouteParameters::from_payment_params_and_value(payment_params, amt_msat);
21832185

2184-
// Ensure the first monitor update (for the initial send path1 over chan_1) succeeds, but the
2185-
// second (for the initial send path2 over chan_2) fails.
2186-
chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed);
2187-
chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::PermanentFailure);
2188-
// Ensure third monitor update (for the retry1's path1 over chan_1) succeeds, but the fourth (for
2189-
// the retry1's path2 over chan_3) fails, and monitor updates succeed after that.
2190-
chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed);
2191-
chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::PermanentFailure);
2192-
chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::Completed);
2193-
21942186
// Configure the initial send, retry1 and retry2's paths.
21952187
let send_route = Route {
21962188
paths: vec![
@@ -2263,31 +2255,23 @@ fn auto_retry_partial_failure() {
22632255
nodes[0].node.send_payment(payment_hash, RecipientOnionFields::secret_only(payment_secret),
22642256
PaymentId(payment_hash.0), route_params, Retry::Attempts(3)).unwrap();
22652257
let closed_chan_events = nodes[0].node.get_and_clear_pending_events();
2266-
assert_eq!(closed_chan_events.len(), 4);
2258+
assert_eq!(closed_chan_events.len(), 2);
22672259
match closed_chan_events[0] {
2268-
Event::ChannelClosed { .. } => {},
2269-
_ => panic!("Unexpected event"),
2270-
}
2271-
match closed_chan_events[1] {
22722260
Event::PaymentPathFailed { .. } => {},
22732261
_ => panic!("Unexpected event"),
22742262
}
2275-
match closed_chan_events[2] {
2276-
Event::ChannelClosed { .. } => {},
2277-
_ => panic!("Unexpected event"),
2278-
}
2279-
match closed_chan_events[3] {
2263+
match closed_chan_events[1] {
22802264
Event::PaymentPathFailed { .. } => {},
22812265
_ => panic!("Unexpected event"),
22822266
}
22832267

22842268
// Pass the first part of the payment along the path.
2285-
check_added_monitors!(nodes[0], 5); // three outbound channel updates succeeded, two permanently failed
2269+
check_added_monitors!(nodes[0], 1); // three outbound channel updates succeeded, two permanently failed
22862270
let mut msg_events = nodes[0].node.get_and_clear_pending_msg_events();
22872271

22882272
// First message is the first update_add, remaining messages are broadcasting channel updates and
22892273
// errors for the permfailed channels
2290-
assert_eq!(msg_events.len(), 5);
2274+
assert_eq!(msg_events.len(), 1);
22912275
let mut payment_event = SendEvent::from_event(msg_events.remove(0));
22922276

22932277
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]);
@@ -2376,12 +2360,13 @@ fn auto_retry_zero_attempts_send_error() {
23762360
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
23772361
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
23782362

2379-
create_announced_chan_between_nodes(&nodes, 0, 1).0.contents.short_channel_id;
2380-
create_announced_chan_between_nodes(&nodes, 0, 1).0.contents.short_channel_id;
2363+
// Open a single channel that does not have sufficient liquidity for the payment we want to
2364+
// send.
2365+
let chan_id = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 989_000_000).0.contents.short_channel_id;
23812366

23822367
// Marshall data to send the payment
2383-
let amt_msat = 20_000;
2384-
let (_, payment_hash, _, payment_secret) = get_route_and_payment_hash!(&nodes[0], nodes[1], amt_msat);
2368+
let amt_msat = 10_000_000;
2369+
let (_, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[1], Some(amt_msat), None);
23852370
#[cfg(feature = "std")]
23862371
let payment_expiry_secs = SystemTime::UNIX_EPOCH.elapsed().unwrap().as_secs() + 60 * 60;
23872372
#[cfg(not(feature = "std"))]
@@ -2395,16 +2380,30 @@ fn auto_retry_zero_attempts_send_error() {
23952380
.with_bolt11_features(invoice_features).unwrap();
23962381
let route_params = RouteParameters::from_payment_params_and_value(payment_params, amt_msat);
23972382

2398-
chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::PermanentFailure);
2383+
// Override the route search to return a route, rather than failing at the route-finding step.
2384+
let send_route = Route {
2385+
paths: vec![
2386+
Path { hops: vec![RouteHop {
2387+
pubkey: nodes[1].node.get_our_node_id(),
2388+
node_features: nodes[1].node.node_features(),
2389+
short_channel_id: chan_id,
2390+
channel_features: nodes[1].node.channel_features(),
2391+
fee_msat: amt_msat,
2392+
cltv_expiry_delta: 100,
2393+
}], blinded_tail: None },
2394+
],
2395+
route_params: Some(route_params.clone()),
2396+
};
2397+
nodes[0].router.expect_find_route(route_params.clone(), Ok(send_route));
2398+
23992399
nodes[0].node.send_payment(payment_hash, RecipientOnionFields::secret_only(payment_secret),
24002400
PaymentId(payment_hash.0), route_params, Retry::Attempts(0)).unwrap();
2401-
assert_eq!(nodes[0].node.get_and_clear_pending_msg_events().len(), 2); // channel close messages
2401+
assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
24022402
let events = nodes[0].node.get_and_clear_pending_events();
2403-
assert_eq!(events.len(), 3);
2404-
if let Event::ChannelClosed { .. } = events[0] { } else { panic!(); }
2405-
if let Event::PaymentPathFailed { .. } = events[1] { } else { panic!(); }
2406-
if let Event::PaymentFailed { .. } = events[2] { } else { panic!(); }
2407-
check_added_monitors!(nodes[0], 2);
2403+
assert_eq!(events.len(), 2);
2404+
if let Event::PaymentPathFailed { .. } = events[0] { } else { panic!(); }
2405+
if let Event::PaymentFailed { .. } = events[1] { } else { panic!(); }
2406+
check_added_monitors!(nodes[0], 0);
24082407
}
24092408

24102409
#[test]

0 commit comments

Comments
 (0)