Skip to content

Commit 689aec2

Browse files
wpaulinoTheBlueMatt
authored andcommitted
Break up ChannelContext::funding_tx_constructed
This method was originally intended to DRY the logic between `FundedChannel` and `PendingChannelV2` when handling `funding_tx_constructed`, though it's not very useful anymore. Backport of 25264d7
1 parent 883142b commit 689aec2

File tree

1 file changed

+31
-44
lines changed

1 file changed

+31
-44
lines changed

lightning/src/ln/channel.rs

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,18 +2019,32 @@ where
20192019
| NegotiatingFundingFlags::THEIR_INIT_SENT
20202020
),
20212021
);
2022+
chan.context.assert_no_commitment_advancement(
2023+
chan.unfunded_context.transaction_number(),
2024+
"initial commitment_signed",
2025+
);
2026+
2027+
chan.context.channel_state =
2028+
ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
2029+
chan.funding.channel_transaction_parameters.funding_outpoint =
2030+
Some(funding_outpoint);
20222031

20232032
let interactive_tx_constructor = chan
20242033
.interactive_tx_constructor
20252034
.take()
20262035
.expect("PendingV2Channel::interactive_tx_constructor should be set");
2027-
let commitment_signed = chan.context.funding_tx_constructed(
2028-
&mut chan.funding,
2029-
funding_outpoint,
2030-
false,
2031-
chan.unfunded_context.transaction_number(),
2032-
&&logger,
2033-
)?;
2036+
2037+
let commitment_signed =
2038+
chan.context.get_initial_commitment_signed_v2(&chan.funding, &&logger);
2039+
let commitment_signed = match commitment_signed {
2040+
Some(commitment_signed) => commitment_signed,
2041+
// TODO(dual_funding): Support async signing
2042+
None => {
2043+
return Err(AbortReason::InternalError(
2044+
"Failed to compute commitment_signed signatures",
2045+
));
2046+
},
2047+
};
20342048

20352049
(interactive_tx_constructor, commitment_signed)
20362050
},
@@ -2059,14 +2073,11 @@ where
20592073
)
20602074
})
20612075
.and_then(|(is_initiator, mut funding, interactive_tx_constructor)| {
2062-
match chan.context.funding_tx_constructed(
2063-
&mut funding,
2064-
funding_outpoint,
2065-
true,
2066-
chan.holder_commitment_point.next_transaction_number(),
2067-
&&logger,
2068-
) {
2069-
Ok(commitment_signed) => {
2076+
funding.channel_transaction_parameters.funding_outpoint =
2077+
Some(funding_outpoint);
2078+
match chan.context.get_initial_commitment_signed_v2(&funding, &&logger)
2079+
{
2080+
Some(commitment_signed) => {
20702081
// Advance the state
20712082
pending_splice.funding_negotiation =
20722083
Some(FundingNegotiation::AwaitingSignatures {
@@ -2075,14 +2086,17 @@ where
20752086
});
20762087
Ok((interactive_tx_constructor, commitment_signed))
20772088
},
2078-
Err(e) => {
2089+
// TODO(splicing): Support async signing
2090+
None => {
20792091
// Restore the taken state for later error handling
20802092
pending_splice.funding_negotiation =
20812093
Some(FundingNegotiation::ConstructingTransaction {
20822094
funding,
20832095
interactive_tx_constructor,
20842096
});
2085-
Err(e)
2097+
Err(AbortReason::InternalError(
2098+
"Failed to compute commitment_signed signatures",
2099+
))
20862100
},
20872101
}
20882102
})?
@@ -6203,33 +6217,6 @@ where
62036217
Ok(())
62046218
}
62056219

6206-
#[rustfmt::skip]
6207-
fn funding_tx_constructed<L: Deref>(
6208-
&mut self, funding: &mut FundingScope, funding_outpoint: OutPoint, is_splice: bool,
6209-
holder_commitment_transaction_number: u64, logger: &L,
6210-
) -> Result<msgs::CommitmentSigned, AbortReason>
6211-
where
6212-
L::Target: Logger
6213-
{
6214-
funding.channel_transaction_parameters.funding_outpoint = Some(funding_outpoint);
6215-
6216-
if !is_splice {
6217-
self.assert_no_commitment_advancement(holder_commitment_transaction_number, "initial commitment_signed");
6218-
self.channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
6219-
}
6220-
6221-
let commitment_signed = self.get_initial_commitment_signed_v2(&funding, logger);
6222-
let commitment_signed = match commitment_signed {
6223-
Some(commitment_signed) => commitment_signed,
6224-
// TODO(splicing): Support async signing
6225-
None => {
6226-
return Err(AbortReason::InternalError("Failed to compute commitment_signed signatures"));
6227-
},
6228-
};
6229-
6230-
Ok(commitment_signed)
6231-
}
6232-
62336220
/// Asserts that the commitment tx numbers have not advanced from their initial number.
62346221
fn assert_no_commitment_advancement(
62356222
&self, holder_commitment_transaction_number: u64, msg_name: &str,

0 commit comments

Comments
 (0)