Skip to content

Commit e95b158

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 8848c9a commit e95b158

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
@@ -1213,6 +1213,7 @@ pub(super) struct ReestablishResponses {
12131213
pub shutdown_msg: Option<msgs::Shutdown>,
12141214
pub tx_signatures: Option<msgs::TxSignatures>,
12151215
pub tx_abort: Option<msgs::TxAbort>,
1216+
pub splice_locked: Option<msgs::SpliceLocked>,
12161217
}
12171218

12181219
/// The first message we send to our peer after connection
@@ -2169,6 +2170,10 @@ impl FundingScope {
21692170
pub fn get_short_channel_id(&self) -> Option<u64> {
21702171
self.short_channel_id
21712172
}
2173+
2174+
fn is_splice(&self) -> bool {
2175+
self.channel_transaction_parameters.splice_parent_funding_txid.is_some()
2176+
}
21722177
}
21732178

21742179
/// Info about a pending splice, used in the pre-splice channel
@@ -8389,6 +8394,7 @@ where
83898394
shutdown_msg, announcement_sigs,
83908395
tx_signatures: None,
83918396
tx_abort: None,
8397+
splice_locked: None,
83928398
});
83938399
}
83948400

@@ -8400,6 +8406,7 @@ where
84008406
shutdown_msg, announcement_sigs,
84018407
tx_signatures: None,
84028408
tx_abort: None,
8409+
splice_locked: None,
84038410
});
84048411
}
84058412

@@ -8445,6 +8452,25 @@ where
84458452
.and_then(|_| self.get_channel_ready(logger))
84468453
} else { None };
84478454

8455+
// A receiving node:
8456+
// - if `your_last_funding_locked` is set and it does not match the most recent
8457+
// `splice_locked` it has sent:
8458+
// - MUST retransmit `splice_locked`.
8459+
let sent_splice_txid = self
8460+
.maybe_get_my_current_funding_locked(features)
8461+
.filter(|funding| funding.is_splice())
8462+
.map(|funding| {
8463+
funding.get_funding_txid().expect("Splice funding_txid should always be set")
8464+
});
8465+
let splice_locked = msg.your_last_funding_locked_txid.and_then(|last_funding_txid| {
8466+
sent_splice_txid
8467+
.filter(|sent_splice_txid| last_funding_txid != *sent_splice_txid)
8468+
.map(|splice_txid| msgs::SpliceLocked {
8469+
channel_id: self.context.channel_id,
8470+
splice_txid,
8471+
})
8472+
});
8473+
84488474
let mut commitment_update = None;
84498475
let mut tx_signatures = None;
84508476
let mut tx_abort = None;
@@ -8551,6 +8577,7 @@ where
85518577
order: self.context.resend_order.clone(),
85528578
tx_signatures,
85538579
tx_abort,
8580+
splice_locked,
85548581
})
85558582
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
85568583
// We've made an update so we must have exchanged `tx_signatures`, implying that
@@ -8572,6 +8599,7 @@ where
85728599
order: self.context.resend_order.clone(),
85738600
tx_signatures,
85748601
tx_abort,
8602+
splice_locked,
85758603
})
85768604
} else {
85778605
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -8596,6 +8624,7 @@ where
85968624
order: self.context.resend_order.clone(),
85978625
tx_signatures,
85988626
tx_abort,
8627+
splice_locked,
85998628
})
86008629
}
86018630
} else if msg.next_local_commitment_number < next_counterparty_commitment_number {
@@ -10219,6 +10248,32 @@ where
1021910248
None
1022010249
}
1022110250

10251+
#[cfg(splicing)]
10252+
fn maybe_get_my_current_funding_locked(
10253+
&self, features: &InitFeatures,
10254+
) -> Option<&FundingScope> {
10255+
if !features.supports_splicing() {
10256+
return None;
10257+
}
10258+
10259+
self.pending_splice
10260+
.as_ref()
10261+
.and_then(|pending_splice| pending_splice.sent_funding_txid)
10262+
.and_then(|funding_txid| {
10263+
self.pending_funding
10264+
.iter()
10265+
.find(|funding| funding.get_funding_txid() == Some(funding_txid))
10266+
})
10267+
.or_else(|| self.is_our_channel_ready().then(|| &self.funding))
10268+
}
10269+
10270+
#[cfg(not(splicing))]
10271+
fn maybe_get_my_current_funding_locked(
10272+
&self, _features: &InitFeatures,
10273+
) -> Option<&FundingScope> {
10274+
None
10275+
}
10276+
1022210277
#[cfg(splicing)]
1022310278
fn maybe_get_my_current_funding_locked_txid(&self, features: &InitFeatures) -> Option<Txid> {
1022410279
if !features.supports_splicing() {

lightning/src/ln/channelmanager.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3406,7 +3406,8 @@ macro_rules! handle_monitor_update_completion {
34063406
&mut $peer_state.pending_msg_events, $chan, updates.raa,
34073407
updates.commitment_update, updates.order, updates.accepted_htlcs, updates.pending_update_adds,
34083408
updates.funding_broadcastable, updates.channel_ready,
3409-
updates.announcement_sigs, updates.tx_signatures, None);
3409+
updates.announcement_sigs, updates.tx_signatures, None, None,
3410+
);
34103411
if let Some(upd) = channel_update {
34113412
$peer_state.pending_msg_events.push(upd);
34123413
}
@@ -8059,9 +8060,10 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
80598060
funding_broadcastable: Option<Transaction>,
80608061
channel_ready: Option<msgs::ChannelReady>, announcement_sigs: Option<msgs::AnnouncementSignatures>,
80618062
tx_signatures: Option<msgs::TxSignatures>, tx_abort: Option<msgs::TxAbort>,
8063+
splice_locked: Option<msgs::SpliceLocked>,
80628064
) -> (Option<(u64, Option<PublicKey>, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)>, Option<(u64, Vec<msgs::UpdateAddHTLC>)>) {
80638065
let logger = WithChannelContext::from(&self.logger, &channel.context, None);
8064-
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",
8066+
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",
80658067
&channel.context.channel_id(),
80668068
if raa.is_some() { "an" } else { "no" },
80678069
if commitment_update.is_some() { "a" } else { "no" },
@@ -8071,6 +8073,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
80718073
if announcement_sigs.is_some() { "sending" } else { "without" },
80728074
if tx_signatures.is_some() { "sending" } else { "without" },
80738075
if tx_abort.is_some() { "sending" } else { "without" },
8076+
if splice_locked.is_some() { "sending" } else { "without" },
80748077
);
80758078

80768079
let counterparty_node_id = channel.context.get_counterparty_node_id();
@@ -8110,6 +8113,12 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
81108113
msg,
81118114
});
81128115
}
8116+
if let Some(msg) = splice_locked {
8117+
pending_msg_events.push(MessageSendEvent::SendSpliceLocked {
8118+
node_id: counterparty_node_id,
8119+
msg,
8120+
});
8121+
}
81138122

81148123
macro_rules! handle_cs { () => {
81158124
if let Some(update) = commitment_update {
@@ -10054,7 +10063,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1005410063
let (htlc_forwards, decode_update_add_htlcs) = self.handle_channel_resumption(
1005510064
&mut peer_state.pending_msg_events, chan, responses.raa, responses.commitment_update, responses.order,
1005610065
Vec::new(), Vec::new(), None, responses.channel_ready, responses.announcement_sigs,
10057-
responses.tx_signatures, responses.tx_abort);
10066+
responses.tx_signatures, responses.tx_abort, responses.splice_locked,
10067+
);
1005810068
debug_assert!(htlc_forwards.is_none());
1005910069
debug_assert!(decode_update_add_htlcs.is_none());
1006010070
if let Some(upd) = channel_update {

0 commit comments

Comments
 (0)