@@ -1694,8 +1694,7 @@ where
1694
1694
pending_v2_channel.interactive_tx_constructor.take();
1695
1695
},
1696
1696
ChannelPhase::Funded(funded_channel) => {
1697
- if funded_channel.should_reset_pending_splice_funding_negotiation().unwrap_or(true)
1698
- {
1697
+ if funded_channel.should_reset_pending_splice_state() {
1699
1698
funded_channel.reset_pending_splice_state();
1700
1699
} else {
1701
1700
debug_assert!(false, "We should never fail an interactive funding negotiation once we're exchanging tx_signatures");
@@ -1829,18 +1828,15 @@ where
1829
1828
pending_v2_channel.interactive_tx_constructor.take().is_some()
1830
1829
},
1831
1830
ChannelPhase::Funded(funded_channel) => {
1832
- if let Some(should_reset) =
1833
- funded_channel.should_reset_pending_splice_funding_negotiation()
1834
- {
1835
- if should_reset {
1836
- // We may have still tracked the pending funding negotiation state, so we
1837
- // should ack with our own `tx_abort`.
1838
- funded_channel.reset_pending_splice_state()
1839
- } else {
1840
- return Err(ChannelError::close(
1841
- "Received tx_abort while awaiting tx_signatures exchange".to_owned(),
1842
- ));
1843
- }
1831
+ if funded_channel.has_pending_splice_awaiting_signatures() {
1832
+ return Err(ChannelError::close(
1833
+ "Received tx_abort while awaiting tx_signatures exchange".to_owned(),
1834
+ ));
1835
+ }
1836
+ if funded_channel.should_reset_pending_splice_state() {
1837
+ let has_funding_negotiation = funded_channel.reset_pending_splice_state();
1838
+ debug_assert!(has_funding_negotiation);
1839
+ true
1844
1840
} else {
1845
1841
// We were not tracking the pending funding negotiation state anymore, likely
1846
1842
// due to a disconnection or already having sent our own `tx_abort`.
@@ -2583,13 +2579,17 @@ impl FundingNegotiation {
2583
2579
}
2584
2580
2585
2581
impl PendingFunding {
2586
- fn can_abandon_funding_negotiation (&self) -> bool {
2582
+ fn can_abandon_state (&self) -> bool {
2587
2583
self.funding_negotiation
2588
2584
.as_ref()
2589
2585
.map(|funding_negotiation| {
2590
2586
!matches!(funding_negotiation, FundingNegotiation::AwaitingSignatures { .. })
2591
2587
})
2592
- .unwrap_or(true)
2588
+ .unwrap_or_else(|| {
2589
+ let has_negotiated_candidates = !self.negotiated_candidates.is_empty();
2590
+ debug_assert!(has_negotiated_candidates);
2591
+ !has_negotiated_candidates
2592
+ })
2593
2593
}
2594
2594
2595
2595
fn check_get_splice_locked<SP: Deref>(
@@ -6773,40 +6773,35 @@ where
6773
6773
)
6774
6774
}
6775
6775
6776
- /// Returns `None` if there is no [`FundedChannel::pending_splice`], otherwise a boolean
6777
- /// indicating whether we should reset the splice's [`PendingFunding::funding_negotiation`].
6778
- fn should_reset_pending_splice_funding_negotiation(&self) -> Option<bool> {
6779
- self.pending_splice.as_ref().map(|pending_splice| {
6780
- if pending_splice.can_abandon_funding_negotiation() {
6781
- true
6782
- } else {
6783
- self.context
6784
- .interactive_tx_signing_session
6785
- .as_ref()
6786
- .map(|signing_session| !signing_session.has_received_commitment_signed())
6787
- .unwrap_or_else(|| {
6788
- debug_assert!(false);
6789
- false
6790
- })
6791
- }
6792
- })
6776
+ fn has_pending_splice_awaiting_signatures(&self) -> bool {
6777
+ self.pending_splice
6778
+ .as_ref()
6779
+ .and_then(|pending_splice| pending_splice.funding_negotiation.as_ref())
6780
+ .map(|funding_negotiation| {
6781
+ matches!(funding_negotiation, FundingNegotiation::AwaitingSignatures { .. })
6782
+ })
6783
+ .unwrap_or(false)
6793
6784
}
6794
6785
6786
+ /// Returns a boolean indicating whether we should reset the splice's
6787
+ /// [`PendingFunding::funding_negotiation`].
6795
6788
fn should_reset_pending_splice_state(&self) -> bool {
6796
- self.should_reset_pending_splice_funding_negotiation().unwrap_or(true)
6797
- && self.pending_funding().is_empty()
6789
+ self.pending_splice
6790
+ .as_ref()
6791
+ .map(|pending_splice| pending_splice.can_abandon_state())
6792
+ .unwrap_or(false)
6798
6793
}
6799
6794
6800
6795
fn reset_pending_splice_state(&mut self) -> bool {
6801
- debug_assert!(self.should_reset_pending_splice_funding_negotiation().unwrap_or(true));
6796
+ debug_assert!(self.should_reset_pending_splice_state());
6797
+ debug_assert!(self.context.interactive_tx_signing_session.is_none());
6802
6798
self.context.channel_state.clear_quiescent();
6803
- self.context.interactive_tx_signing_session.take();
6804
6799
let has_funding_negotiation = self
6805
6800
.pending_splice
6806
6801
.as_mut()
6807
6802
.and_then(|pending_splice| pending_splice.funding_negotiation.take())
6808
6803
.is_some();
6809
- if self.should_reset_pending_splice_state () {
6804
+ if self.pending_funding().is_empty () {
6810
6805
self.pending_splice.take();
6811
6806
}
6812
6807
has_funding_negotiation
@@ -8678,8 +8673,19 @@ where
8678
8673
.unwrap_or(false));
8679
8674
}
8680
8675
8676
+ if signing_session.holder_tx_signatures().is_some() {
8677
+ // Our `tx_signatures` either should've been the first time we processed them,
8678
+ // or we're waiting for our counterparty to send theirs first.
8679
+ return Ok((None, None));
8680
+ }
8681
+
8681
8682
signing_session
8682
8683
} else {
8684
+ if Some(funding_txid_signed) == self.funding.get_funding_txid() {
8685
+ // We may be handling a duplicate call and the funding was already locked so we
8686
+ // no longer have the signing session present.
8687
+ return Ok((None, None));
8688
+ }
8683
8689
let err =
8684
8690
format!("Channel {} not expecting funding signatures", self.context.channel_id);
8685
8691
return Err(APIError::APIMisuseError { err });
@@ -8937,13 +8943,16 @@ where
8937
8943
}
8938
8944
self.context.channel_state.clear_local_stfu_sent();
8939
8945
self.context.channel_state.clear_remote_stfu_sent();
8940
- if self.should_reset_pending_splice_funding_negotiation().unwrap_or(true) {
8941
- // If we were in quiescence but a splice was never negotiated, or the negotiation
8942
- // failed due to disconnecting, we shouldn't be quiescent anymore upon reconnecting.
8943
- // If there was a pending splice negotiation that has failed due to disconnecting,
8944
- // we also take the opportunity to clean up our state.
8946
+ if self.should_reset_pending_splice_state() {
8947
+ // If there was a pending splice negotiation that failed due to disconnecting, we
8948
+ // also take the opportunity to clean up our state.
8945
8949
self.reset_pending_splice_state();
8946
8950
debug_assert!(!self.context.channel_state.is_quiescent());
8951
+ } else if !self.has_pending_splice_awaiting_signatures() {
8952
+ // We shouldn't be quiescent anymore upon reconnecting if:
8953
+ // - We were in quiescence but a splice/RBF was never negotiated or
8954
+ // - We were in quiescence but the splice negotiation failed due to disconnecting
8955
+ self.context.channel_state.clear_quiescent();
8947
8956
}
8948
8957
}
8949
8958
@@ -9682,12 +9691,18 @@ where
9682
9691
9683
9692
// A node:
9684
9693
// - if `next_commitment_number` is 1 in both the `channel_reestablish` it
9685
- // sent and received:
9694
+ // sent and received, and none of those `channel_reestablish` messages
9695
+ // contain `my_current_funding_locked` or `next_funding` for a splice transaction:
9686
9696
// - MUST retransmit `channel_ready`.
9687
9697
// - otherwise:
9688
9698
// - MUST NOT retransmit `channel_ready`, but MAY send `channel_ready` with
9689
9699
// a different `short_channel_id` `alias` field.
9690
- let channel_ready = if msg.next_local_commitment_number == 1 && INITIAL_COMMITMENT_NUMBER - self.holder_commitment_point.next_transaction_number() == 1 {
9700
+ let both_sides_on_initial_commitment_number = msg.next_local_commitment_number == 1
9701
+ && INITIAL_COMMITMENT_NUMBER - self.holder_commitment_point.next_transaction_number() == 1;
9702
+ let channel_ready = if both_sides_on_initial_commitment_number
9703
+ && self.pending_splice.is_none()
9704
+ && self.funding.channel_transaction_parameters.splice_parent_funding_txid.is_none()
9705
+ {
9691
9706
// We should never have to worry about MonitorUpdateInProgress resending ChannelReady
9692
9707
self.get_channel_ready(logger)
9693
9708
} else { None };
@@ -13976,10 +13991,13 @@ where
13976
13991
}
13977
13992
channel_state.clear_local_stfu_sent();
13978
13993
channel_state.clear_remote_stfu_sent();
13979
- if self.should_reset_pending_splice_funding_negotiation().unwrap_or(true) {
13980
- // If we were in quiescence but a splice was never negotiated, or the
13981
- // negotiation failed due to disconnecting, we shouldn't be quiescent
13982
- // anymore upon reconnecting.
13994
+ if self.should_reset_pending_splice_state()
13995
+ || !self.has_pending_splice_awaiting_signatures()
13996
+ {
13997
+ // We shouldn't be quiescent anymore upon reconnecting if:
13998
+ // - We were in quiescence but a splice/RBF was never negotiated or
13999
+ // - We were in quiescence but the splice negotiation failed due to
14000
+ // disconnecting
13983
14001
channel_state.clear_quiescent();
13984
14002
}
13985
14003
},
@@ -14344,19 +14362,10 @@ where
14344
14362
let holder_commitment_point_next = self.holder_commitment_point.next_point();
14345
14363
let holder_commitment_point_pending_next = self.holder_commitment_point.pending_next_point;
14346
14364
14347
- let interactive_tx_signing_session =
14348
- if self.should_reset_pending_splice_funding_negotiation().unwrap_or(false) {
14349
- None
14350
- } else {
14351
- self.context.interactive_tx_signing_session.as_ref()
14352
- };
14353
- let pending_splice = if self.should_reset_pending_splice_state() {
14354
- None
14355
- } else {
14356
- // We don't have to worry about resetting the pending `FundingNegotiation` because we
14357
- // can only read `FundingNegotiation::AwaitingSignatures` variants anyway.
14358
- self.pending_splice.as_ref()
14359
- };
14365
+ // We don't have to worry about resetting the pending `FundingNegotiation` because we
14366
+ // can only read `FundingNegotiation::AwaitingSignatures` variants anyway.
14367
+ let pending_splice =
14368
+ self.pending_splice.as_ref().filter(|_| !self.should_reset_pending_splice_state());
14360
14369
14361
14370
write_tlv_fields!(writer, {
14362
14371
(0, self.context.announcement_sigs, option),
@@ -14401,7 +14410,7 @@ where
14401
14410
(53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
14402
14411
(55, removed_htlc_attribution_data, optional_vec), // Added in 0.2
14403
14412
(57, holding_cell_attribution_data, optional_vec), // Added in 0.2
14404
- (58, interactive_tx_signing_session, option), // Added in 0.2
14413
+ (58, self.context. interactive_tx_signing_session, option), // Added in 0.2
14405
14414
(59, self.funding.minimum_depth_override, option), // Added in 0.2
14406
14415
(60, self.context.historical_scids, optional_vec), // Added in 0.2
14407
14416
(61, fulfill_attribution_data, optional_vec), // Added in 0.2
0 commit comments