Skip to content

Commit 5478741

Browse files
committed
Update next_commitment_number logic for channel_reestablish
The splicing spec updates the logic pertaining to next_commitment_number when sending a channel_reestablish message. Specifically: The sending node: - if it has sent `commitment_signed` for an interactive transaction construction but it has not received `tx_signatures`: - MUST set `next_funding_txid` to the txid of that interactive transaction. - if it has not received `commitment_signed` for that interactive transaction: - MUST set `next_commitment_number` to the commitment number of the `commitment_signed` it sent.
1 parent 5a5cb97 commit 5478741

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

lightning/src/ln/channel.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10541,6 +10541,27 @@ where
1054110541
self.sign_channel_announcement(node_signer, announcement).ok()
1054210542
}
1054310543

10544+
fn get_next_local_commitment_number(&self) -> u64 {
10545+
let next_local_commitment_number =
10546+
INITIAL_COMMITMENT_NUMBER - self.holder_commitment_point.transaction_number();
10547+
10548+
// The sending node:
10549+
// - if it has sent `commitment_signed` for an interactive transaction construction but
10550+
// it has not received `tx_signatures`:
10551+
// - MUST set `next_funding_txid` to the txid of that interactive transaction.
10552+
// - if it has not received `commitment_signed` for that interactive transaction:
10553+
// - MUST set `next_commitment_number` to the commitment number of the `commitment_signed` it sent.
10554+
if let Some(session) = &self.interactive_tx_signing_session {
10555+
if !self.context.channel_state.is_their_tx_signatures_sent()
10556+
&& !session.has_received_commitment_signed()
10557+
{
10558+
return next_local_commitment_number + 1;
10559+
}
10560+
}
10561+
10562+
next_local_commitment_number
10563+
}
10564+
1054410565
#[rustfmt::skip]
1054510566
fn maybe_get_next_funding_txid(&self) -> Option<Txid> {
1054610567
// If we've sent `commtiment_signed` for an interactively constructed transaction
@@ -10616,7 +10637,7 @@ where
1061610637

1061710638
// next_local_commitment_number is the next commitment_signed number we expect to
1061810639
// receive (indicating if they need to resend one that we missed).
10619-
next_local_commitment_number: INITIAL_COMMITMENT_NUMBER - self.holder_commitment_point.transaction_number(),
10640+
next_local_commitment_number: self.get_next_local_commitment_number(),
1062010641
// We have to set next_remote_commitment_number to the next revoke_and_ack we expect to
1062110642
// receive, however we track it by the next commitment number for a remote transaction
1062210643
// (which is one further, as they always revoke previous commitment transaction, not

0 commit comments

Comments
 (0)