@@ -1645,7 +1645,7 @@ where
16451645 }
16461646 chan.context.channel_state.clear_local_stfu_sent();
16471647 chan.context.channel_state.clear_remote_stfu_sent();
1648- if chan.should_reset_pending_splice_state() {
1648+ if chan.should_reset_pending_splice_state(false ) {
16491649 // If there was a pending splice negotiation that failed due to disconnecting, we
16501650 // also take the opportunity to clean up our state.
16511651 let splice_funding_failed = chan.reset_pending_splice_state();
@@ -1766,7 +1766,7 @@ where
17661766 None
17671767 },
17681768 ChannelPhase::Funded(funded_channel) => {
1769- if funded_channel.should_reset_pending_splice_state() {
1769+ if funded_channel.should_reset_pending_splice_state(false ) {
17701770 funded_channel.reset_pending_splice_state()
17711771 } else {
17721772 debug_assert!(false, "We should never fail an interactive funding negotiation once we're exchanging tx_signatures");
@@ -1923,12 +1923,24 @@ where
19231923 (had_constructor, None)
19241924 },
19251925 ChannelPhase::Funded(funded_channel) => {
1926- if funded_channel.has_pending_splice_awaiting_signatures() {
1926+ if funded_channel.has_pending_splice_awaiting_signatures()
1927+ && funded_channel
1928+ .context()
1929+ .interactive_tx_signing_session
1930+ .as_ref()
1931+ .expect("We have a pending splice awaiting signatures")
1932+ .has_received_commitment_signed()
1933+ {
1934+ // We only force close once the counterparty tries to abort after committing to
1935+ // the splice via their initial `commitment_signed`. This is because our monitor
1936+ // state is updated with the post-splice commitment transaction upon receiving
1937+ // their `commitment_signed`, so we would need another monitor update to abandon
1938+ // it, which we don't currently support.
19271939 return Err(ChannelError::close(
19281940 "Received tx_abort while awaiting tx_signatures exchange".to_owned(),
19291941 ));
19301942 }
1931- if funded_channel.should_reset_pending_splice_state() {
1943+ if funded_channel.should_reset_pending_splice_state(true ) {
19321944 let has_funding_negotiation = funded_channel
19331945 .pending_splice
19341946 .as_ref()
@@ -2695,19 +2707,6 @@ impl FundingNegotiation {
26952707}
26962708
26972709impl PendingFunding {
2698- fn can_abandon_state(&self) -> bool {
2699- self.funding_negotiation
2700- .as_ref()
2701- .map(|funding_negotiation| {
2702- !matches!(funding_negotiation, FundingNegotiation::AwaitingSignatures { .. })
2703- })
2704- .unwrap_or_else(|| {
2705- let has_negotiated_candidates = !self.negotiated_candidates.is_empty();
2706- debug_assert!(has_negotiated_candidates);
2707- !has_negotiated_candidates
2708- })
2709- }
2710-
27112710 fn check_get_splice_locked<SP: Deref>(
27122711 &mut self, context: &ChannelContext<SP>, confirmed_funding_index: usize, height: u32,
27132712 ) -> Option<msgs::SpliceLocked>
@@ -6890,7 +6889,7 @@ pub struct SpliceFundingFailed {
68906889}
68916890
68926891macro_rules! maybe_create_splice_funding_failed {
6893- ($pending_splice: expr, $get: ident, $contributed_inputs_and_outputs: ident) => {{
6892+ ($funded_channel: expr, $ pending_splice: expr, $get: ident, $contributed_inputs_and_outputs: ident) => {{
68946893 $pending_splice
68956894 .and_then(|pending_splice| pending_splice.funding_negotiation.$get())
68966895 .filter(|funding_negotiation| funding_negotiation.is_initiator())
@@ -6912,10 +6911,12 @@ macro_rules! maybe_create_splice_funding_failed {
69126911 interactive_tx_constructor,
69136912 ..
69146913 } => interactive_tx_constructor.$contributed_inputs_and_outputs(),
6915- FundingNegotiation::AwaitingSignatures { .. } => {
6916- debug_assert!(false);
6917- (Vec::new(), Vec::new())
6918- },
6914+ FundingNegotiation::AwaitingSignatures { .. } => $funded_channel
6915+ .context
6916+ .interactive_tx_signing_session
6917+ .$get()
6918+ .expect("We have a pending splice awaiting signatures")
6919+ .$contributed_inputs_and_outputs(),
69196920 };
69206921
69216922 SpliceFundingFailed {
@@ -6954,7 +6955,7 @@ where
69546955
69556956 fn maybe_fail_splice_negotiation(&mut self) -> Option<SpliceFundingFailed> {
69566957 if matches!(self.context.channel_state, ChannelState::ChannelReady(_)) {
6957- if self.should_reset_pending_splice_state() {
6958+ if self.should_reset_pending_splice_state(false ) {
69586959 self.reset_pending_splice_state()
69596960 } else {
69606961 match self.quiescent_action.take() {
@@ -7028,19 +7029,54 @@ where
70287029
70297030 /// Returns a boolean indicating whether we should reset the splice's
70307031 /// [`PendingFunding::funding_negotiation`].
7031- fn should_reset_pending_splice_state(&self) -> bool {
7032+ fn should_reset_pending_splice_state(&self, counterparty_aborted: bool ) -> bool {
70327033 self.pending_splice
70337034 .as_ref()
7034- .map(|pending_splice| pending_splice.can_abandon_state())
7035+ .map(|pending_splice| {
7036+ pending_splice
7037+ .funding_negotiation
7038+ .as_ref()
7039+ .map(|funding_negotiation| {
7040+ let is_awaiting_signatures = matches!(
7041+ funding_negotiation,
7042+ FundingNegotiation::AwaitingSignatures { .. }
7043+ );
7044+ if counterparty_aborted {
7045+ !is_awaiting_signatures
7046+ || !self
7047+ .context()
7048+ .interactive_tx_signing_session
7049+ .as_ref()
7050+ .expect("We have a pending splice awaiting signatures")
7051+ .has_received_commitment_signed()
7052+ } else {
7053+ !is_awaiting_signatures
7054+ }
7055+ })
7056+ .unwrap_or_else(|| {
7057+ let has_negotiated_candidates =
7058+ !pending_splice.negotiated_candidates.is_empty();
7059+ debug_assert!(has_negotiated_candidates);
7060+ !has_negotiated_candidates
7061+ })
7062+ })
70357063 .unwrap_or(false)
70367064 }
70377065
70387066 fn reset_pending_splice_state(&mut self) -> Option<SpliceFundingFailed> {
7039- debug_assert!(self.should_reset_pending_splice_state());
7040- debug_assert!(self.context.interactive_tx_signing_session.is_none());
7041- self.context.channel_state.clear_quiescent();
7067+ debug_assert!(self.should_reset_pending_splice_state(true));
7068+ debug_assert!(
7069+ self.context.interactive_tx_signing_session.is_none()
7070+ || !self
7071+ .context
7072+ .interactive_tx_signing_session
7073+ .as_ref()
7074+ .expect("We have a pending splice awaiting signatures")
7075+ .has_received_commitment_signed()
7076+ );
70427077
70437078 let splice_funding_failed = maybe_create_splice_funding_failed!(
7079+ self,
70447080 self.pending_splice.as_mut(),
70457081 take,
70467082 into_contributed_inputs_and_outputs
@@ -7050,15 +7086,19 @@ where
70507086 self.pending_splice.take();
70517087 }
70527088
7089+ self.context.channel_state.clear_quiescent();
7090+ self.context.interactive_tx_signing_session.take();
7091+
70537092 splice_funding_failed
70547093 }
70557094
70567095 pub(super) fn maybe_splice_funding_failed(&self) -> Option<SpliceFundingFailed> {
7057- if !self.should_reset_pending_splice_state() {
7096+ if !self.should_reset_pending_splice_state(false ) {
70587097 return None;
70597098 }
70607099
70617100 maybe_create_splice_funding_failed!(
7101+ self,
70627102 self.pending_splice.as_ref(),
70637103 as_ref,
70647104 to_contributed_inputs_and_outputs
@@ -12013,7 +12053,7 @@ where
1201312053 pub fn abandon_splice(
1201412054 &mut self,
1201512055 ) -> Result<(msgs::TxAbort, Option<SpliceFundingFailed>), APIError> {
12016- if self.should_reset_pending_splice_state() {
12056+ if self.should_reset_pending_splice_state(false ) {
1201712057 let tx_abort =
1201812058 msgs::TxAbort { channel_id: self.context.channel_id(), data: Vec::new() };
1201912059 let splice_funding_failed = self.reset_pending_splice_state();
@@ -14382,7 +14422,7 @@ where
1438214422 }
1438314423 channel_state.clear_local_stfu_sent();
1438414424 channel_state.clear_remote_stfu_sent();
14385- if self.should_reset_pending_splice_state()
14425+ if self.should_reset_pending_splice_state(false )
1438614426 || !self.has_pending_splice_awaiting_signatures()
1438714427 {
1438814428 // We shouldn't be quiescent anymore upon reconnecting if:
@@ -14756,7 +14796,7 @@ where
1475614796 // We don't have to worry about resetting the pending `FundingNegotiation` because we
1475714797 // can only read `FundingNegotiation::AwaitingSignatures` variants anyway.
1475814798 let pending_splice =
14759- self.pending_splice.as_ref().filter(|_| !self.should_reset_pending_splice_state());
14799+ self.pending_splice.as_ref().filter(|_| !self.should_reset_pending_splice_state(false ));
1476014800
1476114801 write_tlv_fields!(writer, {
1476214802 (0, self.context.announcement_sigs, option),
0 commit comments