@@ -699,9 +699,9 @@ enum ChannelState {
699
699
/// `AwaitingChannelReady`. Note that this is nonsense for an inbound channel as we immediately generate
700
700
/// `funding_signed` upon receipt of `funding_created`, so simply skip this state.
701
701
///
702
- /// For inbound and outbound interactively funded channels (dual-funding/splicing), this flag indicates
702
+ /// For inbound and outbound interactively funded channels (dual-funding/splicing), this state indicates
703
703
/// that interactive transaction construction has been completed and we are now interactively signing
704
- /// the funding/splice transaction.
704
+ /// the initial funding transaction.
705
705
FundingNegotiated(FundingNegotiatedFlags),
706
706
/// We've received/sent `funding_created` and `funding_signed` and are thus now waiting on the
707
707
/// funding transaction to confirm.
@@ -1913,6 +1913,14 @@ where
1913
1913
let logger = WithChannelContext::from(logger, self.context(), None);
1914
1914
match &mut self.phase {
1915
1915
ChannelPhase::UnfundedV2(chan) => {
1916
+ debug_assert_eq!(
1917
+ chan.context.channel_state,
1918
+ ChannelState::NegotiatingFunding(
1919
+ NegotiatingFundingFlags::OUR_INIT_SENT
1920
+ | NegotiatingFundingFlags::THEIR_INIT_SENT
1921
+ ),
1922
+ );
1923
+
1916
1924
let signing_session = chan
1917
1925
.interactive_tx_constructor
1918
1926
.take()
@@ -6068,7 +6076,6 @@ where
6068
6076
funding
6069
6077
.channel_transaction_parameters.funding_outpoint = Some(outpoint);
6070
6078
self.interactive_tx_signing_session = Some(signing_session);
6071
- self.channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
6072
6079
6073
6080
if is_splice {
6074
6081
debug_assert_eq!(
@@ -6079,6 +6086,7 @@ where
6079
6086
return Err(AbortReason::InternalError("Splicing not yet supported"));
6080
6087
} else {
6081
6088
self.assert_no_commitment_advancement(holder_commitment_transaction_number, "initial commitment_signed");
6089
+ self.channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
6082
6090
}
6083
6091
6084
6092
let commitment_signed = self.get_initial_commitment_signed_v2(&funding, logger);
@@ -6163,9 +6171,7 @@ where
6163
6171
SP::Target: SignerProvider,
6164
6172
L::Target: Logger,
6165
6173
{
6166
- assert!(
6167
- matches!(self.channel_state, ChannelState::FundingNegotiated(_) if self.interactive_tx_signing_session.is_some())
6168
- );
6174
+ debug_assert!(self.interactive_tx_signing_session.is_some());
6169
6175
6170
6176
let signature = self.get_initial_counterparty_commitment_signature(funding, logger);
6171
6177
if let Some(signature) = signature {
@@ -8538,6 +8544,27 @@ where
8538
8544
}
8539
8545
}
8540
8546
8547
+ fn on_tx_signatures_exchange(&mut self, funding_tx: Transaction) {
8548
+ debug_assert!(!self.context.channel_state.is_monitor_update_in_progress());
8549
+ debug_assert!(!self.context.channel_state.is_awaiting_remote_revoke());
8550
+
8551
+ if let Some(pending_splice) = self.pending_splice.as_mut() {
8552
+ if let Some(FundingNegotiation::AwaitingSignatures(mut funding)) =
8553
+ pending_splice.funding_negotiation.take()
8554
+ {
8555
+ funding.funding_transaction = Some(funding_tx);
8556
+ self.pending_funding.push(funding);
8557
+ } else {
8558
+ debug_assert!(false, "We checked we were in the right state above");
8559
+ }
8560
+ self.context.channel_state.clear_quiescent();
8561
+ } else {
8562
+ self.funding.funding_transaction = Some(funding_tx);
8563
+ self.context.channel_state =
8564
+ ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
8565
+ }
8566
+ }
8567
+
8541
8568
pub fn funding_transaction_signed(
8542
8569
&mut self, funding_txid_signed: Txid, witnesses: Vec<Witness>,
8543
8570
) -> Result<(Option<msgs::TxSignatures>, Option<Transaction>), APIError> {
@@ -8585,10 +8612,9 @@ where
8585
8612
.provide_holder_witnesses(tx_signatures, &self.context.secp_ctx)
8586
8613
.map_err(|err| APIError::APIMisuseError { err })?;
8587
8614
8588
- if funding_tx_opt.is_some() {
8589
- self.funding.funding_transaction = funding_tx_opt.clone();
8590
- self.context.channel_state =
8591
- ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
8615
+ if let Some(funding_tx) = funding_tx_opt.clone() {
8616
+ debug_assert!(tx_signatures_opt.is_some());
8617
+ self.on_tx_signatures_exchange(funding_tx);
8592
8618
}
8593
8619
8594
8620
Ok((tx_signatures_opt, funding_tx_opt))
@@ -8625,13 +8651,8 @@ where
8625
8651
let (holder_tx_signatures_opt, funding_tx_opt) = signing_session.received_tx_signatures(msg)
8626
8652
.map_err(|msg| ChannelError::Warn(msg))?;
8627
8653
8628
- if funding_tx_opt.is_some() {
8629
- // TODO(splicing): Transition back to `ChannelReady` and not `AwaitingChannelReady`
8630
- // We will also need to use the pending `FundingScope` in the splicing case.
8631
- //
8632
- // We have a finalized funding transaction, so we can set the funding transaction.
8633
- self.funding.funding_transaction = funding_tx_opt.clone();
8634
- self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
8654
+ if let Some(funding_tx) = funding_tx_opt.clone() {
8655
+ self.on_tx_signatures_exchange(funding_tx);
8635
8656
}
8636
8657
8637
8658
Ok((holder_tx_signatures_opt, funding_tx_opt))
0 commit comments