Skip to content

Commit ab63008

Browse files
committed
Add trivial test of monitor update failure during block connection
1 parent 8bdd2f2 commit ab63008

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

0 commit comments

Comments
 (0)