@@ -1204,6 +1204,18 @@ pub enum UpdateFulfillCommitFetch {
12041204 DuplicateClaim {},
12051205}
12061206
1207+ /// Error returned when processing an invalid interactive-tx message from our counterparty.
1208+ pub(super) struct InteractiveTxMsgError {
1209+ /// The underlying error.
1210+ pub(super) err: ChannelError,
1211+ /// If a splice was in progress when processing the message, this contains the splice funding
1212+ /// information for emitting a `SpliceFailed` event.
1213+ pub(super) splice_funding_failed: Option<SpliceFundingFailed>,
1214+ /// Whether we were quiescent when we received the message, and are no longer due to aborting
1215+ /// the session.
1216+ pub(super) exited_quiescence: bool,
1217+ }
1218+
12071219/// The return value of `monitor_updating_restored`
12081220pub(super) struct MonitorRestoreUpdates {
12091221 pub raa: Option<msgs::RevokeAndACK>,
@@ -1846,104 +1858,118 @@ where
18461858
18471859 fn fail_interactive_tx_negotiation<L: Logger>(
18481860 &mut self, reason: AbortReason, logger: &L,
1849- ) -> (ChannelError, Option<SpliceFundingFailed>) {
1861+ ) -> InteractiveTxMsgError {
18501862 let logger = WithChannelContext::from(logger, &self.context(), None);
18511863 log_info!(logger, "Failed interactive transaction negotiation: {reason}");
18521864
1853- let splice_funding_failed = match &mut self.phase {
1865+ let ( splice_funding_failed, exited_quiescence) = match &mut self.phase {
18541866 ChannelPhase::Undefined => unreachable!(),
1855- ChannelPhase::UnfundedOutboundV1(_) | ChannelPhase::UnfundedInboundV1(_) => None,
1867+ ChannelPhase::UnfundedOutboundV1(_) | ChannelPhase::UnfundedInboundV1(_) => {
1868+ (None, false)
1869+ },
18561870 ChannelPhase::UnfundedV2(pending_v2_channel) => {
18571871 pending_v2_channel.interactive_tx_constructor.take();
1858- None
1872+ ( None, false)
18591873 },
18601874 ChannelPhase::Funded(funded_channel) => {
18611875 if funded_channel.should_reset_pending_splice_state(false) {
1862- funded_channel.reset_pending_splice_state()
1876+ ( funded_channel.reset_pending_splice_state(), true )
18631877 } else {
18641878 debug_assert!(false, "We should never fail an interactive funding negotiation once we're exchanging tx_signatures");
1865- None
1879+ ( None, false)
18661880 }
18671881 },
18681882 };
18691883
1870- (ChannelError::Abort(reason), splice_funding_failed)
1884+ InteractiveTxMsgError {
1885+ err: ChannelError::Abort(reason),
1886+ splice_funding_failed,
1887+ exited_quiescence,
1888+ }
18711889 }
18721890
18731891 pub fn tx_add_input<L: Logger>(
18741892 &mut self, msg: &msgs::TxAddInput, logger: &L,
1875- ) -> Result<InteractiveTxMessageSend, (ChannelError, Option<SpliceFundingFailed>) > {
1893+ ) -> Result<InteractiveTxMessageSend, InteractiveTxMsgError > {
18761894 match self.interactive_tx_constructor_mut() {
18771895 Some(interactive_tx_constructor) => interactive_tx_constructor
18781896 .handle_tx_add_input(msg)
18791897 .map_err(|reason| self.fail_interactive_tx_negotiation(reason, logger)),
1880- None => Err((
1881- ChannelError::WarnAndDisconnect(
1898+ None => Err(InteractiveTxMsgError {
1899+ err: ChannelError::WarnAndDisconnect(
18821900 "Received unexpected interactive transaction negotiation message".to_owned(),
18831901 ),
1884- None,
1885- )),
1902+ splice_funding_failed: None,
1903+ exited_quiescence: false,
1904+ }),
18861905 }
18871906 }
18881907
18891908 pub fn tx_add_output<L: Logger>(
18901909 &mut self, msg: &msgs::TxAddOutput, logger: &L,
1891- ) -> Result<InteractiveTxMessageSend, (ChannelError, Option<SpliceFundingFailed>) > {
1910+ ) -> Result<InteractiveTxMessageSend, InteractiveTxMsgError > {
18921911 match self.interactive_tx_constructor_mut() {
18931912 Some(interactive_tx_constructor) => interactive_tx_constructor
18941913 .handle_tx_add_output(msg)
18951914 .map_err(|reason| self.fail_interactive_tx_negotiation(reason, logger)),
1896- None => Err((
1897- ChannelError::WarnAndDisconnect(
1915+ None => Err(InteractiveTxMsgError {
1916+ err: ChannelError::WarnAndDisconnect(
18981917 "Received unexpected interactive transaction negotiation message".to_owned(),
18991918 ),
1900- None,
1901- )),
1919+ splice_funding_failed: None,
1920+ exited_quiescence: false,
1921+ }),
19021922 }
19031923 }
19041924
19051925 pub fn tx_remove_input<L: Logger>(
19061926 &mut self, msg: &msgs::TxRemoveInput, logger: &L,
1907- ) -> Result<InteractiveTxMessageSend, (ChannelError, Option<SpliceFundingFailed>) > {
1927+ ) -> Result<InteractiveTxMessageSend, InteractiveTxMsgError > {
19081928 match self.interactive_tx_constructor_mut() {
19091929 Some(interactive_tx_constructor) => interactive_tx_constructor
19101930 .handle_tx_remove_input(msg)
19111931 .map_err(|reason| self.fail_interactive_tx_negotiation(reason, logger)),
1912- None => Err((
1913- ChannelError::WarnAndDisconnect(
1932+ None => Err(InteractiveTxMsgError {
1933+ err: ChannelError::WarnAndDisconnect(
19141934 "Received unexpected interactive transaction negotiation message".to_owned(),
19151935 ),
1916- None,
1917- )),
1936+ splice_funding_failed: None,
1937+ exited_quiescence: false,
1938+ }),
19181939 }
19191940 }
19201941
19211942 pub fn tx_remove_output<L: Logger>(
19221943 &mut self, msg: &msgs::TxRemoveOutput, logger: &L,
1923- ) -> Result<InteractiveTxMessageSend, (ChannelError, Option<SpliceFundingFailed>) > {
1944+ ) -> Result<InteractiveTxMessageSend, InteractiveTxMsgError > {
19241945 match self.interactive_tx_constructor_mut() {
19251946 Some(interactive_tx_constructor) => interactive_tx_constructor
19261947 .handle_tx_remove_output(msg)
19271948 .map_err(|reason| self.fail_interactive_tx_negotiation(reason, logger)),
1928- None => Err((
1929- ChannelError::WarnAndDisconnect(
1949+ None => Err(InteractiveTxMsgError {
1950+ err: ChannelError::WarnAndDisconnect(
19301951 "Received unexpected interactive transaction negotiation message".to_owned(),
19311952 ),
1932- None,
1933- )),
1953+ splice_funding_failed: None,
1954+ exited_quiescence: false,
1955+ }),
19341956 }
19351957 }
19361958
19371959 pub fn tx_complete<F: FeeEstimator, L: Logger>(
19381960 &mut self, msg: &msgs::TxComplete, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
1939- ) -> Result<TxCompleteResult, (ChannelError, Option<SpliceFundingFailed>) > {
1961+ ) -> Result<TxCompleteResult, InteractiveTxMsgError > {
19401962 let tx_complete_action = match self.interactive_tx_constructor_mut() {
19411963 Some(interactive_tx_constructor) => interactive_tx_constructor
19421964 .handle_tx_complete(msg)
19431965 .map_err(|reason| self.fail_interactive_tx_negotiation(reason, logger))?,
19441966 None => {
19451967 let err = "Received unexpected interactive transaction negotiation message";
1946- return Err((ChannelError::WarnAndDisconnect(err.to_owned()), None));
1968+ return Err(InteractiveTxMsgError {
1969+ err: ChannelError::WarnAndDisconnect(err.to_owned()),
1970+ splice_funding_failed: None,
1971+ exited_quiescence: false,
1972+ });
19471973 },
19481974 };
19491975
@@ -2003,13 +2029,13 @@ where
20032029
20042030 pub fn tx_abort<L: Logger>(
20052031 &mut self, msg: &msgs::TxAbort, logger: &L,
2006- ) -> Result<(Option<msgs::TxAbort>, Option<SpliceFundingFailed>), ChannelError> {
2032+ ) -> Result<(Option<msgs::TxAbort>, Option<SpliceFundingFailed>, bool ), ChannelError> {
20072033 // If we have not sent a `tx_abort` message for this negotiation previously, we need to echo
20082034 // back a tx_abort message according to the spec:
20092035 // https://github.com/lightning/bolts/blob/247e83d/02-peer-protocol.md?plain=1#L560-L561
20102036 // For rationale why we echo back `tx_abort`:
20112037 // https://github.com/lightning/bolts/blob/247e83d/02-peer-protocol.md?plain=1#L578-L580
2012- let (should_ack, splice_funding_failed) = match &mut self.phase {
2038+ let (should_ack, splice_funding_failed, exited_quiescence ) = match &mut self.phase {
20132039 ChannelPhase::Undefined => unreachable!(),
20142040 ChannelPhase::UnfundedOutboundV1(_) | ChannelPhase::UnfundedInboundV1(_) => {
20152041 let err = "Got an unexpected tx_abort message: This is an unfunded channel created with V1 channel establishment";
@@ -2018,7 +2044,7 @@ where
20182044 ChannelPhase::UnfundedV2(pending_v2_channel) => {
20192045 let had_constructor =
20202046 pending_v2_channel.interactive_tx_constructor.take().is_some();
2021- (had_constructor, None)
2047+ (had_constructor, None, false )
20222048 },
20232049 ChannelPhase::Funded(funded_channel) => {
20242050 if funded_channel.has_pending_splice_awaiting_signatures()
@@ -2046,11 +2072,11 @@ where
20462072 .unwrap_or(false);
20472073 debug_assert!(has_funding_negotiation);
20482074 let splice_funding_failed = funded_channel.reset_pending_splice_state();
2049- (true, splice_funding_failed)
2075+ (true, splice_funding_failed, true )
20502076 } else {
20512077 // We were not tracking the pending funding negotiation state anymore, likely
20522078 // due to a disconnection or already having sent our own `tx_abort`.
2053- (false, None)
2079+ (false, None, false )
20542080 }
20552081 },
20562082 };
@@ -2066,7 +2092,7 @@ where
20662092 }
20672093 });
20682094
2069- Ok((tx_abort, splice_funding_failed))
2095+ Ok((tx_abort, splice_funding_failed, exited_quiescence ))
20702096 }
20712097
20722098 #[rustfmt::skip]
0 commit comments