Skip to content

Commit c661cb5

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 555ab97 commit c661cb5

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
@@ -8361,6 +8366,7 @@ where
83618366
shutdown_msg, announcement_sigs,
83628367
tx_signatures: None,
83638368
tx_abort: None,
8369+
splice_locked: None,
83648370
});
83658371
}
83668372

@@ -8372,6 +8378,7 @@ where
83728378
shutdown_msg, announcement_sigs,
83738379
tx_signatures: None,
83748380
tx_abort: None,
8381+
splice_locked: None,
83758382
});
83768383
}
83778384

@@ -8417,6 +8424,25 @@ where
84178424
.and_then(|_| self.get_channel_ready(logger))
84188425
} else { None };
84198426

8427+
// A receiving node:
8428+
// - if `your_last_funding_locked` is set and it does not match the most recent
8429+
// `splice_locked` it has sent:
8430+
// - MUST retransmit `splice_locked`.
8431+
let sent_splice_txid = self
8432+
.maybe_get_my_current_funding_locked(features)
8433+
.filter(|funding| funding.is_splice())
8434+
.map(|funding| {
8435+
funding.get_funding_txid().expect("Splice funding_txid should always be set")
8436+
});
8437+
let splice_locked = msg.your_last_funding_locked_txid.and_then(|last_funding_txid| {
8438+
sent_splice_txid
8439+
.filter(|sent_splice_txid| last_funding_txid != *sent_splice_txid)
8440+
.map(|splice_txid| msgs::SpliceLocked {
8441+
channel_id: self.context.channel_id,
8442+
splice_txid,
8443+
})
8444+
});
8445+
84208446
let mut commitment_update = None;
84218447
let mut tx_signatures = None;
84228448
let mut tx_abort = None;
@@ -8523,6 +8549,7 @@ where
85238549
order: self.context.resend_order.clone(),
85248550
tx_signatures,
85258551
tx_abort,
8552+
splice_locked,
85268553
})
85278554
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
85288555
// We've made an update so we must have exchanged `tx_signatures`, implying that
@@ -8544,6 +8571,7 @@ where
85448571
order: self.context.resend_order.clone(),
85458572
tx_signatures,
85468573
tx_abort,
8574+
splice_locked,
85478575
})
85488576
} else {
85498577
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -8568,6 +8596,7 @@ where
85688596
order: self.context.resend_order.clone(),
85698597
tx_signatures,
85708598
tx_abort,
8599+
splice_locked,
85718600
})
85728601
}
85738602
} else if msg.next_local_commitment_number < next_counterparty_commitment_number {
@@ -10197,6 +10226,32 @@ where
1019710226
None
1019810227
}
1019910228

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