Skip to content

Commit 91537f1

Browse files
committed
f but still dont insert if the channel was never used
1 parent 0ad0d60 commit 91537f1

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

lightning/src/ln/channelmanager.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -12576,12 +12576,20 @@ where
1257612576
for (funding_txo, monitor) in args.channel_monitors.iter() {
1257712577
if !funding_txo_set.contains(funding_txo) {
1257812578
if let Some(counterparty_node_id) = monitor.get_counterparty_node_id() {
12579-
per_peer_state.entry(counterparty_node_id)
12580-
.or_insert_with(|| Mutex::new(empty_peer_state()))
12581-
.lock().unwrap()
12582-
.closed_channel_monitor_update_ids.entry(monitor.channel_id())
12583-
.and_modify(|v| *v = cmp::max(monitor.get_latest_update_id(), *v))
12584-
.or_insert(monitor.get_latest_update_id());
12579+
// If the ChannelMonitor had any updates, we may need to update it further and
12580+
// thus track it in `closed_channel_monitor_update_ids`. If the channel never
12581+
// had any updates at all, there can't be any HTLCs pending which we need to
12582+
// claim.
12583+
// Note that a `ChannelMonitor` is created with `update_id` 0 and after we
12584+
// provide it with a closure update its `update_id` will be at 1.
12585+
if !monitor.offchain_closed() || monitor.get_latest_update_id() > 1 {
12586+
per_peer_state.entry(counterparty_node_id)
12587+
.or_insert_with(|| Mutex::new(empty_peer_state()))
12588+
.lock().unwrap()
12589+
.closed_channel_monitor_update_ids.entry(monitor.channel_id())
12590+
.and_modify(|v| *v = cmp::max(monitor.get_latest_update_id(), *v))
12591+
.or_insert(monitor.get_latest_update_id());
12592+
}
1258512593
}
1258612594

1258712595
if monitor.offchain_closed() {

0 commit comments

Comments
 (0)