Skip to content

Commit 5896aed

Browse files
committed
f - correctly emit SpliceFailed when funding_tx_constructed fails
1 parent 727b25f commit 5896aed

File tree

1 file changed

+21
-41
lines changed

1 file changed

+21
-41
lines changed

lightning/src/ln/channel.rs

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,56 +1754,34 @@ where
17541754
let logger = WithChannelContext::from(logger, &self.context(), None);
17551755
log_info!(logger, "Failed interactive transaction negotiation: {reason}");
17561756

1757-
let mut splice_failed = None;
1758-
1759-
let _interactive_tx_constructor = match &mut self.phase {
1757+
let splice_funding_failed = match &mut self.phase {
17601758
ChannelPhase::Undefined => unreachable!(),
17611759
ChannelPhase::UnfundedOutboundV1(_) | ChannelPhase::UnfundedInboundV1(_) => None,
17621760
ChannelPhase::UnfundedV2(pending_v2_channel) => {
1763-
pending_v2_channel.interactive_tx_constructor.take()
1761+
pending_v2_channel.interactive_tx_constructor.take();
1762+
None
17641763
},
17651764
ChannelPhase::Funded(funded_channel) => {
1766-
if let Some(pending_splice) = funded_channel.pending_splice.as_mut() {
1767-
if pending_splice.funding_negotiation.is_some() {
1768-
let funding_negotiation = pending_splice.funding_negotiation.take();
1769-
1770-
let (funding_txo, channel_type, contributed_inputs, contributed_outputs) =
1771-
if let Some(FundingNegotiation::ConstructingTransaction { funding, interactive_tx_constructor: _ }) = &funding_negotiation {
1772-
(
1773-
funding.get_funding_txo().map(|txo| txo.into_bitcoin_outpoint()),
1774-
Some(funding.get_channel_type().clone()),
1775-
Vec::new(), // TODO: Extract contributed inputs from interactive_tx_constructor
1776-
Vec::new(), // TODO: Extract contributed outputs from interactive_tx_constructor
1777-
)
1778-
} else {
1779-
(None, None, Vec::new(), Vec::new())
1780-
};
1781-
1782-
splice_failed = Some(SpliceFundingFailed {
1765+
funded_channel
1766+
.pending_splice
1767+
.as_mut()
1768+
.and_then(|pending_splice| pending_splice.funding_negotiation.take())
1769+
.map(|funding_negotiation| {
1770+
let funding = funding_negotiation.as_funding();
1771+
SpliceFundingFailed {
17831772
channel_id: funded_channel.context.channel_id,
17841773
counterparty_node_id: funded_channel.context.counterparty_node_id,
17851774
user_channel_id: funded_channel.context.user_id,
1786-
funding_txo,
1787-
channel_type,
1788-
contributed_inputs,
1789-
contributed_outputs,
1790-
});
1791-
1792-
if let Some(FundingNegotiation::ConstructingTransaction { interactive_tx_constructor, .. }) = funding_negotiation {
1793-
Some(interactive_tx_constructor)
1794-
} else {
1795-
None
1775+
funding_txo: funding.as_ref().and_then(|funding| funding.get_funding_txo()).map(|txo| txo.into_bitcoin_outpoint()),
1776+
channel_type: funding.as_ref().map(|funding| funding.get_channel_type().clone()),
1777+
contributed_inputs: Vec::new(),
1778+
contributed_outputs: Vec::new(),
17961779
}
1797-
} else {
1798-
None
1799-
}
1800-
} else {
1801-
None
1802-
}
1780+
})
18031781
},
18041782
};
18051783

1806-
(reason.into_tx_abort_msg(self.context().channel_id), splice_failed)
1784+
(reason.into_tx_abort_msg(self.context().channel_id), splice_funding_failed)
18071785
}
18081786

18091787
pub fn tx_add_input<L: Deref>(
@@ -2024,18 +2002,20 @@ where
20242002
} = funding_negotiation
20252003
{
20262004
let signing_session = interactive_tx_constructor.into_signing_session();
2027-
let commitment_signed = chan.context.funding_tx_constructed(
2005+
let commitment_signed_result = chan.context.funding_tx_constructed(
20282006
&mut funding,
20292007
signing_session,
20302008
true,
20312009
chan.holder_commitment_point.next_transaction_number(),
20322010
&&logger,
2033-
)?;
2011+
);
20342012

2013+
// This must be set even if returning an Err. Otherwise,
2014+
// fail_interactive_tx_negotiation won't produce a SpliceFailed event.
20352015
pending_splice.funding_negotiation =
20362016
Some(FundingNegotiation::AwaitingSignatures { funding });
20372017

2038-
return Ok(commitment_signed);
2018+
return commitment_signed_result;
20392019
} else {
20402020
// Replace the taken state
20412021
pending_splice.funding_negotiation = Some(funding_negotiation);

0 commit comments

Comments
 (0)