Skip to content

Commit 2e9bceb

Browse files
committed
f - don't set shutdown state if waiting on signature
1 parent fa6de18 commit 2e9bceb

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

lightning/src/ln/channel.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6168,13 +6168,8 @@ impl<SP: Deref> Channel<SP> where
61686168
-> Result<(Option<msgs::ClosingSigned>, Option<Transaction>, Option<ShutdownResult>), ChannelError>
61696169
where F::Target: FeeEstimator, L::Target: Logger
61706170
{
6171-
if matches!(self.context.channel_state, ChannelState::ShutdownComplete) {
6172-
// During async signing, we may need to keep the channel around
6173-
// even after it's been fully closed, so that we can construct
6174-
// and sign the final transaction to send back to the peer.
6175-
// If they send us another closing_signed, we should act as
6176-
// if the channel has already been fully closed.
6177-
return Err(ChannelError::Warn(String::from("Remote end sent us a closing_signed after shutdown complete")));
6171+
if self.is_shutdown_pending_signature() {
6172+
return Err(ChannelError::Warn(String::from("Remote end sent us a closing_signed while fully shutdown and just waiting on the final closing signature")));
61786173
}
61796174
if !self.context.channel_state.is_both_sides_shutdown() {
61806175
return Err(ChannelError::close("Remote end sent us a closing_signed before both sides provided a shutdown".to_owned()));
@@ -6277,7 +6272,9 @@ impl<SP: Deref> Channel<SP> where
62776272
unbroadcasted_funding_tx: self.context.unbroadcasted_funding(),
62786273
channel_funding_txo: self.context.get_funding_txo(),
62796274
};
6280-
self.context.channel_state = ChannelState::ShutdownComplete;
6275+
if closing_signed.is_some() {
6276+
self.context.channel_state = ChannelState::ShutdownComplete;
6277+
}
62816278
self.context.update_time_counter += 1;
62826279
self.context.last_received_closing_sig = Some(msg.signature.clone());
62836280
let tx = closing_signed.as_ref().map(|ClosingSigned { signature, .. }|
@@ -6640,6 +6637,12 @@ impl<SP: Deref> Channel<SP> where
66406637
matches!(self.context.channel_state, ChannelState::ShutdownComplete)
66416638
}
66426639

6640+
pub fn is_shutdown_pending_signature(&self) -> bool {
6641+
matches!(self.context.channel_state, ChannelState::ChannelReady(_))
6642+
&& self.context.signer_pending_closing
6643+
&& self.context.last_received_closing_sig.is_some()
6644+
}
6645+
66436646
pub fn channel_update_status(&self) -> ChannelUpdateStatus {
66446647
self.context.channel_update_status
66456648
}

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7795,7 +7795,7 @@ where
77957795
if let ChannelPhase::Funded(chan) = chan_phase_entry.get_mut() {
77967796
let logger = WithChannelContext::from(&self.logger, &chan.context, None);
77977797
let (closing_signed, tx, shutdown_result) = try_chan_phase_entry!(self, chan.closing_signed(&self.fee_estimator, &msg, &&logger), chan_phase_entry);
7798-
debug_assert_eq!(shutdown_result.is_some(), chan.is_shutdown());
7798+
debug_assert_eq!(shutdown_result.is_some(), chan.is_shutdown() || chan.is_shutdown_pending_signature());
77997799
if let Some(msg) = closing_signed {
78007800
peer_state.pending_msg_events.push(events::MessageSendEvent::SendClosingSigned {
78017801
node_id: counterparty_node_id.clone(),
@@ -8739,7 +8739,7 @@ where
87398739
});
87408740
}
87418741
if let Some(shutdown_result) = shutdown_result_opt {
8742-
debug_assert!(chan.is_shutdown());
8742+
debug_assert!(chan.is_shutdown() || chan.is_shutdown_pending_signature());
87438743
shutdown_results.push(shutdown_result);
87448744
}
87458745
if let Some(tx) = tx_opt {

0 commit comments

Comments
 (0)