@@ -1654,7 +1654,7 @@ where
16541654 }
16551655 chan.context.channel_state.clear_local_stfu_sent();
16561656 chan.context.channel_state.clear_remote_stfu_sent();
1657- if chan.should_reset_pending_splice_state() {
1657+ if chan.should_reset_pending_splice_state(false ) {
16581658 // If there was a pending splice negotiation that failed due to disconnecting, we
16591659 // also take the opportunity to clean up our state.
16601660 let splice_funding_failed = chan.reset_pending_splice_state();
@@ -1775,7 +1775,7 @@ where
17751775 None
17761776 },
17771777 ChannelPhase::Funded(funded_channel) => {
1778- if funded_channel.should_reset_pending_splice_state() {
1778+ if funded_channel.should_reset_pending_splice_state(false ) {
17791779 funded_channel.reset_pending_splice_state()
17801780 } else {
17811781 debug_assert!(false, "We should never fail an interactive funding negotiation once we're exchanging tx_signatures");
@@ -1932,12 +1932,24 @@ where
19321932 (had_constructor, None)
19331933 },
19341934 ChannelPhase::Funded(funded_channel) => {
1935- if funded_channel.has_pending_splice_awaiting_signatures() {
1935+ if funded_channel.has_pending_splice_awaiting_signatures()
1936+ && funded_channel
1937+ .context()
1938+ .interactive_tx_signing_session
1939+ .as_ref()
1940+ .expect("We have a pending splice awaiting signatures")
1941+ .has_received_commitment_signed()
1942+ {
1943+ // We only force close once the counterparty tries to abort after committing to
1944+ // the splice via their initial `commitment_signed`. This is because our monitor
1945+ // state is updated with the post-splice commitment transaction upon receiving
1946+ // their `commitment_signed`, so we would need another monitor update to abandon
1947+ // it, which we don't currently support.
19361948 return Err(ChannelError::close(
19371949 "Received tx_abort while awaiting tx_signatures exchange".to_owned(),
19381950 ));
19391951 }
1940- if funded_channel.should_reset_pending_splice_state() {
1952+ if funded_channel.should_reset_pending_splice_state(true ) {
19411953 let has_funding_negotiation = funded_channel
19421954 .pending_splice
19431955 .as_ref()
@@ -2681,19 +2693,6 @@ impl FundingNegotiation {
26812693}
26822694
26832695impl PendingFunding {
2684- fn can_abandon_state(&self) -> bool {
2685- self.funding_negotiation
2686- .as_ref()
2687- .map(|funding_negotiation| {
2688- !matches!(funding_negotiation, FundingNegotiation::AwaitingSignatures { .. })
2689- })
2690- .unwrap_or_else(|| {
2691- let has_negotiated_candidates = !self.negotiated_candidates.is_empty();
2692- debug_assert!(has_negotiated_candidates);
2693- !has_negotiated_candidates
2694- })
2695- }
2696-
26972696 fn check_get_splice_locked<SP: Deref>(
26982697 &mut self, context: &ChannelContext<SP>, confirmed_funding_index: usize, height: u32,
26992698 ) -> Option<msgs::SpliceLocked>
@@ -6873,7 +6872,7 @@ pub struct SpliceFundingFailed {
68736872}
68746873
68756874macro_rules! maybe_create_splice_funding_failed {
6876- ($pending_splice: expr, $get: ident, $contributed_inputs_and_outputs: ident) => {{
6875+ ($funded_channel: expr, $ pending_splice: expr, $get: ident, $contributed_inputs_and_outputs: ident) => {{
68776876 $pending_splice
68786877 .and_then(|pending_splice| pending_splice.funding_negotiation.$get())
68796878 .filter(|funding_negotiation| funding_negotiation.is_initiator())
@@ -6895,10 +6894,12 @@ macro_rules! maybe_create_splice_funding_failed {
68956894 interactive_tx_constructor,
68966895 ..
68976896 } => interactive_tx_constructor.$contributed_inputs_and_outputs(),
6898- FundingNegotiation::AwaitingSignatures { .. } => {
6899- debug_assert!(false);
6900- (Vec::new(), Vec::new())
6901- },
6897+ FundingNegotiation::AwaitingSignatures { .. } => $funded_channel
6898+ .context
6899+ .interactive_tx_signing_session
6900+ .$get()
6901+ .expect("We have a pending splice awaiting signatures")
6902+ .$contributed_inputs_and_outputs(),
69026903 };
69036904
69046905 SpliceFundingFailed {
@@ -6937,7 +6938,7 @@ where
69376938
69386939 fn maybe_fail_splice_negotiation(&mut self) -> Option<SpliceFundingFailed> {
69396940 if matches!(self.context.channel_state, ChannelState::ChannelReady(_)) {
6940- if self.should_reset_pending_splice_state() {
6941+ if self.should_reset_pending_splice_state(false ) {
69416942 self.reset_pending_splice_state()
69426943 } else {
69436944 match self.quiescent_action.take() {
@@ -7011,19 +7012,54 @@ where
70117012
70127013 /// Returns a boolean indicating whether we should reset the splice's
70137014 /// [`PendingFunding::funding_negotiation`].
7014- fn should_reset_pending_splice_state(&self) -> bool {
7015+ fn should_reset_pending_splice_state(&self, counterparty_aborted: bool ) -> bool {
70157016 self.pending_splice
70167017 .as_ref()
7017- .map(|pending_splice| pending_splice.can_abandon_state())
7018+ .map(|pending_splice| {
7019+ pending_splice
7020+ .funding_negotiation
7021+ .as_ref()
7022+ .map(|funding_negotiation| {
7023+ let is_awaiting_signatures = matches!(
7024+ funding_negotiation,
7025+ FundingNegotiation::AwaitingSignatures { .. }
7026+ );
7027+ if counterparty_aborted {
7028+ !is_awaiting_signatures
7029+ || !self
7030+ .context()
7031+ .interactive_tx_signing_session
7032+ .as_ref()
7033+ .expect("We have a pending splice awaiting signatures")
7034+ .has_received_commitment_signed()
7035+ } else {
7036+ !is_awaiting_signatures
7037+ }
7038+ })
7039+ .unwrap_or_else(|| {
7040+ let has_negotiated_candidates =
7041+ !pending_splice.negotiated_candidates.is_empty();
7042+ debug_assert!(has_negotiated_candidates);
7043+ !has_negotiated_candidates
7044+ })
7045+ })
70187046 .unwrap_or(false)
70197047 }
70207048
70217049 fn reset_pending_splice_state(&mut self) -> Option<SpliceFundingFailed> {
7022- debug_assert!(self.should_reset_pending_splice_state());
7023- debug_assert!(self.context.interactive_tx_signing_session.is_none());
7024- self.context.channel_state.clear_quiescent();
7050+ debug_assert!(self.should_reset_pending_splice_state(true));
7051+ debug_assert!(
7052+ self.context.interactive_tx_signing_session.is_none()
7053+ || !self
7054+ .context
7055+ .interactive_tx_signing_session
7056+ .as_ref()
7057+ .expect("We have a pending splice awaiting signatures")
7058+ .has_received_commitment_signed()
7059+ );
70257060
70267061 let splice_funding_failed = maybe_create_splice_funding_failed!(
7062+ self,
70277063 self.pending_splice.as_mut(),
70287064 take,
70297065 into_contributed_inputs_and_outputs
@@ -7033,15 +7069,19 @@ where
70337069 self.pending_splice.take();
70347070 }
70357071
7072+ self.context.channel_state.clear_quiescent();
7073+ self.context.interactive_tx_signing_session.take();
7074+
70367075 splice_funding_failed
70377076 }
70387077
70397078 pub(super) fn maybe_splice_funding_failed(&self) -> Option<SpliceFundingFailed> {
7040- if !self.should_reset_pending_splice_state() {
7079+ if !self.should_reset_pending_splice_state(false ) {
70417080 return None;
70427081 }
70437082
70447083 maybe_create_splice_funding_failed!(
7084+ self,
70457085 self.pending_splice.as_ref(),
70467086 as_ref,
70477087 to_contributed_inputs_and_outputs
@@ -11996,7 +12036,7 @@ where
1199612036 pub fn abandon_splice(
1199712037 &mut self,
1199812038 ) -> Result<(msgs::TxAbort, Option<SpliceFundingFailed>), APIError> {
11999- if self.should_reset_pending_splice_state() {
12039+ if self.should_reset_pending_splice_state(false ) {
1200012040 let tx_abort =
1200112041 msgs::TxAbort { channel_id: self.context.channel_id(), data: Vec::new() };
1200212042 let splice_funding_failed = self.reset_pending_splice_state();
@@ -14361,7 +14401,7 @@ where
1436114401 }
1436214402 channel_state.clear_local_stfu_sent();
1436314403 channel_state.clear_remote_stfu_sent();
14364- if self.should_reset_pending_splice_state()
14404+ if self.should_reset_pending_splice_state(false )
1436514405 || !self.has_pending_splice_awaiting_signatures()
1436614406 {
1436714407 // We shouldn't be quiescent anymore upon reconnecting if:
@@ -14735,7 +14775,7 @@ where
1473514775 // We don't have to worry about resetting the pending `FundingNegotiation` because we
1473614776 // can only read `FundingNegotiation::AwaitingSignatures` variants anyway.
1473714777 let pending_splice =
14738- self.pending_splice.as_ref().filter(|_| !self.should_reset_pending_splice_state());
14778+ self.pending_splice.as_ref().filter(|_| !self.should_reset_pending_splice_state(false ));
1473914779
1474014780 write_tlv_fields!(writer, {
1474114781 (0, self.context.announcement_sigs, option),
0 commit comments