@@ -718,9 +718,9 @@ enum ChannelState {
718
718
/// `AwaitingChannelReady`. Note that this is nonsense for an inbound channel as we immediately generate
719
719
/// `funding_signed` upon receipt of `funding_created`, so simply skip this state.
720
720
///
721
- /// For inbound and outbound interactively funded channels (dual-funding/splicing ), this flag indicates
722
- /// that interactive transaction construction has been completed and we are now interactively signing
723
- /// the funding/splice transaction.
721
+ /// For inbound and outbound interactively funded channels (dual-funding), this state indicates
722
+ /// that interactive transaction construction has been completed and we are now interactively
723
+ /// signing the initial funding transaction.
724
724
FundingNegotiated(FundingNegotiatedFlags),
725
725
/// We've received/sent `funding_created` and `funding_signed` and are thus now waiting on the
726
726
/// funding transaction to confirm.
@@ -1932,6 +1932,14 @@ where
1932
1932
let logger = WithChannelContext::from(logger, self.context(), None);
1933
1933
match &mut self.phase {
1934
1934
ChannelPhase::UnfundedV2(chan) => {
1935
+ debug_assert_eq!(
1936
+ chan.context.channel_state,
1937
+ ChannelState::NegotiatingFunding(
1938
+ NegotiatingFundingFlags::OUR_INIT_SENT
1939
+ | NegotiatingFundingFlags::THEIR_INIT_SENT
1940
+ ),
1941
+ );
1942
+
1935
1943
let signing_session = chan
1936
1944
.interactive_tx_constructor
1937
1945
.take()
@@ -6116,7 +6124,6 @@ where
6116
6124
funding
6117
6125
.channel_transaction_parameters.funding_outpoint = Some(outpoint);
6118
6126
self.interactive_tx_signing_session = Some(signing_session);
6119
- self.channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
6120
6127
6121
6128
if is_splice {
6122
6129
debug_assert_eq!(
@@ -6127,6 +6134,7 @@ where
6127
6134
return Err(AbortReason::InternalError("Splicing not yet supported"));
6128
6135
} else {
6129
6136
self.assert_no_commitment_advancement(holder_commitment_transaction_number, "initial commitment_signed");
6137
+ self.channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
6130
6138
}
6131
6139
6132
6140
let commitment_signed = self.get_initial_commitment_signed_v2(&funding, logger);
@@ -6211,9 +6219,7 @@ where
6211
6219
SP::Target: SignerProvider,
6212
6220
L::Target: Logger,
6213
6221
{
6214
- assert!(
6215
- matches!(self.channel_state, ChannelState::FundingNegotiated(_) if self.interactive_tx_signing_session.is_some())
6216
- );
6222
+ debug_assert!(self.interactive_tx_signing_session.is_some());
6217
6223
6218
6224
let signature = self.get_initial_counterparty_commitment_signature(funding, logger);
6219
6225
if let Some(signature) = signature {
@@ -8573,11 +8579,43 @@ where
8573
8579
}
8574
8580
}
8575
8581
8582
+ fn on_tx_signatures_exchange(&mut self, funding_tx: Transaction) {
8583
+ debug_assert!(!self.context.channel_state.is_monitor_update_in_progress());
8584
+ debug_assert!(!self.context.channel_state.is_awaiting_remote_revoke());
8585
+
8586
+ if let Some(pending_splice) = self.pending_splice.as_mut() {
8587
+ if let Some(FundingNegotiation::AwaitingSignatures { mut funding }) =
8588
+ pending_splice.funding_negotiation.take()
8589
+ {
8590
+ funding.funding_transaction = Some(funding_tx);
8591
+ pending_splice.negotiated_candidates.push(funding);
8592
+ } else {
8593
+ debug_assert!(false);
8594
+ }
8595
+ self.context.channel_state.clear_quiescent();
8596
+ } else {
8597
+ self.funding.funding_transaction = Some(funding_tx);
8598
+ self.context.channel_state =
8599
+ ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
8600
+ }
8601
+ }
8602
+
8576
8603
pub fn funding_transaction_signed(
8577
8604
&mut self, funding_txid_signed: Txid, witnesses: Vec<Witness>,
8578
8605
) -> Result<(Option<msgs::TxSignatures>, Option<Transaction>), APIError> {
8579
8606
let signing_session =
8580
8607
if let Some(signing_session) = self.context.interactive_tx_signing_session.as_mut() {
8608
+ if let Some(pending_splice) = self.pending_splice.as_ref() {
8609
+ debug_assert!(pending_splice
8610
+ .funding_negotiation
8611
+ .as_ref()
8612
+ .map(|funding_negotiation| matches!(
8613
+ funding_negotiation,
8614
+ FundingNegotiation::AwaitingSignatures { .. }
8615
+ ))
8616
+ .unwrap_or(false));
8617
+ }
8618
+
8581
8619
signing_session
8582
8620
} else {
8583
8621
let err =
@@ -8620,24 +8658,40 @@ where
8620
8658
.provide_holder_witnesses(tx_signatures, &self.context.secp_ctx)
8621
8659
.map_err(|err| APIError::APIMisuseError { err })?;
8622
8660
8623
- if funding_tx_opt.is_some() {
8624
- self.funding.funding_transaction = funding_tx_opt.clone();
8625
- self.context.channel_state =
8626
- ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
8661
+ if let Some(funding_tx) = funding_tx_opt.clone() {
8662
+ debug_assert!(tx_signatures_opt.is_some());
8663
+ self.on_tx_signatures_exchange(funding_tx);
8627
8664
}
8628
8665
8629
8666
Ok((tx_signatures_opt, funding_tx_opt))
8630
8667
}
8631
8668
8632
- #[rustfmt::skip]
8633
- pub fn tx_signatures(&mut self, msg: &msgs::TxSignatures) -> Result<(Option<msgs::TxSignatures>, Option<Transaction>), ChannelError> {
8634
- let signing_session = if let Some(signing_session) = self.context.interactive_tx_signing_session.as_mut() {
8669
+ pub fn tx_signatures(
8670
+ &mut self, msg: &msgs::TxSignatures,
8671
+ ) -> Result<(Option<msgs::TxSignatures>, Option<Transaction>), ChannelError> {
8672
+ let signing_session = if let Some(signing_session) =
8673
+ self.context.interactive_tx_signing_session.as_mut()
8674
+ {
8635
8675
if signing_session.has_received_tx_signatures() {
8636
8676
return Err(ChannelError::Ignore("Ignoring duplicate tx_signatures".to_owned()));
8637
8677
}
8638
8678
if !signing_session.has_received_commitment_signed() {
8639
- return Err(ChannelError::close("Received tx_signatures before initial commitment_signed".to_owned()));
8679
+ return Err(ChannelError::close(
8680
+ "Received tx_signatures before initial commitment_signed".to_owned(),
8681
+ ));
8682
+ }
8683
+
8684
+ if let Some(pending_splice) = self.pending_splice.as_ref() {
8685
+ debug_assert!(pending_splice
8686
+ .funding_negotiation
8687
+ .as_ref()
8688
+ .map(|funding_negotiation| matches!(
8689
+ funding_negotiation,
8690
+ FundingNegotiation::AwaitingSignatures { .. }
8691
+ ))
8692
+ .unwrap_or(false));
8640
8693
}
8694
+
8641
8695
signing_session
8642
8696
} else {
8643
8697
return Err(ChannelError::Ignore("Ignoring unexpected tx_signatures".to_owned()));
@@ -8657,16 +8711,11 @@ where
8657
8711
}
8658
8712
}
8659
8713
8660
- let (holder_tx_signatures_opt, funding_tx_opt) = signing_session.received_tx_signatures(msg)
8661
- .map_err(|msg| ChannelError::Warn(msg))?;
8714
+ let (holder_tx_signatures_opt, funding_tx_opt) =
8715
+ signing_session.received_tx_signatures(msg) .map_err(|msg| ChannelError::Warn(msg))?;
8662
8716
8663
- if funding_tx_opt.is_some() {
8664
- // TODO(splicing): Transition back to `ChannelReady` and not `AwaitingChannelReady`
8665
- // We will also need to use the pending `FundingScope` in the splicing case.
8666
- //
8667
- // We have a finalized funding transaction, so we can set the funding transaction.
8668
- self.funding.funding_transaction = funding_tx_opt.clone();
8669
- self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
8717
+ if let Some(funding_tx) = funding_tx_opt.clone() {
8718
+ self.on_tx_signatures_exchange(funding_tx);
8670
8719
}
8671
8720
8672
8721
Ok((holder_tx_signatures_opt, funding_tx_opt))
0 commit comments