Skip to content

Commit 6fb15b8

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 fd7d12b commit 6fb15b8

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

lightning/src/ln/channel.rs

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

12201221
/// The first message we send to our peer after connection
@@ -2241,6 +2242,11 @@ impl FundingScope {
22412242
self.short_channel_id
22422243
}
22432244

2245+
/// Returns whether the `FundingScope` is for splicing a channel.
2246+
fn is_splice(&self) -> bool {
2247+
self.channel_transaction_parameters.splice_parent_funding_txid.is_some()
2248+
}
2249+
22442250
/// Constructs a `FundingScope` for splicing a channel.
22452251
#[cfg(splicing)]
22462252
fn for_splice<SP: Deref>(
@@ -8755,6 +8761,7 @@ where
87558761
shutdown_msg, announcement_sigs,
87568762
tx_signatures: None,
87578763
tx_abort: None,
8764+
splice_locked: None,
87588765
});
87598766
}
87608767

@@ -8766,6 +8773,7 @@ where
87668773
shutdown_msg, announcement_sigs,
87678774
tx_signatures: None,
87688775
tx_abort: None,
8776+
splice_locked: None,
87698777
});
87708778
}
87718779

@@ -8813,6 +8821,25 @@ where
88138821
.and_then(|_| self.get_channel_ready(logger))
88148822
} else { None };
88158823

8824+
// A receiving node:
8825+
// - if `your_last_funding_locked` is set and it does not match the most recent
8826+
// `splice_locked` it has sent:
8827+
// - MUST retransmit `splice_locked`.
8828+
let sent_splice_txid = self
8829+
.maybe_get_my_current_funding_locked()
8830+
.filter(|funding| funding.is_splice())
8831+
.map(|funding| {
8832+
funding.get_funding_txid().expect("Splice funding_txid should always be set")
8833+
});
8834+
let splice_locked = msg.your_last_funding_locked_txid.and_then(|last_funding_txid| {
8835+
sent_splice_txid
8836+
.filter(|sent_splice_txid| last_funding_txid != *sent_splice_txid)
8837+
.map(|splice_txid| msgs::SpliceLocked {
8838+
channel_id: self.context.channel_id,
8839+
splice_txid,
8840+
})
8841+
});
8842+
88168843
let mut commitment_update = None;
88178844
let mut tx_signatures = None;
88188845
let mut tx_abort = None;
@@ -8927,6 +8954,7 @@ where
89278954
order: self.context.resend_order.clone(),
89288955
tx_signatures,
89298956
tx_abort,
8957+
splice_locked,
89308958
})
89318959
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
89328960
// We've made an update so we must have exchanged `tx_signatures`, implying that
@@ -8948,6 +8976,7 @@ where
89488976
order: self.context.resend_order.clone(),
89498977
tx_signatures,
89508978
tx_abort,
8979+
splice_locked,
89518980
})
89528981
} else {
89538982
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -8972,6 +9001,7 @@ where
89729001
order: self.context.resend_order.clone(),
89739002
tx_signatures,
89749003
tx_abort,
9004+
splice_locked,
89759005
})
89769006
}
89779007
} else if msg.next_local_commitment_number < next_counterparty_commitment_number {
@@ -10627,6 +10657,24 @@ where
1062710657
None
1062810658
}
1062910659

10660+
#[cfg(splicing)]
10661+
fn maybe_get_my_current_funding_locked(&self) -> Option<&FundingScope> {
10662+
self.pending_splice
10663+
.as_ref()
10664+
.and_then(|pending_splice| pending_splice.sent_funding_txid)
10665+
.and_then(|funding_txid| {
10666+
self.pending_funding
10667+
.iter()
10668+
.find(|funding| funding.get_funding_txid() == Some(funding_txid))
10669+
})
10670+
.or_else(|| self.is_our_channel_ready().then(|| &self.funding))
10671+
}
10672+
10673+
#[cfg(not(splicing))]
10674+
fn maybe_get_my_current_funding_locked(&self) -> Option<&FundingScope> {
10675+
None
10676+
}
10677+
1063010678
#[cfg(splicing)]
1063110679
fn maybe_get_my_current_funding_locked_txid(&self) -> Option<Txid> {
1063210680
self.pending_splice

lightning/src/ln/channelmanager.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3380,7 +3380,8 @@ macro_rules! handle_monitor_update_completion {
33803380
&mut $peer_state.pending_msg_events, $chan, updates.raa,
33813381
updates.commitment_update, updates.order, updates.accepted_htlcs, updates.pending_update_adds,
33823382
updates.funding_broadcastable, updates.channel_ready,
3383-
updates.announcement_sigs, updates.tx_signatures, None);
3383+
updates.announcement_sigs, updates.tx_signatures, None, None,
3384+
);
33843385
if let Some(upd) = channel_update {
33853386
$peer_state.pending_msg_events.push(upd);
33863387
}
@@ -8756,9 +8757,10 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
87568757
funding_broadcastable: Option<Transaction>,
87578758
channel_ready: Option<msgs::ChannelReady>, announcement_sigs: Option<msgs::AnnouncementSignatures>,
87588759
tx_signatures: Option<msgs::TxSignatures>, tx_abort: Option<msgs::TxAbort>,
8760+
splice_locked: Option<msgs::SpliceLocked>,
87598761
) -> (Option<(u64, Option<PublicKey>, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)>, Option<(u64, Vec<msgs::UpdateAddHTLC>)>) {
87608762
let logger = WithChannelContext::from(&self.logger, &channel.context, None);
8761-
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",
8763+
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",
87628764
&channel.context.channel_id(),
87638765
if raa.is_some() { "an" } else { "no" },
87648766
if commitment_update.is_some() { "a" } else { "no" },
@@ -8768,6 +8770,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
87688770
if announcement_sigs.is_some() { "sending" } else { "without" },
87698771
if tx_signatures.is_some() { "sending" } else { "without" },
87708772
if tx_abort.is_some() { "sending" } else { "without" },
8773+
if splice_locked.is_some() { "sending" } else { "without" },
87718774
);
87728775

87738776
let counterparty_node_id = channel.context.get_counterparty_node_id();
@@ -8807,6 +8810,12 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
88078810
msg,
88088811
});
88098812
}
8813+
if let Some(msg) = splice_locked {
8814+
pending_msg_events.push(MessageSendEvent::SendSpliceLocked {
8815+
node_id: counterparty_node_id,
8816+
msg,
8817+
});
8818+
}
88108819

88118820
macro_rules! handle_cs { () => {
88128821
if let Some(update) = commitment_update {
@@ -10815,7 +10824,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1081510824
let (htlc_forwards, decode_update_add_htlcs) = self.handle_channel_resumption(
1081610825
&mut peer_state.pending_msg_events, chan, responses.raa, responses.commitment_update, responses.order,
1081710826
Vec::new(), Vec::new(), None, responses.channel_ready, responses.announcement_sigs,
10818-
responses.tx_signatures, responses.tx_abort);
10827+
responses.tx_signatures, responses.tx_abort, responses.splice_locked,
10828+
);
1081910829
debug_assert!(htlc_forwards.is_none());
1082010830
debug_assert!(decode_update_add_htlcs.is_none());
1082110831
if let Some(upd) = channel_update {

0 commit comments

Comments
 (0)