@@ -1937,6 +1937,18 @@ where
1937
1937
let logger = WithChannelContext::from(logger, self.context(), None);
1938
1938
match &mut self.phase {
1939
1939
ChannelPhase::UnfundedV2(chan) => {
1940
+ debug_assert_eq!(
1941
+ chan.context.channel_state,
1942
+ ChannelState::NegotiatingFunding(
1943
+ NegotiatingFundingFlags::OUR_INIT_SENT
1944
+ | NegotiatingFundingFlags::THEIR_INIT_SENT
1945
+ ),
1946
+ );
1947
+
1948
+ chan.context.channel_state =
1949
+ ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
1950
+ chan.context.channel_state.set_interactive_signing();
1951
+
1940
1952
let mut signing_session = chan
1941
1953
.interactive_tx_constructor
1942
1954
.take()
@@ -6000,9 +6012,6 @@ where
6000
6012
funding
6001
6013
.channel_transaction_parameters.funding_outpoint = Some(outpoint);
6002
6014
6003
- self.channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
6004
- self.channel_state.set_interactive_signing();
6005
-
6006
6015
if is_splice {
6007
6016
debug_assert_eq!(
6008
6017
holder_commitment_transaction_number,
@@ -6050,6 +6059,12 @@ where
6050
6059
SP::Target: SignerProvider,
6051
6060
L::Target: Logger,
6052
6061
{
6062
+ let is_quiescent = matches!(
6063
+ self.channel_state,
6064
+ ChannelState::ChannelReady(f) if f.is_set(ChannelReadyFlags::QUIESCENT)
6065
+ );
6066
+ debug_assert!(self.channel_state.is_interactive_signing() || is_quiescent);
6067
+
6053
6068
let mut commitment_number = self.counterparty_next_commitment_transaction_number;
6054
6069
let mut commitment_point = self.counterparty_next_commitment_point.unwrap();
6055
6070
@@ -6096,10 +6111,6 @@ where
6096
6111
SP::Target: SignerProvider,
6097
6112
L::Target: Logger,
6098
6113
{
6099
- assert!(
6100
- matches!(self.channel_state, ChannelState::FundingNegotiated(flags) if flags.is_interactive_signing())
6101
- );
6102
-
6103
6114
let signature = self.get_initial_counterparty_commitment_signature(funding, logger);
6104
6115
if let Some(signature) = signature {
6105
6116
log_info!(
@@ -6130,6 +6141,8 @@ where
6130
6141
SP::Target: SignerProvider,
6131
6142
L::Target: Logger,
6132
6143
{
6144
+ self.channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
6145
+ self.channel_state.set_interactive_signing();
6133
6146
self.counterparty_next_commitment_point = Some(counterparty_next_commitment_point_override);
6134
6147
self.get_initial_counterparty_commitment_signature(funding, logger)
6135
6148
}
@@ -8510,6 +8523,10 @@ where
8510
8523
format!("Channel {} not expecting funding signatures", self.context.channel_id);
8511
8524
return Err(APIError::APIMisuseError { err });
8512
8525
}
8526
+ debug_assert_eq!(
8527
+ self.has_pending_splice_awaiting_signatures(),
8528
+ matches!(self.context.channel_state, ChannelState::ChannelReady(f) if f.is_set(ChannelReadyFlags::QUIESCENT))
8529
+ );
8513
8530
8514
8531
let signing_session =
8515
8532
if let Some(signing_session) = self.interactive_tx_signing_session.as_mut() {
@@ -8560,9 +8577,25 @@ where
8560
8577
.map_err(|err| APIError::APIMisuseError { err })?;
8561
8578
8562
8579
if funding_tx_opt.is_some() {
8563
- self.funding.funding_transaction = funding_tx_opt.clone();
8564
- self.context.channel_state =
8565
- ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
8580
+ debug_assert!(tx_signatures_opt.is_some());
8581
+ debug_assert!(!self.context.channel_state.is_monitor_update_in_progress());
8582
+ debug_assert!(!self.context.channel_state.is_awaiting_remote_revoke());
8583
+
8584
+ if let Some(pending_splice) = self.pending_splice.as_mut() {
8585
+ if let Some(FundingNegotiation::AwaitingSignatures(mut funding)) =
8586
+ pending_splice.funding_negotiation.take()
8587
+ {
8588
+ funding.funding_transaction = funding_tx_opt.clone();
8589
+ self.pending_funding.push(funding);
8590
+ } else {
8591
+ debug_assert!(false, "We checked we were in the right state above");
8592
+ }
8593
+ self.context.channel_state.clear_quiescent();
8594
+ } else {
8595
+ self.funding.funding_transaction = funding_tx_opt.clone();
8596
+ self.context.channel_state =
8597
+ ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
8598
+ }
8566
8599
}
8567
8600
8568
8601
Ok((tx_signatures_opt, funding_tx_opt))
@@ -8575,6 +8608,10 @@ where
8575
8608
{
8576
8609
return Err(ChannelError::Ignore("Ignoring unexpected tx_signatures".to_owned()));
8577
8610
}
8611
+ debug_assert_eq!(
8612
+ self.has_pending_splice_awaiting_signatures(),
8613
+ matches!(self.context.channel_state, ChannelState::ChannelReady(f) if f.is_set(ChannelReadyFlags::QUIESCENT))
8614
+ );
8578
8615
8579
8616
let signing_session = if let Some(signing_session) = self.interactive_tx_signing_session.as_mut() {
8580
8617
if signing_session.has_received_tx_signatures() {
@@ -8607,12 +8644,24 @@ where
8607
8644
.map_err(|msg| ChannelError::Warn(msg))?;
8608
8645
8609
8646
if funding_tx_opt.is_some() {
8610
- // TODO(splicing): Transition back to `ChannelReady` and not `AwaitingChannelReady`
8611
- // We will also need to use the pending `FundingScope` in the splicing case.
8612
- //
8613
- // We have a finalized funding transaction, so we can set the funding transaction.
8614
- self.funding.funding_transaction = funding_tx_opt.clone();
8615
- self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
8647
+ debug_assert!(!self.context.channel_state.is_monitor_update_in_progress());
8648
+ debug_assert!(!self.context.channel_state.is_awaiting_remote_revoke());
8649
+
8650
+ if let Some(pending_splice) = self.pending_splice.as_mut() {
8651
+ if let Some(FundingNegotiation::AwaitingSignatures(mut funding)) =
8652
+ pending_splice.funding_negotiation.take()
8653
+ {
8654
+ funding.funding_transaction = funding_tx_opt.clone();
8655
+ self.pending_funding.push(funding);
8656
+ } else {
8657
+ debug_assert!(false, "We checked we were in the right state above");
8658
+ }
8659
+ self.context.channel_state.clear_quiescent();
8660
+ } else {
8661
+ self.funding.funding_transaction = funding_tx_opt.clone();
8662
+ self.context.channel_state =
8663
+ ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
8664
+ }
8616
8665
}
8617
8666
8618
8667
Ok((holder_tx_signatures_opt, funding_tx_opt))
0 commit comments