Skip to content

Commit 44d5377

Browse files
committed
(XXX: doc for one thing) update test!
1 parent dec052c commit 44d5377

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3248,7 +3248,7 @@ fn test_inverted_mon_completion_order() {
32483248
do_test_inverted_mon_completion_order(false, false);
32493249
}
32503250

3251-
fn do_test_durable_preimages_on_closed_channel(close_chans_before_reload: bool, close_only_a: bool) {
3251+
fn do_test_durable_preimages_on_closed_channel(close_chans_before_reload: bool, close_only_a: bool, hold_post_reload_mon_update: bool) {
32523252
// Test that we can apply a `ChannelMonitorUpdate` with a payment preimage even if the channel
32533253
// is force-closed between when we generate the update on reload and when we go to handle the
32543254
// update or prior to generating the update at all.
@@ -3344,8 +3344,14 @@ fn do_test_durable_preimages_on_closed_channel(close_chans_before_reload: bool,
33443344
// After a timer tick a payment preimage ChannelMonitorUpdate is applied to the A<->B
33453345
// ChannelMonitor (possible twice), even though the channel has since been closed.
33463346
check_added_monitors(&nodes[1], 0);
3347+
let mons_added = if close_chans_before_reload { if !close_only_a { 4 } else { 3 } } else { 2 };
3348+
if hold_post_reload_mon_update {
3349+
for _ in 0..mons_added {
3350+
persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
3351+
}
3352+
}
33473353
nodes[1].node.timer_tick_occurred();
3348-
check_added_monitors(&nodes[1], if close_chans_before_reload { if !close_only_a { 4 } else { 3 } } else { 2 });
3354+
check_added_monitors(&nodes[1], mons_added);
33493355

33503356
// Finally, check that B created a payment preimage transaction and close out the payment.
33513357
let bs_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
@@ -3359,17 +3365,39 @@ fn do_test_durable_preimages_on_closed_channel(close_chans_before_reload: bool,
33593365
} else {
33603366
// While we forwarded the payment a while ago, we don't want to process events too early or
33613367
// we'll run background tasks we wanted to test individually.
3362-
expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], None, false, !close_only_a);
3368+
expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], None, true, !close_only_a);
33633369
}
33643370

33653371
mine_transactions(&nodes[0], &[&as_closing_tx[0], bs_preimage_tx]);
33663372
check_closed_broadcast(&nodes[0], 1, true);
33673373
expect_payment_sent(&nodes[0], payment_preimage, None, true, true);
3374+
3375+
if !close_chans_before_reload || close_only_a {
3376+
// Make sure the B<->C channel is still alive and well by sending a payment over it.
3377+
let have_mon = if close_only_a {
3378+
// XXX If
3379+
-1
3380+
} else { -2 };
3381+
reconnect_nodes(&nodes[1], &nodes[2], (false, false), (0, have_mon), (0, 0), (0, 0), (0, 0), (0, 0), (false, true));
3382+
let (outpoint, ab_update_id, _) = nodes[1].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&chan_id_ab).unwrap().clone();
3383+
nodes[1].chain_monitor.chain_monitor.force_channel_monitor_updated(outpoint, ab_update_id);
3384+
expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], Some(1000), true, false);
3385+
if !close_only_a {
3386+
// Once we call `process_pending_events` the final `ChannelMonitor` for the B<->C
3387+
// channel will fly, removing the payment preimage from it.
3388+
check_added_monitors(&nodes[1], 1);
3389+
}
3390+
assert!(nodes[1].node.get_and_clear_pending_events().is_empty());
3391+
send_payment(&nodes[1], &[&nodes[2]], 100_000);
3392+
}
33683393
}
33693394

33703395
#[test]
33713396
fn test_durable_preimages_on_closed_channel() {
3372-
do_test_durable_preimages_on_closed_channel(true, true);
3373-
do_test_durable_preimages_on_closed_channel(true, false);
3374-
do_test_durable_preimages_on_closed_channel(false, false);
3397+
do_test_durable_preimages_on_closed_channel(true, true, true);
3398+
do_test_durable_preimages_on_closed_channel(true, true, false);
3399+
do_test_durable_preimages_on_closed_channel(true, false, true);
3400+
do_test_durable_preimages_on_closed_channel(true, false, false);
3401+
do_test_durable_preimages_on_closed_channel(false, false, true);
3402+
do_test_durable_preimages_on_closed_channel(false, false, false);
33753403
}

0 commit comments

Comments
 (0)