Skip to content

Commit f0890ed

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 154697b commit f0890ed

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>(
@@ -8750,6 +8756,7 @@ where
87508756
shutdown_msg, announcement_sigs,
87518757
tx_signatures: None,
87528758
tx_abort: None,
8759+
splice_locked: None,
87538760
});
87548761
}
87558762

@@ -8761,6 +8768,7 @@ where
87618768
shutdown_msg, announcement_sigs,
87628769
tx_signatures: None,
87638770
tx_abort: None,
8771+
splice_locked: None,
87648772
});
87658773
}
87668774

@@ -8808,6 +8816,25 @@ where
88088816
.and_then(|_| self.get_channel_ready(logger))
88098817
} else { None };
88108818

8819+
// A receiving node:
8820+
// - if `your_last_funding_locked` is set and it does not match the most recent
8821+
// `splice_locked` it has sent:
8822+
// - MUST retransmit `splice_locked`.
8823+
let sent_splice_txid = self
8824+
.maybe_get_my_current_funding_locked()
8825+
.filter(|funding| funding.is_splice())
8826+
.map(|funding| {
8827+
funding.get_funding_txid().expect("Splice funding_txid should always be set")
8828+
});
8829+
let splice_locked = msg.your_last_funding_locked_txid.and_then(|last_funding_txid| {
8830+
sent_splice_txid
8831+
.filter(|sent_splice_txid| last_funding_txid != *sent_splice_txid)
8832+
.map(|splice_txid| msgs::SpliceLocked {
8833+
channel_id: self.context.channel_id,
8834+
splice_txid,
8835+
})
8836+
});
8837+
88118838
let mut commitment_update = None;
88128839
let mut tx_signatures = None;
88138840
let mut tx_abort = None;
@@ -8916,6 +8943,7 @@ where
89168943
order: self.context.resend_order.clone(),
89178944
tx_signatures,
89188945
tx_abort,
8946+
splice_locked,
89198947
})
89208948
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
89218949
// We've made an update so we must have exchanged `tx_signatures`, implying that
@@ -8937,6 +8965,7 @@ where
89378965
order: self.context.resend_order.clone(),
89388966
tx_signatures,
89398967
tx_abort,
8968+
splice_locked,
89408969
})
89418970
} else {
89428971
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -8961,6 +8990,7 @@ where
89618990
order: self.context.resend_order.clone(),
89628991
tx_signatures,
89638992
tx_abort,
8993+
splice_locked,
89648994
})
89658995
}
89668996
} else if msg.next_local_commitment_number < next_counterparty_commitment_number {
@@ -10616,6 +10646,24 @@ where
1061610646
None
1061710647
}
1061810648

10649+
#[cfg(splicing)]
10650+
fn maybe_get_my_current_funding_locked(&self) -> Option<&FundingScope> {
10651+
self.pending_splice
10652+
.as_ref()
10653+
.and_then(|pending_splice| pending_splice.sent_funding_txid)
10654+
.and_then(|funding_txid| {
10655+
self.pending_funding
10656+
.iter()
10657+
.find(|funding| funding.get_funding_txid() == Some(funding_txid))
10658+
})
10659+
.or_else(|| self.is_our_channel_ready().then(|| &self.funding))
10660+
}
10661+
10662+
#[cfg(not(splicing))]
10663+
fn maybe_get_my_current_funding_locked(&self) -> Option<&FundingScope> {
10664+
None
10665+
}
10666+
1061910667
#[cfg(splicing)]
1062010668
fn maybe_get_my_current_funding_locked_txid(&self) -> Option<Txid> {
1062110669
self.pending_splice

lightning/src/ln/channelmanager.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3402,7 +3402,8 @@ macro_rules! handle_monitor_update_completion {
34023402
&mut $peer_state.pending_msg_events, $chan, updates.raa,
34033403
updates.commitment_update, updates.order, updates.accepted_htlcs, updates.pending_update_adds,
34043404
updates.funding_broadcastable, updates.channel_ready,
3405-
updates.announcement_sigs, updates.tx_signatures, None);
3405+
updates.announcement_sigs, updates.tx_signatures, None, None,
3406+
);
34063407
if let Some(upd) = channel_update {
34073408
$peer_state.pending_msg_events.push(upd);
34083409
}
@@ -8918,9 +8919,10 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
89188919
funding_broadcastable: Option<Transaction>,
89198920
channel_ready: Option<msgs::ChannelReady>, announcement_sigs: Option<msgs::AnnouncementSignatures>,
89208921
tx_signatures: Option<msgs::TxSignatures>, tx_abort: Option<msgs::TxAbort>,
8922+
splice_locked: Option<msgs::SpliceLocked>,
89218923
) -> (Option<(u64, PublicKey, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)>, Option<(u64, Vec<msgs::UpdateAddHTLC>)>) {
89228924
let logger = WithChannelContext::from(&self.logger, &channel.context, None);
8923-
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",
8925+
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",
89248926
&channel.context.channel_id(),
89258927
if raa.is_some() { "an" } else { "no" },
89268928
if commitment_update.is_some() { "a" } else { "no" },
@@ -8930,6 +8932,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
89308932
if announcement_sigs.is_some() { "sending" } else { "without" },
89318933
if tx_signatures.is_some() { "sending" } else { "without" },
89328934
if tx_abort.is_some() { "sending" } else { "without" },
8935+
if splice_locked.is_some() { "sending" } else { "without" },
89338936
);
89348937

89358938
let counterparty_node_id = channel.context.get_counterparty_node_id();
@@ -8970,6 +8973,12 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
89708973
msg,
89718974
});
89728975
}
8976+
if let Some(msg) = splice_locked {
8977+
pending_msg_events.push(MessageSendEvent::SendSpliceLocked {
8978+
node_id: counterparty_node_id,
8979+
msg,
8980+
});
8981+
}
89738982

89748983
macro_rules! handle_cs { () => {
89758984
if let Some(update) = commitment_update {
@@ -11012,7 +11021,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1101211021
let (htlc_forwards, decode_update_add_htlcs) = self.handle_channel_resumption(
1101311022
&mut peer_state.pending_msg_events, chan, responses.raa, responses.commitment_update, responses.order,
1101411023
Vec::new(), Vec::new(), None, responses.channel_ready, responses.announcement_sigs,
11015-
responses.tx_signatures, responses.tx_abort);
11024+
responses.tx_signatures, responses.tx_abort, responses.splice_locked,
11025+
);
1101611026
debug_assert!(htlc_forwards.is_none());
1101711027
debug_assert!(decode_update_add_htlcs.is_none());
1101811028
if let Some(upd) = channel_update {

0 commit comments

Comments
 (0)