Skip to content

Commit 2adb8ee

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 685b08d commit 2adb8ee

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lightning/src/ln/channel.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -5965,16 +5965,24 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
59655965
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()});
59665966
}
59675967

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

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

0 commit comments

Comments
 (0)