@@ -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
@@ -8948,13 +8943,16 @@ where
8948
8943
}
8949
8944
self.context.channel_state.clear_local_stfu_sent();
8950
8945
self.context.channel_state.clear_remote_stfu_sent();
8951
- if self.should_reset_pending_splice_funding_negotiation().unwrap_or(true) {
8952
- // If we were in quiescence but a splice was never negotiated, or the negotiation
8953
- // failed due to disconnecting, we shouldn't be quiescent anymore upon reconnecting.
8954
- // If there was a pending splice negotiation that has failed due to disconnecting,
8955
- // 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.
8956
8949
self.reset_pending_splice_state();
8957
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();
8958
8956
}
8959
8957
}
8960
8958
@@ -13993,10 +13991,13 @@ where
13993
13991
}
13994
13992
channel_state.clear_local_stfu_sent();
13995
13993
channel_state.clear_remote_stfu_sent();
13996
- if self.should_reset_pending_splice_funding_negotiation().unwrap_or(true) {
13997
- // If we were in quiescence but a splice was never negotiated, or the
13998
- // negotiation failed due to disconnecting, we shouldn't be quiescent
13999
- // 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
14000
14001
channel_state.clear_quiescent();
14001
14002
}
14002
14003
},
@@ -14361,19 +14362,10 @@ where
14361
14362
let holder_commitment_point_next = self.holder_commitment_point.next_point();
14362
14363
let holder_commitment_point_pending_next = self.holder_commitment_point.pending_next_point;
14363
14364
14364
- let interactive_tx_signing_session =
14365
- if self.should_reset_pending_splice_funding_negotiation().unwrap_or(false) {
14366
- None
14367
- } else {
14368
- self.context.interactive_tx_signing_session.as_ref()
14369
- };
14370
- let pending_splice = if self.should_reset_pending_splice_state() {
14371
- None
14372
- } else {
14373
- // We don't have to worry about resetting the pending `FundingNegotiation` because we
14374
- // can only read `FundingNegotiation::AwaitingSignatures` variants anyway.
14375
- self.pending_splice.as_ref()
14376
- };
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());
14377
14369
14378
14370
write_tlv_fields!(writer, {
14379
14371
(0, self.context.announcement_sigs, option),
@@ -14418,7 +14410,7 @@ where
14418
14410
(53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
14419
14411
(55, removed_htlc_attribution_data, optional_vec), // Added in 0.2
14420
14412
(57, holding_cell_attribution_data, optional_vec), // Added in 0.2
14421
- (58, interactive_tx_signing_session, option), // Added in 0.2
14413
+ (58, self.context. interactive_tx_signing_session, option), // Added in 0.2
14422
14414
(59, self.funding.minimum_depth_override, option), // Added in 0.2
14423
14415
(60, self.context.historical_scids, optional_vec), // Added in 0.2
14424
14416
(61, fulfill_attribution_data, optional_vec), // Added in 0.2
0 commit comments