Skip to content

Commit f18d7e7

Browse files
committed
Enter FundingNegotiated state after constructing funding tx
The ChannelState::NegotiatingFunding assertion check in ChannelContext::get_initial_commitment_signed will fail when implementing splicing's channel_reestablish logic. In order to support it and channel establishment, enter ChannelState::FundingNegotiated prior to calling the method and update the assertion accordingly.
1 parent d8e787f commit f18d7e7

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

lightning/src/ln/channel.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2960,6 +2960,8 @@ where
29602960
};
29612961
self.funding.channel_transaction_parameters.funding_outpoint = Some(outpoint);
29622962

2963+
self.context.channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
2964+
29632965
self.context.assert_no_commitment_advancement(transaction_number, "initial commitment_signed");
29642966
let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger);
29652967
let commitment_signed = match commitment_signed {
@@ -3008,13 +3010,10 @@ where
30083010
)));
30093011
};
30103012

3011-
let mut channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
3012-
channel_state.set_interactive_signing();
3013-
self.context.channel_state = channel_state;
3014-
30153013
// Clear the interactive transaction constructor
30163014
self.interactive_tx_constructor.take();
30173015
self.interactive_tx_signing_session = Some(signing_session);
3016+
self.context.channel_state.set_interactive_signing();
30183017

30193018
Ok((commitment_signed, funding_ready_for_sig_event))
30203019
}
@@ -5530,16 +5529,7 @@ where
55305529
SP::Target: SignerProvider,
55315530
L::Target: Logger
55325531
{
5533-
if !matches!(
5534-
self.channel_state, ChannelState::NegotiatingFunding(flags)
5535-
if flags == (NegotiatingFundingFlags::OUR_INIT_SENT | NegotiatingFundingFlags::THEIR_INIT_SENT)
5536-
) {
5537-
debug_assert!(false);
5538-
return Err(ChannelError::Close(("Tried to get an initial commitment_signed messsage at a time other than \
5539-
immediately after initial handshake completion (or tried to get funding_created twice)".to_string(),
5540-
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(true) }
5541-
)));
5542-
}
5532+
assert!(matches!(self.channel_state, ChannelState::FundingNegotiated(_)));
55435533

55445534
let signature = match self.get_initial_counterparty_commitment_signature(funding, logger) {
55455535
Ok(res) => res,

0 commit comments

Comments
 (0)