Skip to content

Commit 58b11bf

Browse files
committed
Add trivial test of monitor update failure during block connection
1 parent 17a1e20 commit 58b11bf

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lightning/src/chain/chainmonitor.rs

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

0 commit comments

Comments
 (0)