Skip to content

Commit accaa9f

Browse files
committed
Send splice_locked on channel_reestablish
The channel_reestablish protocol supports retransmitting splice_locked messages as needed. Add support for doing such when handling channel_reestablish messages.
1 parent 02ec193 commit accaa9f

File tree

2 files changed

+68
-3
lines changed

2 files changed

+68
-3
lines changed

lightning/src/ln/channel.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,7 @@ pub(super) struct ReestablishResponses {
12161216
pub shutdown_msg: Option<msgs::Shutdown>,
12171217
pub tx_signatures: Option<msgs::TxSignatures>,
12181218
pub tx_abort: Option<msgs::TxAbort>,
1219+
pub splice_locked: Option<msgs::SpliceLocked>,
12191220
}
12201221

12211222
/// The first message we send to our peer after connection
@@ -2172,6 +2173,10 @@ impl FundingScope {
21722173
pub fn get_short_channel_id(&self) -> Option<u64> {
21732174
self.short_channel_id
21742175
}
2176+
2177+
fn is_splice(&self) -> bool {
2178+
self.channel_transaction_parameters.splice_parent_funding_txid.is_some()
2179+
}
21752180
}
21762181

21772182
/// Info about a pending splice, used in the pre-splice channel
@@ -8349,6 +8354,7 @@ where
83498354
shutdown_msg, announcement_sigs,
83508355
tx_signatures: None,
83518356
tx_abort: None,
8357+
splice_locked: None,
83528358
});
83538359
}
83548360

@@ -8360,6 +8366,7 @@ where
83608366
shutdown_msg, announcement_sigs,
83618367
tx_signatures: None,
83628368
tx_abort: None,
8369+
splice_locked: None,
83638370
});
83648371
}
83658372

@@ -8405,6 +8412,25 @@ where
84058412
.and_then(|_| self.get_channel_ready(logger))
84068413
} else { None };
84078414

8415+
// A receiving node:
8416+
// - if `your_last_funding_locked` is set and it does not match the most recent
8417+
// `splice_locked` it has sent:
8418+
// - MUST retransmit `splice_locked`.
8419+
let sent_splice_txid = self
8420+
.maybe_get_my_current_funding_locked(their_features)
8421+
.filter(|funding| funding.is_splice())
8422+
.map(|funding| {
8423+
funding.get_funding_txid().expect("Splice funding_txid should always be set")
8424+
});
8425+
let splice_locked = msg.your_last_funding_locked_txid.and_then(|last_funding_txid| {
8426+
sent_splice_txid
8427+
.filter(|sent_splice_txid| last_funding_txid != *sent_splice_txid)
8428+
.map(|splice_txid| msgs::SpliceLocked {
8429+
channel_id: self.context.channel_id,
8430+
splice_txid,
8431+
})
8432+
});
8433+
84088434
let mut commitment_update = None;
84098435
let mut tx_signatures = None;
84108436
let mut tx_abort = None;
@@ -8517,6 +8543,7 @@ where
85178543
order: self.context.resend_order.clone(),
85188544
tx_signatures,
85198545
tx_abort,
8546+
splice_locked,
85208547
})
85218548
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
85228549
// We've made an update so we must have exchanged `tx_signatures`, implying that
@@ -8538,6 +8565,7 @@ where
85388565
order: self.context.resend_order.clone(),
85398566
tx_signatures,
85408567
tx_abort,
8568+
splice_locked,
85418569
})
85428570
} else {
85438571
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -8562,6 +8590,7 @@ where
85628590
order: self.context.resend_order.clone(),
85638591
tx_signatures,
85648592
tx_abort,
8593+
splice_locked,
85658594
})
85668595
}
85678596
} else if msg.next_local_commitment_number < next_counterparty_commitment_number {
@@ -10193,6 +10222,32 @@ where
1019310222
None
1019410223
}
1019510224

10225+
#[cfg(splicing)]
10226+
fn maybe_get_my_current_funding_locked(
10227+
&self, features: &InitFeatures,
10228+
) -> Option<&FundingScope> {
10229+
if !features.supports_splicing() {
10230+
return None;
10231+
}
10232+
10233+
self.pending_splice
10234+
.as_ref()
10235+
.and_then(|pending_splice| pending_splice.sent_funding_txid)
10236+
.and_then(|funding_txid| {
10237+
self.pending_funding
10238+
.iter()
10239+
.find(|funding| funding.get_funding_txid() == Some(funding_txid))
10240+
})
10241+
.or_else(|| self.is_our_channel_ready().then(|| &self.funding))
10242+
}
10243+
10244+
#[cfg(not(splicing))]
10245+
fn maybe_get_my_current_funding_locked(
10246+
&self, _features: &InitFeatures,
10247+
) -> Option<&FundingScope> {
10248+
None
10249+
}
10250+
1019610251
#[cfg(splicing)]
1019710252
fn maybe_get_my_current_funding_locked_txid(&self, features: &InitFeatures) -> Option<Txid> {
1019810253
if !features.supports_splicing() {

lightning/src/ln/channelmanager.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3408,7 +3408,8 @@ macro_rules! handle_monitor_update_completion {
34083408
&mut $peer_state.pending_msg_events, $chan, updates.raa,
34093409
updates.commitment_update, updates.order, updates.accepted_htlcs, updates.pending_update_adds,
34103410
updates.funding_broadcastable, updates.channel_ready,
3411-
updates.announcement_sigs, updates.tx_signatures, None);
3411+
updates.announcement_sigs, updates.tx_signatures, None, None,
3412+
);
34123413
if let Some(upd) = channel_update {
34133414
$peer_state.pending_msg_events.push(upd);
34143415
}
@@ -8088,9 +8089,10 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
80888089
funding_broadcastable: Option<Transaction>,
80898090
channel_ready: Option<msgs::ChannelReady>, announcement_sigs: Option<msgs::AnnouncementSignatures>,
80908091
tx_signatures: Option<msgs::TxSignatures>, tx_abort: Option<msgs::TxAbort>,
8092+
splice_locked: Option<msgs::SpliceLocked>,
80918093
) -> (Option<(u64, Option<PublicKey>, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)>, Option<(u64, Vec<msgs::UpdateAddHTLC>)>) {
80928094
let logger = WithChannelContext::from(&self.logger, &channel.context, None);
8093-
log_trace!(logger, "Handling channel resumption for channel {} with {} RAA, {} commitment update, {} pending forwards, {} pending update_add_htlcs, {}broadcasting funding, {} channel ready, {} announcement, {} tx_signatures, {} tx_abort",
8095+
log_trace!(logger, "Handling channel resumption for channel {} with {} RAA, {} commitment update, {} pending forwards, {} pending update_add_htlcs, {}broadcasting funding, {} channel ready, {} announcement, {} tx_signatures, {} tx_abort, {} splice_locked",
80948096
&channel.context.channel_id(),
80958097
if raa.is_some() { "an" } else { "no" },
80968098
if commitment_update.is_some() { "a" } else { "no" },
@@ -8100,6 +8102,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
81008102
if announcement_sigs.is_some() { "sending" } else { "without" },
81018103
if tx_signatures.is_some() { "sending" } else { "without" },
81028104
if tx_abort.is_some() { "sending" } else { "without" },
8105+
if splice_locked.is_some() { "sending" } else { "without" },
81038106
);
81048107

81058108
let counterparty_node_id = channel.context.get_counterparty_node_id();
@@ -8139,6 +8142,12 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
81398142
msg,
81408143
});
81418144
}
8145+
if let Some(msg) = splice_locked {
8146+
pending_msg_events.push(MessageSendEvent::SendSpliceLocked {
8147+
node_id: counterparty_node_id,
8148+
msg,
8149+
});
8150+
}
81428151

81438152
macro_rules! handle_cs { () => {
81448153
if let Some(update) = commitment_update {
@@ -10083,7 +10092,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1008310092
let (htlc_forwards, decode_update_add_htlcs) = self.handle_channel_resumption(
1008410093
&mut peer_state.pending_msg_events, chan, responses.raa, responses.commitment_update, responses.order,
1008510094
Vec::new(), Vec::new(), None, responses.channel_ready, responses.announcement_sigs,
10086-
responses.tx_signatures, responses.tx_abort);
10095+
responses.tx_signatures, responses.tx_abort, responses.splice_locked,
10096+
);
1008710097
debug_assert!(htlc_forwards.is_none());
1008810098
debug_assert!(decode_update_add_htlcs.is_none());
1008910099
if let Some(upd) = channel_update {

0 commit comments

Comments
 (0)