@@ -1694,10 +1694,17 @@ where
1694
1694
},
1695
1695
ChannelPhase::Funded(funded_channel) => {
1696
1696
funded_channel.context.channel_state.clear_quiescent();
1697
- funded_channel
1698
- .pending_splice
1699
- .as_mut()
1700
- .and_then(|pending_splice| pending_splice.funding_negotiation.take());
1697
+ if funded_channel.should_reset_pending_splice_funding_negotiation() {
1698
+ funded_channel
1699
+ .pending_splice
1700
+ .as_mut()
1701
+ .and_then(|pending_splice| pending_splice.funding_negotiation.take());
1702
+ } else {
1703
+ debug_assert!(false);
1704
+ }
1705
+ if funded_channel.should_reset_pending_splice_state() {
1706
+ funded_channel.pending_splice.take();
1707
+ }
1701
1708
},
1702
1709
};
1703
1710
@@ -1826,11 +1833,18 @@ where
1826
1833
},
1827
1834
ChannelPhase::Funded(funded_channel) => {
1828
1835
funded_channel.context.channel_state.clear_quiescent();
1829
- funded_channel
1830
- .pending_splice
1831
- .as_mut()
1832
- .and_then(|pending_splice| pending_splice.funding_negotiation.take())
1833
- .is_some()
1836
+ let has_funding_negotiation =
1837
+ funded_channel.should_reset_pending_splice_funding_negotiation();
1838
+ if has_funding_negotiation {
1839
+ funded_channel
1840
+ .pending_splice
1841
+ .as_mut()
1842
+ .and_then(|pending_splice| pending_splice.funding_negotiation.take());
1843
+ }
1844
+ if funded_channel.should_reset_pending_splice_state() {
1845
+ funded_channel.pending_splice.take();
1846
+ }
1847
+ has_funding_negotiation
1834
1848
},
1835
1849
};
1836
1850
@@ -2549,6 +2563,15 @@ impl FundingNegotiation {
2549
2563
}
2550
2564
2551
2565
impl PendingFunding {
2566
+ fn can_abandon_funding_negotiation(&self) -> bool {
2567
+ self.funding_negotiation
2568
+ .as_ref()
2569
+ .map(|funding_negotiation| {
2570
+ !matches!(funding_negotiation, FundingNegotiation::AwaitingSignatures { .. })
2571
+ })
2572
+ .unwrap_or(true)
2573
+ }
2574
+
2552
2575
fn check_get_splice_locked<SP: Deref>(
2553
2576
&mut self, context: &ChannelContext<SP>, confirmed_funding_index: usize, height: u32,
2554
2577
) -> Option<msgs::SpliceLocked>
@@ -6734,6 +6757,33 @@ where
6734
6757
)
6735
6758
}
6736
6759
6760
+ fn should_reset_pending_splice_funding_negotiation(&self) -> bool {
6761
+ self.pending_splice
6762
+ .as_ref()
6763
+ .map(|pending_splice| {
6764
+ if pending_splice.can_abandon_funding_negotiation() {
6765
+ true
6766
+ } else {
6767
+ self.context
6768
+ .interactive_tx_signing_session
6769
+ .as_ref()
6770
+ .map(|signing_session| {
6771
+ signing_session.holder_tx_signatures().is_some()
6772
+ || signing_session.has_received_tx_signatures()
6773
+ })
6774
+ .unwrap_or_else(|| {
6775
+ debug_assert!(false);
6776
+ false
6777
+ })
6778
+ }
6779
+ })
6780
+ .unwrap_or(false)
6781
+ }
6782
+
6783
+ fn should_reset_pending_splice_state(&self) -> bool {
6784
+ self.should_reset_pending_splice_funding_negotiation() && self.pending_funding().is_empty()
6785
+ }
6786
+
6737
6787
#[rustfmt::skip]
6738
6788
fn check_remote_fee<F: Deref, L: Deref>(
6739
6789
channel_type: &ChannelTypeFeatures, fee_estimator: &LowerBoundedFeeEstimator<F>,
@@ -8862,6 +8912,15 @@ where
8862
8912
self.context.channel_state.clear_quiescent();
8863
8913
}
8864
8914
8915
+ if self.should_reset_pending_splice_funding_negotiation() {
8916
+ self.pending_splice
8917
+ .as_mut()
8918
+ .and_then(|pending_splice| pending_splice.funding_negotiation.take());
8919
+ }
8920
+ if self.should_reset_pending_splice_state() {
8921
+ self.pending_splice.take();
8922
+ }
8923
+
8865
8924
self.context.channel_state.set_peer_disconnected();
8866
8925
log_trace!(logger, "Peer disconnection resulted in {} remote-announced HTLC drops on channel {}", inbound_drop_count, &self.context.channel_id());
8867
8926
Ok(())
@@ -14233,6 +14292,14 @@ where
14233
14292
let holder_commitment_point_next = self.holder_commitment_point.next_point();
14234
14293
let holder_commitment_point_pending_next = self.holder_commitment_point.pending_next_point;
14235
14294
14295
+ let pending_splice = if self.should_reset_pending_splice_state() {
14296
+ None
14297
+ } else {
14298
+ // We don't have to worry about resetting the pending `FundingNegotiation` because we
14299
+ // can only read `FundingNegotiation::AwaitingSignatures` variants anyway.
14300
+ self.pending_splice.as_ref()
14301
+ };
14302
+
14236
14303
write_tlv_fields!(writer, {
14237
14304
(0, self.context.announcement_sigs, option),
14238
14305
// minimum_depth and counterparty_selected_channel_reserve_satoshis used to have a
@@ -14281,7 +14348,7 @@ where
14281
14348
(60, self.context.historical_scids, optional_vec), // Added in 0.2
14282
14349
(61, fulfill_attribution_data, optional_vec), // Added in 0.2
14283
14350
(63, holder_commitment_point_current, option), // Added in 0.2
14284
- (64, self. pending_splice, option), // Added in 0.2
14351
+ (64, pending_splice, option), // Added in 0.2
14285
14352
(65, self.quiescent_action, option), // Added in 0.2
14286
14353
(67, pending_outbound_held_htlc_flags, optional_vec), // Added in 0.2
14287
14354
(69, holding_cell_held_htlc_flags, optional_vec), // Added in 0.2
@@ -14945,6 +15012,15 @@ where
14945
15012
}
14946
15013
};
14947
15014
15015
+ if let Some(funding_negotiation) = pending_splice
15016
+ .as_ref()
15017
+ .and_then(|pending_splice| pending_splice.funding_negotiation.as_ref())
15018
+ {
15019
+ if !matches!(funding_negotiation, FundingNegotiation::AwaitingSignatures { .. }) {
15020
+ return Err(DecodeError::InvalidValue);
15021
+ }
15022
+ }
15023
+
14948
15024
Ok(FundedChannel {
14949
15025
funding: FundingScope {
14950
15026
value_to_self_msat,
0 commit comments