Skip to content

Commit b7ba29c

Browse files
committed
Don't use is_pre_funded_state to provide an FC monitor update
`Channel::is_pre_funded_state` is used to mean several different things. In this case its used to decide if we should provide a `ChannelMonitorUpdate` marking a channel as closed when we go to force-close it. Here, we want to capture exactly when the original `ChannelMonitor` is first created, but were doing so indirectly by looking at the channel's state. Worse, `is_pre_funded_state` got updated to be false whenever there is an interctive signing session, which isn't correct for this use - we may have an interactive signing session but have already persisted the original `ChannelMonitor` when we received the first `commitment_signed`. Instead, we just move to examining `counterparty_next_commitment_transaction_number` which is decrementing for the first time at exactly the time we create the original `ChannelMonitor`, so it provides a much simpler test. Fixes #3880
1 parent 759d7aa commit b7ba29c

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

lightning/src/ln/channel.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5496,15 +5496,14 @@ where
54965496
}
54975497

54985498
let monitor_update = if let Some(funding_txo) = funding.get_funding_txo() {
5499-
// If we haven't yet exchanged funding signatures (ie channel_state < AwaitingChannelReady),
5500-
// returning a channel monitor update here would imply a channel monitor update before
5501-
// we even registered the channel monitor to begin with, which is invalid.
5502-
// Thus, if we aren't actually at a point where we could conceivably broadcast the
5503-
// funding transaction, don't return a funding txo (which prevents providing the
5504-
// monitor update to the user, even if we return one).
5505-
// See test_duplicate_chan_id and test_pre_lockin_no_chan_closed_update for more.
5506-
if !self.channel_state.is_pre_funded_state() {
5499+
// We should only generate a closing `ChannelMonitorUpdate` if we already have a
5500+
// `ChannelMonitor` for the disk (i.e. `counterparty_next_commitment_transaction_number`
5501+
// has been decremented once, which hapens when we generate the initial
5502+
// `ChannelMonitor`). Otherwise, that would imply a channel monitor update before we
5503+
// even registered the channel monitor to begin with, which is invalid.
5504+
if self.counterparty_next_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER {
55075505
self.latest_monitor_update_id = self.get_latest_unblocked_monitor_update_id() + 1;
5506+
55085507
let update = ChannelMonitorUpdate {
55095508
update_id: self.latest_monitor_update_id,
55105509
updates: vec![ChannelMonitorUpdateStep::ChannelForceClosed {

0 commit comments

Comments
 (0)