Skip to content

Commit 71ffb50

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 1047dcd commit 71ffb50

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

lightning/src/ln/channel.rs

Lines changed: 47 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
@@ -8350,6 +8355,7 @@ where
83508355
shutdown_msg, announcement_sigs,
83518356
tx_signatures: None,
83528357
tx_abort: None,
8358+
splice_locked: None,
83538359
});
83548360
}
83558361

@@ -8361,6 +8367,7 @@ where
83618367
shutdown_msg, announcement_sigs,
83628368
tx_signatures: None,
83638369
tx_abort: None,
8370+
splice_locked: None,
83648371
});
83658372
}
83668373

@@ -8406,6 +8413,25 @@ where
84068413
.and_then(|_| self.get_channel_ready(logger))
84078414
} else { None };
84088415

8416+
// A receiving node:
8417+
// - if `your_last_funding_locked` is set and it does not match the most recent
8418+
// `splice_locked` it has sent:
8419+
// - MUST retransmit `splice_locked`.
8420+
let sent_splice_txid = self
8421+
.maybe_get_my_current_funding_locked()
8422+
.filter(|funding| funding.is_splice())
8423+
.map(|funding| {
8424+
funding.get_funding_txid().expect("Splice funding_txid should always be set")
8425+
});
8426+
let splice_locked = msg.your_last_funding_locked_txid.and_then(|last_funding_txid| {
8427+
sent_splice_txid
8428+
.filter(|sent_splice_txid| last_funding_txid != *sent_splice_txid)
8429+
.map(|splice_txid| msgs::SpliceLocked {
8430+
channel_id: self.context.channel_id,
8431+
splice_txid,
8432+
})
8433+
});
8434+
84098435
let mut commitment_update = None;
84108436
let mut tx_signatures = None;
84118437
let mut tx_abort = None;
@@ -8518,6 +8544,7 @@ where
85188544
order: self.context.resend_order.clone(),
85198545
tx_signatures,
85208546
tx_abort,
8547+
splice_locked,
85218548
})
85228549
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
85238550
// We've made an update so we must have exchanged `tx_signatures`, implying that
@@ -8539,6 +8566,7 @@ where
85398566
order: self.context.resend_order.clone(),
85408567
tx_signatures,
85418568
tx_abort,
8569+
splice_locked,
85428570
})
85438571
} else {
85448572
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -8563,6 +8591,7 @@ where
85638591
order: self.context.resend_order.clone(),
85648592
tx_signatures,
85658593
tx_abort,
8594+
splice_locked,
85668595
})
85678596
}
85688597
} else if msg.next_local_commitment_number < next_counterparty_commitment_number {
@@ -10196,6 +10225,24 @@ where
1019610225
None
1019710226
}
1019810227

10228+
#[cfg(splicing)]
10229+
fn maybe_get_my_current_funding_locked(&self) -> Option<&FundingScope> {
10230+
self.pending_splice
10231+
.as_ref()
10232+
.and_then(|pending_splice| pending_splice.sent_funding_txid)
10233+
.and_then(|funding_txid| {
10234+
self.pending_funding
10235+
.iter()
10236+
.find(|funding| funding.get_funding_txid() == Some(funding_txid))
10237+
})
10238+
.or_else(|| self.is_our_channel_ready().then(|| &self.funding))
10239+
}
10240+
10241+
#[cfg(not(splicing))]
10242+
fn maybe_get_my_current_funding_locked(&self) -> Option<&FundingScope> {
10243+
None
10244+
}
10245+
1019910246
#[cfg(splicing)]
1020010247
fn maybe_get_my_current_funding_locked_txid(&self) -> Option<Txid> {
1020110248
self.pending_splice

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)