Skip to content

Commit 4e34ff1

Browse files
committed
Don't generate a ChannelMonitorUpdate for closed chans on shutdown
The `Channel::get_shutdown` docs are very clear - if the channel jumps to `Shutdown` as a result of not being funded when we go to initiate shutdown we should not generate a `ChannelMonitorUpdate` as there's no need to bother with the shutdown script - we're force-closing anyway. However, this wasn't actually implemented, potentially causing a spurious monitor update for no reason.
1 parent 87d5482 commit 4e34ff1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lightning/src/ln/channel.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5964,16 +5964,24 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
59645964
return Err(APIError::ChannelUnavailable{err: "Cannot begin shutdown while peer is disconnected or we're waiting on a monitor update, maybe force-close instead?".to_owned()});
59655965
}
59665966

5967+
// If we haven't funded the channel yet, we don't need to bother ensuring the shutdown
5968+
// script is set, we just force-close and call it a day.
5969+
let mut chan_closed = false;
5970+
if self.channel_state < ChannelState::FundingSent as u32 {
5971+
chan_closed = true;
5972+
}
5973+
59675974
let update_shutdown_script = match self.shutdown_scriptpubkey {
59685975
Some(_) => false,
5969-
None => {
5976+
None if !chan_closed => {
59705977
let shutdown_scriptpubkey = signer_provider.get_shutdown_scriptpubkey();
59715978
if !shutdown_scriptpubkey.is_compatible(their_features) {
59725979
return Err(APIError::IncompatibleShutdownScript { script: shutdown_scriptpubkey.clone() });
59735980
}
59745981
self.shutdown_scriptpubkey = Some(shutdown_scriptpubkey);
59755982
true
59765983
},
5984+
None => false,
59775985
};
59785986

59795987
// From here on out, we may not fail!

0 commit comments

Comments
 (0)