Skip to content

Commit 759d7aa

Browse files
committed
Dont use is_pre_funded_state to short-circuit shutdown handling
`Channel::is_pre_funded_state` is used to mean several different things. In this case, its used to skip all the `shutdown` logic as the funding transaction can't possibly have been broadcasted so there's really no ned to try to sign a transaction spending it. Here, we really want to capture any channel in `NegotiatingFunding` or any V1 channel in `FundingNegotiated` or, finally, any V2 channel in `FundingNegotiated` where we haven't yet sent our signatures (which is not captured in `is_pre_funded_state`). Instead of a new helper, we just check the states directly in `shutdown` handling.
1 parent 1c36624 commit 759d7aa

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lightning/src/ln/channel.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9304,13 +9304,20 @@ where
93049304
"Peer sent shutdown when we needed a channel_reestablish".to_owned(),
93059305
));
93069306
}
9307-
if self.context.channel_state.is_pre_funded_state() {
9307+
let mut not_broadcasted =
9308+
matches!(self.context.channel_state, ChannelState::NegotiatingFunding(_));
9309+
if let ChannelState::FundingNegotiated(flags) = &self.context.channel_state {
9310+
if !flags.is_our_tx_signatures_ready() {
9311+
// If we're a V1 channel or we haven't yet sent our `tx_signatures`, the funding tx
9312+
// couldn't be broadcasted yet, so just short-circuit the shutdown logic.
9313+
not_broadcasted = true;
9314+
}
9315+
}
9316+
if not_broadcasted {
93089317
// Spec says we should fail the connection, not the channel, but that's nonsense, there
93099318
// are plenty of reasons you may want to fail a channel pre-funding, and spec says you
93109319
// can do that via error message without getting a connection fail anyway...
9311-
return Err(ChannelError::close(
9312-
"Peer sent shutdown pre-funding generation".to_owned(),
9313-
));
9320+
return Err(ChannelError::close("Shutdown before funding was broadcasted".to_owned()));
93149321
}
93159322
for htlc in self.context.pending_inbound_htlcs.iter() {
93169323
if let InboundHTLCState::RemoteAnnounced(_) = htlc.state {

0 commit comments

Comments
 (0)