Skip to content

Commit 48a0862

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. Also allows writing a channel in the FundedNegotiated state when an interactive signing session is active. This is necessary as it indicates a previously funded channel being spliced.
1 parent 61e5819 commit 48a0862

File tree

2 files changed

+6
-37
lines changed

2 files changed

+6
-37
lines changed

lightning/src/ln/channel.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5517,6 +5517,9 @@ where
55175517
funding
55185518
.channel_transaction_parameters.funding_outpoint = Some(outpoint);
55195519

5520+
self.channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
5521+
self.channel_state.set_interactive_signing();
5522+
55205523
if is_splice {
55215524
debug_assert_eq!(
55225525
holder_commitment_transaction_number,
@@ -5580,10 +5583,6 @@ where
55805583
});
55815584
};
55825585

5583-
let mut channel_state = ChannelState::FundingNegotiated(FundingNegotiatedFlags::new());
5584-
channel_state.set_interactive_signing();
5585-
self.channel_state = channel_state;
5586-
55875586
Ok((commitment_signed, funding_ready_for_sig_event))
55885587
}
55895588

@@ -5636,16 +5635,7 @@ where
56365635
SP::Target: SignerProvider,
56375636
L::Target: Logger
56385637
{
5639-
if !matches!(
5640-
self.channel_state, ChannelState::NegotiatingFunding(flags)
5641-
if flags == (NegotiatingFundingFlags::OUR_INIT_SENT | NegotiatingFundingFlags::THEIR_INIT_SENT)
5642-
) {
5643-
debug_assert!(false);
5644-
let msg = "Tried to get an initial commitment_signed messsage at a time other than \
5645-
immediately after initial handshake completion (or tried to get funding_created twice)";
5646-
let reason = ClosureReason::ProcessingError { err: msg.to_owned() };
5647-
return Err(ChannelError::Close((msg.to_owned(), reason)));
5648-
}
5638+
assert!(matches!(self.channel_state, ChannelState::FundingNegotiated(flags) if flags.is_interactive_signing()));
56495639

56505640
let signature = match self.get_initial_counterparty_commitment_signature(funding, logger) {
56515641
Ok(res) => res,
@@ -12880,6 +12870,7 @@ where
1288012870
channel_state.clear_remote_stfu_sent();
1288112871
channel_state.clear_quiescent();
1288212872
},
12873+
ChannelState::FundingNegotiated(flags) if flags.is_interactive_signing() => {},
1288312874
_ => debug_assert!(false, "Pre-funded/shutdown channels should not be written"),
1288412875
}
1288512876
channel_state.set_peer_disconnected();

lightning/src/ln/splicing_tests.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -274,29 +274,7 @@ fn test_v1_splice_in() {
274274
_ => panic!("Unexpected event {:?}", events[1]),
275275
}
276276

277-
// TODO(splicing): Continue with commitment flow, new tx confirmation
278-
279-
// === Close channel, cooperatively
280-
initiator_node.node.close_channel(&channel_id, &acceptor_node.node.get_our_node_id()).unwrap();
281-
let node0_shutdown_message = get_event_msg!(
282-
initiator_node,
283-
MessageSendEvent::SendShutdown,
284-
acceptor_node.node.get_our_node_id()
285-
);
286-
acceptor_node
287-
.node
288-
.handle_shutdown(initiator_node.node.get_our_node_id(), &node0_shutdown_message);
289-
let nodes_1_shutdown = get_event_msg!(
290-
acceptor_node,
291-
MessageSendEvent::SendShutdown,
292-
initiator_node.node.get_our_node_id()
293-
);
294-
initiator_node.node.handle_shutdown(acceptor_node.node.get_our_node_id(), &nodes_1_shutdown);
295-
let _ = get_event_msg!(
296-
initiator_node,
297-
MessageSendEvent::SendClosingSigned,
298-
acceptor_node.node.get_our_node_id()
299-
);
277+
// TODO(splicing): Continue with commitment flow, new tx confirmation, and shutdown
300278
}
301279

302280
#[test]

0 commit comments

Comments
 (0)