Skip to content

Commit 98dbe43

Browse files
committed
test both with closed chan and not-closed chan
1 parent 18e1de2 commit 98dbe43

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

lightning/src/ln/chanmon_update_fail_tests.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3421,8 +3421,7 @@ fn test_durable_preimages_on_closed_channel() {
34213421
do_test_durable_preimages_on_closed_channel(false, false, false);
34223422
}
34233423

3424-
#[test]
3425-
fn test_reload_mon_update_completion_actions() {
3424+
fn do_test_reload_mon_update_completion_actions(close_during_reload: bool) {
34263425
// Test that if a `ChannelMonitorUpdate` completes but a `ChannelManager` isn't serialized
34273426
// before restart we run the monitor update completion action on startup.
34283427
let chanmon_cfgs = create_chanmon_cfgs(3);
@@ -3481,12 +3480,32 @@ fn test_reload_mon_update_completion_actions() {
34813480
let manager_b = nodes[1].node.encode();
34823481
reload_node!(nodes[1], &manager_b, &[&mon_ab, &mon_bc], persister, new_chain_monitor, nodes_1_deserialized);
34833482

3483+
if close_during_reload {
3484+
// Test that we still free the B<->C channel if the A<->B channel closed while we reloaded
3485+
// (as learned about during the on-reload block connection).
3486+
nodes[0].node.force_close_broadcasting_latest_txn(&chan_id_ab, &nodes[1].node.get_our_node_id()).unwrap();
3487+
check_added_monitors!(nodes[0], 1);
3488+
check_closed_broadcast!(nodes[0], true);
3489+
check_closed_event(&nodes[0], 1, ClosureReason::HolderForceClosed, false, &[nodes[1].node.get_our_node_id()], 100_000);
3490+
let as_closing_tx = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
3491+
mine_transaction_without_checks(&nodes[1], &as_closing_tx[0]);
3492+
}
3493+
34843494
let bc_update_id = nodes[1].chain_monitor.latest_monitor_update_id.lock().unwrap().get(&chan_id_bc).unwrap().2;
3485-
expect_payment_forwarded!(nodes[1], nodes[0], nodes[2], Some(1000), false, false);
3495+
let mut events = nodes[1].node.get_and_clear_pending_events();
3496+
assert_eq!(events.len(), if close_during_reload { 2 } else { 1 });
3497+
expect_payment_forwarded(events.pop().unwrap(), &nodes[1], &nodes[0], &nodes[2], Some(1000), close_during_reload, false);
3498+
if close_during_reload {
3499+
match events[0] {
3500+
Event::ChannelClosed { .. } => {},
3501+
_ => panic!(),
3502+
}
3503+
check_closed_broadcast!(nodes[1], true);
3504+
}
34863505

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

@@ -3496,3 +3515,9 @@ fn test_reload_mon_update_completion_actions() {
34963515
reconnect_nodes(ReconnectArgs::new(&nodes[1], &nodes[2]));
34973516
send_payment(&nodes[1], &[&nodes[2]], 100_000);
34983517
}
3518+
3519+
#[test]
3520+
fn test_reload_mon_update_completion_actions() {
3521+
do_test_reload_mon_update_completion_actions(true);
3522+
do_test_reload_mon_update_completion_actions(false);
3523+
}

0 commit comments

Comments
 (0)