Skip to content

Commit 1b88f16

Browse files
committed
Add trivial test of monitor update failure during block connection
1 parent 9fe0cf1 commit 1b88f16

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lightning/src/chain/chainmonitor.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,4 +935,27 @@ mod tests {
935935
do_chainsync_pauses_events(false);
936936
do_chainsync_pauses_events(true);
937937
}
938+
939+
#[test]
940+
fn update_during_chainsync_fails_channel() {
941+
let chanmon_cfgs = create_chanmon_cfgs(2);
942+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
943+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
944+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
945+
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
946+
947+
chanmon_cfgs[0].persister.chain_sync_monitor_persistences.lock().unwrap().clear();
948+
chanmon_cfgs[0].persister.set_update_ret(Err(ChannelMonitorUpdateErr::PermanentFailure));
949+
950+
connect_blocks(&nodes[0], 1);
951+
// Before processing events, the ChannelManager will still think the Channel is open and
952+
// there won't be any ChannelMonitorUpdates
953+
assert_eq!(nodes[0].node.list_channels().len(), 1);
954+
check_added_monitors!(nodes[0], 0);
955+
// ... however once we get events once, the channel will close, creating a channel-closed
956+
// ChannelMonitorUpdate.
957+
check_closed_broadcast!(nodes[0], true);
958+
check_closed_event!(nodes[0], 1, ClosureReason::ProcessingError { err: "Failed to persist ChannelMonitor update during chain sync".to_string() });
959+
check_added_monitors!(nodes[0], 1);
960+
}
938961
}

0 commit comments

Comments
 (0)