Skip to content

Commit c256fa4

Browse files
committed
Avoid initial commitment channel_ready retransmission while splicing
If nodes have started a splice, this means they have both sent and received `channel_ready` already: in that case, it's unnecessary to retransmit `channel_ready` on reconnection.
1 parent 89ea430 commit c256fa4

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

lightning/src/ln/channel.rs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9693,12 +9693,46 @@ where
96939693

96949694
// A node:
96959695
// - if `next_commitment_number` is 1 in both the `channel_reestablish` it
9696-
// sent and received:
9696+
// sent and received, and none of those `channel_reestablish` messages
9697+
// contain `my_current_funding_locked` or `next_funding` for a splice transaction:
96979698
// - MUST retransmit `channel_ready`.
96989699
// - otherwise:
96999700
// - MUST NOT retransmit `channel_ready`, but MAY send `channel_ready` with
97009701
// a different `short_channel_id` `alias` field.
9701-
let channel_ready = if msg.next_local_commitment_number == 1 && INITIAL_COMMITMENT_NUMBER - self.holder_commitment_point.next_transaction_number() == 1 {
9702+
let both_sides_on_initial_commitment_number = msg.next_local_commitment_number == 1
9703+
&& INITIAL_COMMITMENT_NUMBER - self.holder_commitment_point.next_transaction_number() == 1;
9704+
let is_resuming_splice_negotiation = {
9705+
let their_next_funding_txid = msg
9706+
.next_funding
9707+
.as_ref()
9708+
.map(|next_funding| next_funding.txid);
9709+
let our_next_funding_txid = self
9710+
.context
9711+
.interactive_tx_signing_session
9712+
.as_ref()
9713+
.map(|signing_session| signing_session.unsigned_tx().compute_txid());
9714+
self.pending_splice.is_some() && their_next_funding_txid == our_next_funding_txid
9715+
};
9716+
let is_resuming_splice_locked = {
9717+
let their_splice_locked_txid = msg
9718+
.my_current_funding_locked
9719+
.as_ref()
9720+
.map(|funding_locked| funding_locked.txid);
9721+
let our_splice_locked_txid = self
9722+
.pending_splice
9723+
.as_ref()
9724+
.and_then(|pending_splice| pending_splice.sent_funding_txid)
9725+
.or(self.funding.get_funding_txid().filter(|_| {
9726+
self.funding
9727+
.channel_transaction_parameters
9728+
.splice_parent_funding_txid
9729+
.is_some()
9730+
}));
9731+
their_splice_locked_txid.is_some() && their_splice_locked_txid == our_splice_locked_txid
9732+
};
9733+
let channel_ready = if both_sides_on_initial_commitment_number
9734+
&& !is_resuming_splice_negotiation && !is_resuming_splice_locked
9735+
{
97029736
// We should never have to worry about MonitorUpdateInProgress resending ChannelReady
97039737
self.get_channel_ready(logger)
97049738
} else { None };

0 commit comments

Comments
 (0)