Skip to content

Commit 4a27e68

Browse files
committed
Avoid resetting splice state on FundingNegotiation::AwaitingSignatures
Otherwise, we won't ever be able to resume a pending negotiation after a reconnection via `channel_reestablish`. Along the way, we also merge `should_reset_pending_splice_state` into `PendingFunding::can_abandon_state` to simplify the logic around when we're able to reset specific parts of the pending splice state.
1 parent c256fa4 commit 4a27e68

File tree

2 files changed

+29
-57
lines changed

2 files changed

+29
-57
lines changed

lightning/src/ln/channel.rs

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,8 +1694,7 @@ where
16941694
pending_v2_channel.interactive_tx_constructor.take();
16951695
},
16961696
ChannelPhase::Funded(funded_channel) => {
1697-
if funded_channel.should_reset_pending_splice_funding_negotiation().unwrap_or(true)
1698-
{
1697+
if funded_channel.should_reset_pending_splice_state() {
16991698
funded_channel.reset_pending_splice_state();
17001699
} else {
17011700
debug_assert!(false, "We should never fail an interactive funding negotiation once we're exchanging tx_signatures");
@@ -1829,8 +1828,10 @@ where
18291828
pending_v2_channel.interactive_tx_constructor.take().is_some()
18301829
},
18311830
ChannelPhase::Funded(funded_channel) => {
1832-
if let Some(should_reset) =
1833-
funded_channel.should_reset_pending_splice_funding_negotiation()
1831+
if let Some(should_reset) = funded_channel
1832+
.pending_splice
1833+
.as_ref()
1834+
.map(|pending_splice| pending_splice.can_abandon_state())
18341835
{
18351836
if should_reset {
18361837
// We may have still tracked the pending funding negotiation state, so we
@@ -2583,13 +2584,13 @@ impl FundingNegotiation {
25832584
}
25842585

25852586
impl PendingFunding {
2586-
fn can_abandon_funding_negotiation(&self) -> bool {
2587+
fn can_abandon_state(&self) -> bool {
25872588
self.funding_negotiation
25882589
.as_ref()
25892590
.map(|funding_negotiation| {
25902591
!matches!(funding_negotiation, FundingNegotiation::AwaitingSignatures { .. })
25912592
})
2592-
.unwrap_or(true)
2593+
.unwrap_or(self.negotiated_candidates.is_empty())
25932594
}
25942595

25952596
fn check_get_splice_locked<SP: Deref>(
@@ -6773,40 +6774,25 @@ where
67736774
)
67746775
}
67756776

6776-
/// Returns `None` if there is no [`FundedChannel::pending_splice`], otherwise a boolean
6777-
/// indicating whether we should reset the splice's [`PendingFunding::funding_negotiation`].
6778-
fn should_reset_pending_splice_funding_negotiation(&self) -> Option<bool> {
6779-
self.pending_splice.as_ref().map(|pending_splice| {
6780-
if pending_splice.can_abandon_funding_negotiation() {
6781-
true
6782-
} else {
6783-
self.context
6784-
.interactive_tx_signing_session
6785-
.as_ref()
6786-
.map(|signing_session| !signing_session.has_received_commitment_signed())
6787-
.unwrap_or_else(|| {
6788-
debug_assert!(false);
6789-
false
6790-
})
6791-
}
6792-
})
6793-
}
6794-
6777+
/// Returns a boolean indicating whether we should reset the splice's
6778+
/// [`PendingFunding::funding_negotiation`].
67956779
fn should_reset_pending_splice_state(&self) -> bool {
6796-
self.should_reset_pending_splice_funding_negotiation().unwrap_or(true)
6797-
&& self.pending_funding().is_empty()
6780+
self.pending_splice
6781+
.as_ref()
6782+
.map(|pending_splice| pending_splice.can_abandon_state())
6783+
.unwrap_or(true)
67986784
}
67996785

68006786
fn reset_pending_splice_state(&mut self) -> bool {
6801-
debug_assert!(self.should_reset_pending_splice_funding_negotiation().unwrap_or(true));
6787+
debug_assert!(self.should_reset_pending_splice_state());
68026788
self.context.channel_state.clear_quiescent();
68036789
self.context.interactive_tx_signing_session.take();
68046790
let has_funding_negotiation = self
68056791
.pending_splice
68066792
.as_mut()
68076793
.and_then(|pending_splice| pending_splice.funding_negotiation.take())
68086794
.is_some();
6809-
if self.should_reset_pending_splice_state() {
6795+
if self.pending_funding().is_empty() {
68106796
self.pending_splice.take();
68116797
}
68126798
has_funding_negotiation
@@ -8948,7 +8934,7 @@ where
89488934
}
89498935
self.context.channel_state.clear_local_stfu_sent();
89508936
self.context.channel_state.clear_remote_stfu_sent();
8951-
if self.should_reset_pending_splice_funding_negotiation().unwrap_or(true) {
8937+
if self.should_reset_pending_splice_state() {
89528938
// If we were in quiescence but a splice was never negotiated, or the negotiation
89538939
// failed due to disconnecting, we shouldn't be quiescent anymore upon reconnecting.
89548940
// If there was a pending splice negotiation that has failed due to disconnecting,
@@ -14021,7 +14007,7 @@ where
1402114007
}
1402214008
channel_state.clear_local_stfu_sent();
1402314009
channel_state.clear_remote_stfu_sent();
14024-
if self.should_reset_pending_splice_funding_negotiation().unwrap_or(true) {
14010+
if self.should_reset_pending_splice_state() {
1402514011
// If we were in quiescence but a splice was never negotiated, or the
1402614012
// negotiation failed due to disconnecting, we shouldn't be quiescent
1402714013
// anymore upon reconnecting.
@@ -14389,19 +14375,14 @@ where
1438914375
let holder_commitment_point_next = self.holder_commitment_point.next_point();
1439014376
let holder_commitment_point_pending_next = self.holder_commitment_point.pending_next_point;
1439114377

14392-
let interactive_tx_signing_session =
14393-
if self.should_reset_pending_splice_funding_negotiation().unwrap_or(false) {
14394-
None
14378+
let (interactive_tx_signing_session, pending_splice) =
14379+
if self.should_reset_pending_splice_state() {
14380+
(None, None)
1439514381
} else {
14396-
self.context.interactive_tx_signing_session.as_ref()
14382+
// We don't have to worry about resetting the pending `FundingNegotiation` because we
14383+
// can only read `FundingNegotiation::AwaitingSignatures` variants anyway.
14384+
(self.context.interactive_tx_signing_session.as_ref(), self.pending_splice.as_ref())
1439714385
};
14398-
let pending_splice = if self.should_reset_pending_splice_state() {
14399-
None
14400-
} else {
14401-
// We don't have to worry about resetting the pending `FundingNegotiation` because we
14402-
// can only read `FundingNegotiation::AwaitingSignatures` variants anyway.
14403-
self.pending_splice.as_ref()
14404-
};
1440514386

1440614387
write_tlv_fields!(writer, {
1440714388
(0, self.context.announcement_sigs, option),

lightning/src/ln/splicing_tests.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,9 @@ fn do_test_splice_state_reset_on_disconnect(reload: bool) {
414414
)
415415
.unwrap();
416416

417-
// Attempt a splice negotiation that only goes up to exchanging `tx_complete`. Reconnecting
418-
// should implicitly abort the negotiation and reset the splice state such that we're able to
419-
// retry another splice later.
417+
// Attempt a splice negotiation that ends mid-construction of the funding transaction.
418+
// Reconnecting should implicitly abort the negotiation and reset the splice state such that
419+
// we're able to retry another splice later.
420420
let stfu = get_event_msg!(nodes[0], MessageSendEvent::SendStfu, node_id_1);
421421
nodes[1].node.handle_stfu(node_id_0, &stfu);
422422
let stfu = get_event_msg!(nodes[1], MessageSendEvent::SendStfu, node_id_0);
@@ -427,18 +427,9 @@ fn do_test_splice_state_reset_on_disconnect(reload: bool) {
427427
let splice_ack = get_event_msg!(nodes[1], MessageSendEvent::SendSpliceAck, node_id_0);
428428
nodes[0].node.handle_splice_ack(node_id_1, &splice_ack);
429429

430-
let new_funding_script = chan_utils::make_funding_redeemscript(
431-
&splice_init.funding_pubkey,
432-
&splice_ack.funding_pubkey,
433-
)
434-
.to_p2wsh();
435-
let _ = complete_interactive_funding_negotiation(
436-
&nodes[0],
437-
&nodes[1],
438-
channel_id,
439-
contribution.clone(),
440-
new_funding_script,
441-
);
430+
let tx_add_input = get_event_msg!(nodes[0], MessageSendEvent::SendTxAddInput, node_id_1);
431+
nodes[1].node.handle_tx_add_input(node_id_0, &tx_add_input);
432+
let _ = get_event_msg!(nodes[1], MessageSendEvent::SendTxComplete, node_id_0);
442433

443434
if reload {
444435
let encoded_monitor_0 = get_monitor!(nodes[0], channel_id).encode();

0 commit comments

Comments
 (0)