Skip to content

Commit 9501d64

Browse files
committed
f significantly improve readability of test_path_paused_mpp thanks to
Jeff
1 parent e6ad036 commit 9501d64

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,7 +1765,7 @@ fn during_funding_monitor_fail() {
17651765

17661766
#[test]
17671767
fn test_path_paused_mpp() {
1768-
// Simple test of sending a multi-path payment where one path is currently blocked awaiting
1768+
// Simple test of sending a multi-part payment where one path is currently blocked awaiting
17691769
// monitor update
17701770
let chanmon_cfgs = create_chanmon_cfgs(4);
17711771
let node_cfgs = create_node_cfgs(4, &chanmon_cfgs);
@@ -1780,6 +1780,8 @@ fn test_path_paused_mpp() {
17801780
let (payment_preimage, payment_hash) = get_payment_preimage_hash!(&nodes[0]);
17811781
let payment_secret = PaymentSecret([0xdb; 32]);
17821782
let mut route = nodes[0].router.get_route(&nodes[3].node.get_our_node_id(), None, &[], 100000, TEST_FINAL_CLTV).unwrap();
1783+
1784+
// Set us up to take multiple routes, one 0 -> 1 -> 3 and one 0 -> 2 -> 3:
17831785
let path = route.paths[0].clone();
17841786
route.paths.push(path);
17851787
route.paths[0][0].pubkey = nodes[1].node.get_our_node_id();
@@ -1789,21 +1791,29 @@ fn test_path_paused_mpp() {
17891791
route.paths[1][0].short_channel_id = chan_2_ann.contents.short_channel_id;
17901792
route.paths[1][1].short_channel_id = chan_4_id;
17911793

1794+
// Set it so that the first monitor update (for the path 0 -> 1 -> 3) succeeds, but the second
1795+
// (for the path 0 -> 2 -> 3) fails.
17921796
*nodes[0].chan_monitor.update_ret.lock().unwrap() = Ok(());
17931797
*nodes[0].chan_monitor.next_update_ret.lock().unwrap() = Some(Err(ChannelMonitorUpdateErr::TemporaryFailure));
17941798

1795-
if let Err(PaymentSendFailure::PartialFailure(fails)) = nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret)) {
1796-
assert_eq!(fails.len(), 2);
1797-
if let Ok(()) = fails[0] {} else { panic!(); }
1798-
if let Err(APIError::MonitorUpdateFailed) = fails[1] {} else { panic!(); }
1799+
// Now check that we get the right return value, indicating that the first path succeeded but
1800+
// the second got a MonitorUpdateFailed err. This implies PaymentSendFailure::PartialFailure as
1801+
// some paths succeeded, preventing retry.
1802+
if let Err(PaymentSendFailure::PartialFailure(results)) = nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret)) {
1803+
assert_eq!(results.len(), 2);
1804+
if let Ok(()) = results[0] {} else { panic!(); }
1805+
if let Err(APIError::MonitorUpdateFailed) = results[1] {} else { panic!(); }
17991806
} else { panic!(); }
18001807
check_added_monitors!(nodes[0], 2);
18011808
*nodes[0].chan_monitor.update_ret.lock().unwrap() = Ok(());
18021809

1810+
// Pass the first HTLC of the payment along to nodes[3].
18031811
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
18041812
assert_eq!(events.len(), 1);
18051813
pass_along_path(&nodes[0], &[&nodes[1], &nodes[3]], 0, payment_hash.clone(), Some(payment_secret), events.pop().unwrap(), false);
18061814

1815+
// And check that, after we successfully update the monitor for chan_2 we can pass the second
1816+
// HTLC along to nodes[3] and claim the whole payment back to nodes[0].
18071817
let (outpoint, latest_update) = nodes[0].chan_monitor.latest_monitor_update_id.lock().unwrap().get(&chan_2_id).unwrap().clone();
18081818
nodes[0].node.channel_monitor_updated(&outpoint, latest_update);
18091819
let mut events = nodes[0].node.get_and_clear_pending_msg_events();

0 commit comments

Comments
 (0)