@@ -480,7 +480,7 @@ mod state_flags {
480480 pub const REMOTE_STFU_SENT: u32 = 1 << 16;
481481 pub const QUIESCENT: u32 = 1 << 17;
482482 pub const INTERACTIVE_SIGNING: u32 = 1 << 18;
483- pub const OUR_TX_SIGNATURES_SENT : u32 = 1 << 19;
483+ pub const OUR_TX_SIGNATURES_READY : u32 = 1 << 19;
484484 pub const THEIR_TX_SIGNATURES_SENT: u32 = 1 << 20;
485485}
486486
@@ -523,9 +523,9 @@ define_state_flags!(
523523 ("Indicates they sent us a `tx_signatures` message.",
524524 THEIR_TX_SIGNATURES_SENT, state_flags::THEIR_TX_SIGNATURES_SENT,
525525 is_their_tx_signatures_sent, set_their_tx_signatures_sent, clear_their_tx_signatures_sent),
526- ("Indicates we sent them a `tx_signatures` message.",
527- OUR_TX_SIGNATURES_SENT , state_flags::OUR_TX_SIGNATURES_SENT ,
528- is_our_tx_signatures_sent, set_our_tx_signatures_sent, clear_our_tx_signatures_sent )
526+ ("Indicates we are ready to send them a `tx_signatures` message and it has been queued to send .",
527+ OUR_TX_SIGNATURES_READY , state_flags::OUR_TX_SIGNATURES_READY ,
528+ is_our_tx_signatures_ready, set_our_tx_signatures_ready, clear_our_tx_signatures_ready )
529529 ]
530530);
531531
@@ -675,7 +675,11 @@ impl ChannelState {
675675 }
676676
677677 fn is_pre_funded_state(&self) -> bool {
678- matches!(self, ChannelState::NegotiatingFunding(_)|ChannelState::FundingNegotiated(_))
678+ match self {
679+ ChannelState::NegotiatingFunding(_) => true,
680+ ChannelState::FundingNegotiated(flags) if !flags.is_their_tx_signatures_sent() && !flags.is_our_tx_signatures_ready() => true,
681+ _ => false,
682+ }
679683 }
680684
681685 fn is_both_sides_shutdown(&self) -> bool {
@@ -710,7 +714,7 @@ impl ChannelState {
710714 impl_state_flag!(is_local_shutdown_sent, set_local_shutdown_sent, clear_local_shutdown_sent, FUNDED_STATES);
711715 impl_state_flag!(is_remote_shutdown_sent, set_remote_shutdown_sent, clear_remote_shutdown_sent, FUNDED_STATES);
712716 impl_state_flag!(is_interactive_signing, set_interactive_signing, clear_interactive_signing, FundingNegotiated);
713- impl_state_flag!(is_our_tx_signatures_sent, set_our_tx_signatures_sent, clear_our_tx_signatures_sent , FundingNegotiated);
717+ impl_state_flag!(is_our_tx_signatures_ready, set_our_tx_signatures_ready, clear_our_tx_signatures_ready , FundingNegotiated);
714718 impl_state_flag!(is_their_tx_signatures_sent, set_their_tx_signatures_sent, clear_their_tx_signatures_sent, FundingNegotiated);
715719 impl_state_flag!(is_our_channel_ready, set_our_channel_ready, clear_our_channel_ready, AwaitingChannelReady);
716720 impl_state_flag!(is_their_channel_ready, set_their_channel_ready, clear_their_channel_ready, AwaitingChannelReady);
@@ -2337,10 +2341,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
23372341 self.context.assert_no_commitment_advancement(transaction_number, "initial commitment_signed");
23382342 let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger);
23392343 let commitment_signed = match commitment_signed {
2340- Ok(commitment_signed) => {
2341- self.funding.funding_transaction = Some(signing_session.unsigned_tx().build_unsigned_tx());
2342- commitment_signed
2343- },
2344+ Ok(commitment_signed) => commitment_signed,
23442345 Err(err) => {
23452346 self.funding.channel_transaction_parameters.funding_outpoint = None;
23462347 return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) })));
@@ -5449,6 +5450,8 @@ impl<SP: Deref> FundedChannel<SP> where
54495450
54505451 self.context.counterparty_prev_commitment_point = self.context.counterparty_cur_commitment_point;
54515452 self.context.counterparty_cur_commitment_point = Some(msg.next_per_commitment_point);
5453+ // Clear any interactive signing session.
5454+ self.interactive_tx_signing_session = None;
54525455
54535456 log_info!(logger, "Received channel_ready from peer for channel {}", &self.context.channel_id());
54545457
@@ -6300,10 +6303,8 @@ impl<SP: Deref> FundedChannel<SP> where
63006303 self.context.channel_state.set_their_tx_signatures_sent();
63016304
63026305 if funding_tx_opt.is_some() {
6303- // We have a finalized funding transaction, so we can set the funding transaction and reset the
6304- // signing session fields.
6306+ // We have a finalized funding transaction, so we can set the funding transaction.
63056307 self.funding.funding_transaction = funding_tx_opt.clone();
6306- self.interactive_tx_signing_session = None;
63076308 }
63086309
63096310 if holder_tx_signatures_opt.is_some() && self.is_awaiting_initial_mon_persist() {
@@ -6313,7 +6314,7 @@ impl<SP: Deref> FundedChannel<SP> where
63136314 }
63146315
63156316 if holder_tx_signatures_opt.is_some() {
6316- self.context.channel_state.set_our_tx_signatures_sent ();
6317+ self.context.channel_state.set_our_tx_signatures_ready ();
63176318 }
63186319
63196320 self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
@@ -6579,7 +6580,7 @@ impl<SP: Deref> FundedChannel<SP> where
65796580 // transaction and waits for us to do it).
65806581 let tx_signatures = self.context.monitor_pending_tx_signatures.take();
65816582 if tx_signatures.is_some() {
6582- self.context.channel_state.set_our_tx_signatures_sent ();
6583+ self.context.channel_state.set_our_tx_signatures_ready ();
65836584 }
65846585
65856586 if self.context.channel_state.is_peer_disconnected() {
@@ -7102,7 +7103,7 @@ impl<SP: Deref> FundedChannel<SP> where
71027103 (None, None, Some(msgs::TxAbort { channel_id: self.context.channel_id(), data: vec![] }))
71037104 }
71047105 } else {
7105- return Err(ChannelError::Warn("No active signing session. The associated funding transaction may have already been broadcast. ".into()));
7106+ return Err(ChannelError::close("Counterparty set `next_funding_txid` at incorrect state ".into()));
71067107 }
71077108 } else {
71087109 // Don't send anything related to interactive signing if `next_funding_txid` is not set.
0 commit comments