Skip to content

Commit c079677

Browse files
committed
Support sending 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 80f952e commit c079677

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

lightning/src/ln/channel.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,7 @@ pub(super) struct ReestablishResponses {
12111211
pub shutdown_msg: Option<msgs::Shutdown>,
12121212
pub tx_signatures: Option<msgs::TxSignatures>,
12131213
pub tx_abort: Option<msgs::TxAbort>,
1214+
pub splice_locked: Option<msgs::SpliceLocked>,
12141215
}
12151216

12161217
/// The first message we send to our peer after connection
@@ -2142,6 +2143,10 @@ impl FundingScope {
21422143
pub fn get_short_channel_id(&self) -> Option<u64> {
21432144
self.short_channel_id
21442145
}
2146+
2147+
fn is_splice(&self) -> bool {
2148+
self.channel_transaction_parameters.splice_parent_funding_txid.is_some()
2149+
}
21452150
}
21462151

21472152
/// Info about a pending splice, used in the pre-splice channel
@@ -8050,6 +8055,7 @@ where
80508055
shutdown_msg, announcement_sigs,
80518056
tx_signatures: None,
80528057
tx_abort: None,
8058+
splice_locked: None,
80538059
});
80548060
}
80558061

@@ -8061,6 +8067,7 @@ where
80618067
shutdown_msg, announcement_sigs,
80628068
tx_signatures: None,
80638069
tx_abort: None,
8070+
splice_locked: None,
80648071
});
80658072
}
80668073

@@ -8099,6 +8106,25 @@ where
80998106
self.get_channel_ready(logger)
81008107
} else { None };
81018108

8109+
let splice_locked = msg.your_last_funding_locked_txid.and_then(|last_funding_txid| {
8110+
self.pending_splice
8111+
.as_ref()
8112+
.and_then(|pending_splice| pending_splice.sent_funding_txid)
8113+
.or_else(|| {
8114+
self.funding.is_splice().then(|| {
8115+
self.funding
8116+
.get_funding_txid()
8117+
.expect("Splice funding_txid should always be set")
8118+
})
8119+
})
8120+
.and_then(|sent_funding_txid| {
8121+
(last_funding_txid != sent_funding_txid).then(|| msgs::SpliceLocked {
8122+
channel_id: self.context.channel_id,
8123+
splice_txid: sent_funding_txid,
8124+
})
8125+
})
8126+
});
8127+
81028128
let mut commitment_update = None;
81038129
let mut tx_signatures = None;
81048130
let mut tx_abort = None;
@@ -8205,6 +8231,7 @@ where
82058231
order: self.context.resend_order.clone(),
82068232
tx_signatures,
82078233
tx_abort,
8234+
splice_locked,
82088235
})
82098236
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
82108237
// We've made an update so we must have exchanged `tx_signatures`, implying that
@@ -8226,6 +8253,7 @@ where
82268253
order: self.context.resend_order.clone(),
82278254
tx_signatures,
82288255
tx_abort,
8256+
splice_locked,
82298257
})
82308258
} else {
82318259
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -8250,6 +8278,7 @@ where
82508278
order: self.context.resend_order.clone(),
82518279
tx_signatures,
82528280
tx_abort,
8281+
splice_locked,
82538282
})
82548283
}
82558284
} else if msg.next_local_commitment_number < next_counterparty_commitment_number {

lightning/src/ln/channelmanager.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3405,7 +3405,8 @@ macro_rules! handle_monitor_update_completion {
34053405
&mut $peer_state.pending_msg_events, $chan, updates.raa,
34063406
updates.commitment_update, updates.order, updates.accepted_htlcs, updates.pending_update_adds,
34073407
updates.funding_broadcastable, updates.channel_ready,
3408-
updates.announcement_sigs, updates.tx_signatures, None);
3408+
updates.announcement_sigs, updates.tx_signatures, None, None,
3409+
);
34093410
if let Some(upd) = channel_update {
34103411
$peer_state.pending_msg_events.push(upd);
34113412
}
@@ -8057,9 +8058,10 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
80578058
funding_broadcastable: Option<Transaction>,
80588059
channel_ready: Option<msgs::ChannelReady>, announcement_sigs: Option<msgs::AnnouncementSignatures>,
80598060
tx_signatures: Option<msgs::TxSignatures>, tx_abort: Option<msgs::TxAbort>,
8061+
splice_locked: Option<msgs::SpliceLocked>,
80608062
) -> (Option<(u64, Option<PublicKey>, OutPoint, ChannelId, u128, Vec<(PendingHTLCInfo, u64)>)>, Option<(u64, Vec<msgs::UpdateAddHTLC>)>) {
80618063
let logger = WithChannelContext::from(&self.logger, &channel.context, None);
8062-
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",
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, {} splice_locked",
80638065
&channel.context.channel_id(),
80648066
if raa.is_some() { "an" } else { "no" },
80658067
if commitment_update.is_some() { "a" } else { "no" },
@@ -8069,6 +8071,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
80698071
if announcement_sigs.is_some() { "sending" } else { "without" },
80708072
if tx_signatures.is_some() { "sending" } else { "without" },
80718073
if tx_abort.is_some() { "sending" } else { "without" },
8074+
if splice_locked.is_some() { "sending" } else { "without" },
80728075
);
80738076

80748077
let counterparty_node_id = channel.context.get_counterparty_node_id();
@@ -8108,6 +8111,12 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
81088111
msg,
81098112
});
81108113
}
8114+
if let Some(msg) = splice_locked {
8115+
pending_msg_events.push(MessageSendEvent::SendSpliceLocked {
8116+
node_id: counterparty_node_id,
8117+
msg,
8118+
});
8119+
}
81118120

81128121
macro_rules! handle_cs { () => {
81138122
if let Some(update) = commitment_update {
@@ -9998,7 +10007,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
999810007
let (htlc_forwards, decode_update_add_htlcs) = self.handle_channel_resumption(
999910008
&mut peer_state.pending_msg_events, chan, responses.raa, responses.commitment_update, responses.order,
1000010009
Vec::new(), Vec::new(), None, responses.channel_ready, responses.announcement_sigs,
10001-
responses.tx_signatures, responses.tx_abort);
10010+
responses.tx_signatures, responses.tx_abort, responses.splice_locked,
10011+
);
1000210012
debug_assert!(htlc_forwards.is_none());
1000310013
debug_assert!(decode_update_add_htlcs.is_none());
1000410014
if let Some(upd) = channel_update {

0 commit comments

Comments
 (0)