@@ -1782,57 +1782,74 @@ where
17821782 L::Target: Logger,
17831783 {
17841784 let logger = WithChannelContext::from(logger, self.context(), None);
1785- let (funding, context, signing_session, is_splice, holder_commitment_transaction_number) =
1786- // TODO: Could use a wrapper or trait to DRY this
1787- match &mut self.phase {
1788- ChannelPhase::UnfundedV2(chan) => {
1789- chan.interactive_tx_signing_session = Some(
1790- chan.interactive_tx_constructor
1791- .take()
1792- .expect("TODO")
1793- .into_signing_session(),
1794- );
1795- (
1796- &mut chan.funding,
1797- &mut chan.context,
1798- chan.interactive_tx_signing_session.as_mut().expect("TODO"),
1799- false,
1800- chan.unfunded_context.transaction_number(),
1801- )
1802- },
1803- #[cfg(splicing)]
1804- ChannelPhase::Funded(chan) => {
1805- chan.interactive_tx_signing_session = Some(
1806- chan.pending_splice
1807- .as_mut()
1808- .expect("TODO")
1809- .interactive_tx_constructor
1810- .take()
1811- .expect("TODO")
1812- .into_signing_session(),
1813- );
1814- (
1815- &mut chan.funding,
1816- &mut chan.context,
1817- chan.interactive_tx_signing_session.as_mut().expect("TODO"),
1818- true,
1819- chan.holder_commitment_point.transaction_number(),
1820- )
1821- },
1822- _ => {
1785+ match &mut self.phase {
1786+ ChannelPhase::UnfundedV2(chan) => {
1787+ let mut signing_session =
1788+ chan.interactive_tx_constructor.take().expect("TODO").into_signing_session();
1789+ let result = funding_tx_constructed(
1790+ &mut chan.funding,
1791+ &mut chan.context,
1792+ &mut signing_session,
1793+ false,
1794+ chan.unfunded_context.transaction_number(),
1795+ &&logger,
1796+ );
1797+
1798+ // FIXME: Should this remain None if result is an Err?
1799+ chan.interactive_tx_signing_session = Some(signing_session);
1800+
1801+ return result;
1802+ },
1803+ #[cfg(splicing)]
1804+ ChannelPhase::Funded(chan) => {
1805+ if let Some(pending_splice) = chan.pending_splice.as_mut() {
1806+ if let Some(funding_negotiation) = pending_splice.funding_negotiation.take() {
1807+ if let FundingNegotiation::Pending(
1808+ mut funding,
1809+ interactive_tx_constructor,
1810+ ) = funding_negotiation
1811+ {
1812+ let mut signing_session =
1813+ interactive_tx_constructor.into_signing_session();
1814+ let result = funding_tx_constructed(
1815+ &mut funding,
1816+ &mut chan.context,
1817+ &mut signing_session,
1818+ true,
1819+ chan.holder_commitment_point.transaction_number(),
1820+ &&logger,
1821+ );
1822+
1823+ // FIXME: Should these remain None if result is an Err?
1824+ chan.interactive_tx_signing_session = Some(signing_session);
1825+ pending_splice.funding_negotiation =
1826+ Some(FundingNegotiation::AwaitingSignatures(funding));
1827+
1828+ return result;
1829+ } else {
1830+ pending_splice.funding_negotiation = Some(funding_negotiation);
1831+ return Err(ChannelError::Warn(
1832+ "Got a transaction negotiation message in an invalid state"
1833+ .to_owned(),
1834+ ));
1835+ }
1836+ } else {
1837+ return Err(ChannelError::Warn(
1838+ "Got a transaction negotiation message in an invalid state".to_owned(),
1839+ ));
1840+ }
1841+ } else {
18231842 return Err(ChannelError::Warn(
1824- "Got a transaction negotiation message in an invalid phase".to_owned(),
1825- ))
1826- },
1827- };
1828- funding_tx_constructed(
1829- funding,
1830- context,
1831- signing_session,
1832- is_splice,
1833- holder_commitment_transaction_number,
1834- &&logger,
1835- )
1843+ "Got a transaction negotiation message in an invalid state".to_owned(),
1844+ ));
1845+ }
1846+ },
1847+ _ => {
1848+ return Err(ChannelError::Warn(
1849+ "Got a transaction negotiation message in an invalid phase".to_owned(),
1850+ ))
1851+ },
1852+ }
18361853 }
18371854
18381855 pub fn force_shutdown(&mut self, closure_reason: ClosureReason) -> ShutdownResult {
@@ -2332,8 +2349,6 @@ struct PendingSplice {
23322349 /// Intended contributions to the splice from our end
23332350 pub our_funding_contribution: i64,
23342351 funding_negotiation: Option<FundingNegotiation>,
2335- /// The current interactive transaction construction session under negotiation.
2336- interactive_tx_constructor: Option<InteractiveTxConstructor>,
23372352
23382353 /// The funding txid used in the `splice_locked` sent to the counterparty.
23392354 sent_funding_txid: Option<Txid>,
@@ -2344,14 +2359,16 @@ struct PendingSplice {
23442359
23452360enum FundingNegotiation {
23462361 AwaitingAck(FundingNegotiationContext),
2347- Pending(FundingScope),
2362+ Pending(FundingScope, InteractiveTxConstructor),
2363+ AwaitingSignatures(FundingScope),
23482364}
23492365
23502366impl FundingNegotiation {
23512367 fn as_funding(&self) -> Option<&FundingScope> {
23522368 match self {
23532369 FundingNegotiation::AwaitingAck(_) => None,
2354- FundingNegotiation::Pending(funding) => Some(funding),
2370+ FundingNegotiation::Pending(funding, _) => Some(funding),
2371+ FundingNegotiation::AwaitingSignatures(funding) => Some(funding),
23552372 }
23562373 }
23572374}
@@ -6173,8 +6190,16 @@ where
61736190 fn as_renegotiating_channel(&mut self) -> Option<NegotiatingChannelView> {
61746191 self.pending_splice
61756192 .as_mut()
6176- .and_then(|pending_splice| pending_splice.interactive_tx_constructor.as_mut())
6177- .map(|interactive_tx_constructor| NegotiatingChannelView(interactive_tx_constructor))
6193+ .and_then(|pending_splice| pending_splice.funding_negotiation.as_mut())
6194+ .and_then(|funding_negotiation| {
6195+ if let FundingNegotiation::Pending(_, interactive_tx_constructor) =
6196+ funding_negotiation
6197+ {
6198+ Some(NegotiatingChannelView(interactive_tx_constructor))
6199+ } else {
6200+ None
6201+ }
6202+ })
61786203 }
61796204
61806205 #[rustfmt::skip]
@@ -10432,7 +10457,6 @@ where
1043210457 self.pending_splice = Some(PendingSplice {
1043310458 our_funding_contribution: our_funding_contribution_satoshis,
1043410459 funding_negotiation: Some(FundingNegotiation::AwaitingAck(funding_negotiation_context)),
10435- interactive_tx_constructor: None,
1043610460 sent_funding_txid: None,
1043710461 received_funding_txid: None,
1043810462 });
@@ -10595,8 +10619,10 @@ where
1059510619
1059610620 self.pending_splice = Some(PendingSplice {
1059710621 our_funding_contribution,
10598- funding_negotiation: Some(FundingNegotiation::Pending(splice_funding)),
10599- interactive_tx_constructor: Some(interactive_tx_constructor),
10622+ funding_negotiation: Some(FundingNegotiation::Pending(
10623+ splice_funding,
10624+ interactive_tx_constructor,
10625+ )),
1060010626 received_funding_txid: None,
1060110627 sent_funding_txid: None,
1060210628 });
@@ -10640,8 +10666,16 @@ where
1064010666
1064110667 let mut funding_negotiation_context = match pending_splice.funding_negotiation.take() {
1064210668 Some(FundingNegotiation::AwaitingAck(context)) => context,
10643- Some(FundingNegotiation::Pending(funding)) => {
10644- pending_splice.funding_negotiation = Some(FundingNegotiation::Pending(funding));
10669+ Some(FundingNegotiation::Pending(funding, constructor)) => {
10670+ pending_splice.funding_negotiation =
10671+ Some(FundingNegotiation::Pending(funding, constructor));
10672+ return Err(ChannelError::Warn(format!(
10673+ "Got unexpected splice_ack; splice negotiation already in progress"
10674+ )));
10675+ },
10676+ Some(FundingNegotiation::AwaitingSignatures(funding)) => {
10677+ pending_splice.funding_negotiation =
10678+ Some(FundingNegotiation::AwaitingSignatures(funding));
1064510679 return Err(ChannelError::Warn(format!(
1064610680 "Got unexpected splice_ack; splice negotiation already in progress"
1064710681 )));
@@ -10711,10 +10745,9 @@ where
1071110745 })?;
1071210746 let tx_msg_opt = interactive_tx_constructor.take_initiator_first_message();
1071310747
10714- debug_assert!(pending_splice.interactive_tx_constructor.is_none());
1071510748 debug_assert!(self.interactive_tx_signing_session.is_none());
10716- pending_splice.funding_negotiation = Some(FundingNegotiation::Pending(splice_funding));
10717- pending_splice.interactive_tx_constructor = Some(interactive_tx_constructor);
10749+ pending_splice.funding_negotiation =
10750+ Some(FundingNegotiation::Pending(splice_funding, interactive_tx_constructor) );
1071810751
1071910752 Ok(tx_msg_opt)
1072010753 }
0 commit comments