Skip to content

Commit 6dd2155

Browse files
committed
test both with closed chan and not-closed chan
1 parent 95f61a7 commit 6dd2155

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

lightning/src/ln/chanmon_update_fail_tests.rs

+29-4
Original file line numberDiff line numberDiff line change
@@ -3402,8 +3402,7 @@ fn test_durable_preimages_on_closed_channel() {
34023402
do_test_durable_preimages_on_closed_channel(false, false, false);
34033403
}
34043404

3405-
#[test]
3406-
fn test_reload_mon_update_completion_actions() {
3405+
fn do_test_reload_mon_update_completion_actions(close_during_reload: bool) {
34073406
// Test that if a `ChannelMonitorUpdate` completes but a `ChannelManager` isn't serialized
34083407
// before restart we run the monitor update completion action on startup.
34093408
let chanmon_cfgs = create_chanmon_cfgs(3);
@@ -3462,12 +3461,32 @@ fn test_reload_mon_update_completion_actions() {
34623461
let manager_b = nodes[1].node.encode();
34633462
reload_node!(nodes[1], &manager_b, &[&mon_ab, &mon_bc], persister, new_chain_monitor, nodes_1_deserialized);
34643463

3464+
if close_during_reload {
3465+
// Test that we still free the B<->C channel if the A<->B channel closed while we reloaded
3466+
// (as learned about during the on-reload block connection).
3467+
nodes[0].node.force_close_broadcasting_latest_txn(&chan_id_ab, &nodes[1].node.get_our_node_id()).unwrap();
3468+
check_added_monitors!(nodes[0], 1);
3469+
check_closed_broadcast!(nodes[0], true);
3470+
check_closed_event(&nodes[0], 1, ClosureReason::HolderForceClosed, false);
3471+
let as_closing_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
3472+
mine_transaction_without_checks(&nodes[1], &as_closing_tx[0]);
3473+
}
3474+
34653475
let bc_update_id = nodes[1].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&chan_id_bc).unwrap().2;
3466-
expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], Some(1000), false, false);
3476+
let mut events = nodes[1].node.get_and_clear_pending_events();
3477+
assert_eq!(events.len(), if close_during_reload { 2 } else { 1 });
3478+
expect_payment_forwarded(events.pop().unwrap(), &nodes[1], &nodes[0], &nodes[2], Some(1000), close_during_reload, false);
3479+
if close_during_reload {
3480+
match events[0] {
3481+
Event::ChannelClosed { .. } => {},
3482+
_ => panic!(),
3483+
}
3484+
check_closed_broadcast!(nodes[1], true);
3485+
}
34673486

34683487
// Once we run event processing the monitor should free, check that it was indeed the B<->C
34693488
// channel which was updated.
3470-
check_added_monitors(&nodes[1], 1);
3489+
check_added_monitors(&nodes[1], if close_during_reload { 2 } else { 1 });
34713490
let post_ev_bc_update_id = nodes[1].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&chan_id_bc).unwrap().2;
34723491
assert!(bc_update_id != post_ev_bc_update_id);
34733492

@@ -3477,3 +3496,9 @@ fn test_reload_mon_update_completion_actions() {
34773496
reconnect_nodes(&nodes[1], &nodes[2], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
34783497
send_payment(&nodes[1], &[&nodes[2]], 100_000);
34793498
}
3499+
3500+
#[test]
3501+
fn test_reload_mon_update_completion_actions() {
3502+
do_test_reload_mon_update_completion_actions(true);
3503+
do_test_reload_mon_update_completion_actions(false);
3504+
}

0 commit comments

Comments
 (0)