Skip to content

Commit 41647ee

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 beca12c commit 41647ee

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>(
@@ -8749,6 +8755,7 @@ where
87498755
shutdown_msg, announcement_sigs,
87508756
tx_signatures: None,
87518757
tx_abort: None,
8758+
splice_locked: None,
87528759
});
87538760
}
87548761

@@ -8760,6 +8767,7 @@ where
87608767
shutdown_msg, announcement_sigs,
87618768
tx_signatures: None,
87628769
tx_abort: None,
8770+
splice_locked: None,
87638771
});
87648772
}
87658773

@@ -8795,6 +8803,25 @@ where
87958803
self.get_channel_ready(logger)
87968804
} else { None };
87978805

8806+
// A receiving node:
8807+
// - if `your_last_funding_locked` is set and it does not match the most recent
8808+
// `splice_locked` it has sent:
8809+
// - MUST retransmit `splice_locked`.
8810+
let sent_splice_txid = self
8811+
.maybe_get_my_current_funding_locked()
8812+
.filter(|funding| funding.is_splice())
8813+
.map(|funding| {
8814+
funding.get_funding_txid().expect("Splice funding_txid should always be set")
8815+
});
8816+
let splice_locked = msg.your_last_funding_locked_txid.and_then(|last_funding_txid| {
8817+
sent_splice_txid
8818+
.filter(|sent_splice_txid| last_funding_txid != *sent_splice_txid)
8819+
.map(|splice_txid| msgs::SpliceLocked {
8820+
channel_id: self.context.channel_id,
8821+
splice_txid,
8822+
})
8823+
});
8824+
87988825
let mut commitment_update = None;
87998826
let mut tx_signatures = None;
88008827
let mut tx_abort = None;
@@ -8903,6 +8930,7 @@ where
89038930
order: self.context.resend_order.clone(),
89048931
tx_signatures,
89058932
tx_abort,
8933+
splice_locked,
89068934
})
89078935
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
89088936
// We've made an update so we must have exchanged `tx_signatures`, implying that
@@ -8924,6 +8952,7 @@ where
89248952
order: self.context.resend_order.clone(),
89258953
tx_signatures,
89268954
tx_abort,
8955+
splice_locked,
89278956
})
89288957
} else {
89298958
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -8948,6 +8977,7 @@ where
89488977
order: self.context.resend_order.clone(),
89498978
tx_signatures,
89508979
tx_abort,
8980+
splice_locked,
89518981
})
89528982
}
89538983
} else if msg.next_local_commitment_number < next_counterparty_commitment_number {
@@ -10598,6 +10628,24 @@ where
1059810628
None
1059910629
}
1060010630

10631+
#[cfg(splicing)]
10632+
fn maybe_get_my_current_funding_locked(&self) -> Option<&FundingScope> {
10633+
self.pending_splice
10634+
.as_ref()
10635+
.and_then(|pending_splice| pending_splice.sent_funding_txid)
10636+
.and_then(|funding_txid| {
10637+
self.pending_funding
10638+
.iter()
10639+
.find(|funding| funding.get_funding_txid() == Some(funding_txid))
10640+
})
10641+
.or_else(|| self.is_our_channel_ready().then(|| &self.funding))
10642+
}
10643+
10644+
#[cfg(not(splicing))]
10645+
fn maybe_get_my_current_funding_locked(&self) -> Option<&FundingScope> {
10646+
None
10647+
}
10648+
1060110649
/// May panic if called on a channel that wasn't immediately-previously
1060210650
/// self.remove_uncommitted_htlcs_and_mark_paused()'d
1060310651
#[rustfmt::skip]

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 {
@@ -11011,7 +11020,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1101111020
let (htlc_forwards, decode_update_add_htlcs) = self.handle_channel_resumption(
1101211021
&mut peer_state.pending_msg_events, chan, responses.raa, responses.commitment_update, responses.order,
1101311022
Vec::new(), Vec::new(), None, responses.channel_ready, responses.announcement_sigs,
11014-
responses.tx_signatures, responses.tx_abort);
11023+
responses.tx_signatures, responses.tx_abort, responses.splice_locked,
11024+
);
1101511025
debug_assert!(htlc_forwards.is_none());
1101611026
debug_assert!(decode_update_add_htlcs.is_none());
1101711027
if let Some(upd) = channel_update {

0 commit comments

Comments
 (0)