From 183c0be0e545e27ad588b3ddbb0834fa2937a389 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Thu, 14 Aug 2025 08:52:11 -0500 Subject: [PATCH 1/7] Use struct for HolderCommitmentPoint The only difference between the two variants is the next point, which can be stored using an Option for simplicity. The naming of the Available variant is also confusing as it refers to the next commitment point. But HolderCommitmentPoint is typically used to represent the next point, which is actually stored in the current field. Drop the "current" nomenclature to avoid confusion. --- lightning/src/ln/channel.rs | 224 ++++++++++++++++-------------------- 1 file changed, 98 insertions(+), 126 deletions(-) diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 56d38d5545c..a0cf5ec2788 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -1249,14 +1249,10 @@ pub(crate) struct ShutdownResult { /// This consolidates the logic to advance our commitment number and request new /// commitment points from our signer. #[derive(Debug, Copy, Clone)] -enum HolderCommitmentPoint { - /// We've advanced our commitment number and are waiting on the next commitment point. - /// - /// We should retry advancing to `Available` via `try_resolve_pending` once our - /// signer is ready to provide the next commitment point. - PendingNext { transaction_number: u64, current: PublicKey }, - /// Our current commitment point is ready and we've cached our next point. - Available { transaction_number: u64, current: PublicKey, next: PublicKey }, +struct HolderCommitmentPoint { + transaction_number: u64, + point: PublicKey, + next_point: Option, } impl HolderCommitmentPoint { @@ -1264,87 +1260,66 @@ impl HolderCommitmentPoint { pub fn new(signer: &ChannelSignerType, secp_ctx: &Secp256k1) -> Option where SP::Target: SignerProvider { - let current = signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER, secp_ctx).ok()?; - let next = signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, secp_ctx).ok(); - let point = if let Some(next) = next { - HolderCommitmentPoint::Available { transaction_number: INITIAL_COMMITMENT_NUMBER, current, next } - } else { - HolderCommitmentPoint::PendingNext { transaction_number: INITIAL_COMMITMENT_NUMBER, current } - }; - Some(point) + Some(HolderCommitmentPoint { + transaction_number: INITIAL_COMMITMENT_NUMBER, + point: signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER, secp_ctx).ok()?, + next_point: signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, secp_ctx).ok(), + }) } - #[rustfmt::skip] - pub fn is_available(&self) -> bool { - if let HolderCommitmentPoint::Available { .. } = self { true } else { false } + pub fn can_advance(&self) -> bool { + self.next_point.is_some() } pub fn transaction_number(&self) -> u64 { - match self { - HolderCommitmentPoint::PendingNext { transaction_number, .. } => *transaction_number, - HolderCommitmentPoint::Available { transaction_number, .. } => *transaction_number, - } + self.transaction_number } - pub fn current_point(&self) -> PublicKey { - match self { - HolderCommitmentPoint::PendingNext { current, .. } => *current, - HolderCommitmentPoint::Available { current, .. } => *current, - } + pub fn point(&self) -> PublicKey { + self.point } pub fn next_point(&self) -> Option { - match self { - HolderCommitmentPoint::PendingNext { .. } => None, - HolderCommitmentPoint::Available { next, .. } => Some(*next), - } + self.next_point } - /// If we are pending the next commitment point, this method tries asking the signer again, - /// and transitions to the next state if successful. - /// - /// This method is used for the following transitions: - /// - `PendingNext` -> `Available` + /// If we are pending the next commitment point, this method tries asking the signer again. pub fn try_resolve_pending( &mut self, signer: &ChannelSignerType, secp_ctx: &Secp256k1, logger: &L, ) where SP::Target: SignerProvider, L::Target: Logger, { - if let HolderCommitmentPoint::PendingNext { transaction_number, current } = self { - let next = signer.as_ref().get_per_commitment_point(*transaction_number - 1, secp_ctx); + if !self.can_advance() { + let next = + signer.as_ref().get_per_commitment_point(self.transaction_number - 1, secp_ctx); if let Ok(next) = next { log_trace!( logger, "Retrieved next per-commitment point {}", - *transaction_number - 1 + self.transaction_number - 1 ); - *self = HolderCommitmentPoint::Available { - transaction_number: *transaction_number, - current: *current, - next, - }; + self.next_point = Some(next); } else { - log_trace!(logger, "Next per-commitment point {} is pending", transaction_number); + log_trace!( + logger, + "Next per-commitment point {} is pending", + self.transaction_number + ); } } } /// If we are not pending the next commitment point, this method advances the commitment number - /// and requests the next commitment point from the signer. Returns `Ok` if we were at - /// `Available` and were able to advance our commitment number (even if we are still pending - /// the next commitment point). - /// - /// If our signer is not ready to provide the next commitment point, we will - /// only advance to `PendingNext`, and should be tried again later in `signer_unblocked` - /// via `try_resolve_pending`. + /// and requests the next commitment point from the signer. Returns `Ok` if we were able to + /// advance our commitment number (even if we are still pending the next commitment point). /// - /// If our signer is ready to provide the next commitment point, we will advance all the - /// way to `Available`. + /// If our signer is not ready to provide the next commitment point, we will advance but won't + /// be able to advance again immediately. Instead, this hould be tried again later in + /// `signer_unblocked` via `try_resolve_pending`. /// - /// This method is used for the following transitions: - /// - `Available` -> `PendingNext` - /// - `Available` -> `PendingNext` -> `Available` (in one fell swoop) + /// If our signer is ready to provide the next commitment point, the next call to `advance` will + /// succeed. pub fn advance( &mut self, signer: &ChannelSignerType, secp_ctx: &Secp256k1, logger: &L, ) -> Result<(), ()> @@ -1352,11 +1327,13 @@ impl HolderCommitmentPoint { SP::Target: SignerProvider, L::Target: Logger, { - if let HolderCommitmentPoint::Available { transaction_number, next, .. } = self { - *self = HolderCommitmentPoint::PendingNext { - transaction_number: *transaction_number - 1, - current: *next, + if let Some(next_point) = self.next_point { + *self = Self { + transaction_number: self.transaction_number - 1, + point: next_point, + next_point: None, }; + self.try_resolve_pending(signer, secp_ctx, logger); return Ok(()); } @@ -2771,7 +2748,7 @@ where let funding_script = self.funding().get_funding_redeemscript(); let commitment_data = self.context().build_commitment_transaction(self.funding(), - holder_commitment_point.transaction_number(), &holder_commitment_point.current_point(), + holder_commitment_point.transaction_number(), &holder_commitment_point.point(), true, false, logger); let initial_commitment_tx = commitment_data.tx; let trusted_tx = initial_commitment_tx.trust(); @@ -4218,7 +4195,7 @@ where let funding_script = funding.get_funding_redeemscript(); let commitment_data = self.build_commitment_transaction(funding, - holder_commitment_point.transaction_number(), &holder_commitment_point.current_point(), + holder_commitment_point.transaction_number(), &holder_commitment_point.point(), true, false, logger); let commitment_txid = { let trusted_tx = commitment_data.tx.trust(); @@ -8412,7 +8389,7 @@ where /// blocked. #[rustfmt::skip] pub fn signer_maybe_unblocked(&mut self, logger: &L) -> SignerResumeUpdates where L::Target: Logger { - if !self.holder_commitment_point.is_available() { + if !self.holder_commitment_point.can_advance() { log_trace!(logger, "Attempting to update holder per-commitment point..."); self.holder_commitment_point.try_resolve_pending(&self.context.holder_signer, &self.context.secp_ctx, logger); } @@ -8513,18 +8490,19 @@ where self.holder_commitment_point.try_resolve_pending(&self.context.holder_signer, &self.context.secp_ctx, logger); let per_commitment_secret = self.context.holder_signer.as_ref() .release_commitment_secret(self.holder_commitment_point.transaction_number() + 2).ok(); - if let (HolderCommitmentPoint::Available { current, .. }, Some(per_commitment_secret)) = - (self.holder_commitment_point, per_commitment_secret) { - self.context.signer_pending_revoke_and_ack = false; - return Some(msgs::RevokeAndACK { - channel_id: self.context.channel_id, - per_commitment_secret, - next_per_commitment_point: current, - #[cfg(taproot)] - next_local_nonce: None, - }) + if let Some(per_commitment_secret) = per_commitment_secret { + if self.holder_commitment_point.can_advance() { + self.context.signer_pending_revoke_and_ack = false; + return Some(msgs::RevokeAndACK { + channel_id: self.context.channel_id, + per_commitment_secret, + next_per_commitment_point: self.holder_commitment_point.point(), + #[cfg(taproot)] + next_local_nonce: None, + }) + } } - if !self.holder_commitment_point.is_available() { + if !self.holder_commitment_point.can_advance() { log_trace!(logger, "Last revoke-and-ack pending in channel {} for sequence {} because the next per-commitment point is not available", &self.context.channel_id(), self.holder_commitment_point.transaction_number()); } @@ -8533,7 +8511,7 @@ where &self.context.channel_id(), self.holder_commitment_point.transaction_number(), self.holder_commitment_point.transaction_number() + 2); } - // Technically if we're at HolderCommitmentPoint::PendingNext, + // Technically if HolderCommitmentPoint::can_advance is false, // we have a commitment point ready to send in an RAA, however we // choose to wait since if we send RAA now, we could get another // CS before we have any commitment point available. Blocking our @@ -9873,11 +9851,11 @@ where fn get_channel_ready( &mut self, logger: &L ) -> Option where L::Target: Logger { - if let HolderCommitmentPoint::Available { current, .. } = self.holder_commitment_point { + if self.holder_commitment_point.can_advance() { self.context.signer_pending_channel_ready = false; Some(msgs::ChannelReady { channel_id: self.context.channel_id(), - next_per_commitment_point: current, + next_per_commitment_point: self.holder_commitment_point.point(), short_channel_id_alias: Some(self.context.outbound_scid_alias), }) } else { @@ -11986,9 +11964,9 @@ where } let first_per_commitment_point = match self.unfunded_context.holder_commitment_point { - Some(holder_commitment_point) if holder_commitment_point.is_available() => { + Some(holder_commitment_point) if holder_commitment_point.can_advance() => { self.signer_pending_open_channel = false; - holder_commitment_point.current_point() + holder_commitment_point.point() }, _ => { log_trace!(_logger, "Unable to generate open_channel message, waiting for commitment point"); @@ -12100,7 +12078,7 @@ where self.unfunded_context.holder_commitment_point = HolderCommitmentPoint::new(&self.context.holder_signer, &self.context.secp_ctx); } if let Some(ref mut point) = self.unfunded_context.holder_commitment_point { - if !point.is_available() { + if !point.can_advance() { point.try_resolve_pending(&self.context.holder_signer, &self.context.secp_ctx, logger); } } @@ -12260,9 +12238,9 @@ where &mut self, _logger: &L ) -> Option where L::Target: Logger { let first_per_commitment_point = match self.unfunded_context.holder_commitment_point { - Some(holder_commitment_point) if holder_commitment_point.is_available() => { + Some(holder_commitment_point) if holder_commitment_point.can_advance() => { self.signer_pending_accept_channel = false; - holder_commitment_point.current_point() + holder_commitment_point.point() }, _ => { log_trace!(_logger, "Unable to generate accept_channel message, waiting for commitment point"); @@ -12384,7 +12362,7 @@ where self.unfunded_context.holder_commitment_point = HolderCommitmentPoint::new(&self.context.holder_signer, &self.context.secp_ctx); } if let Some(ref mut point) = self.unfunded_context.holder_commitment_point { - if !point.is_available() { + if !point.can_advance() { point.try_resolve_pending(&self.context.holder_signer, &self.context.secp_ctx, logger); } } @@ -13222,9 +13200,9 @@ where } let is_manual_broadcast = Some(self.context.is_manual_broadcast); - // `current_point` will become optional when async signing is implemented. - let cur_holder_commitment_point = Some(self.holder_commitment_point.current_point()); - let next_holder_commitment_point = self.holder_commitment_point.next_point(); + // `HolderCommitmentPoint::point` will become optional when async signing is implemented. + let holder_commitment_point = Some(self.holder_commitment_point.point()); + let holder_commitment_point_next_advance = self.holder_commitment_point.next_point(); write_tlv_fields!(writer, { (0, self.context.announcement_sigs, option), @@ -13262,8 +13240,8 @@ where (39, pending_outbound_blinding_points, optional_vec), (41, holding_cell_blinding_points, optional_vec), (43, malformed_htlcs, optional_vec), // Added in 0.0.119 - (45, cur_holder_commitment_point, option), - (47, next_holder_commitment_point, option), + (45, holder_commitment_point, option), + (47, holder_commitment_point_next_advance, option), (49, self.context.local_initiated_shutdown, option), // Added in 0.0.122 (51, is_manual_broadcast, option), // Added in 0.0.124 (53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124 @@ -13320,7 +13298,7 @@ where }; let destination_script = Readable::read(reader)?; - let cur_holder_commitment_transaction_number = Readable::read(reader)?; + let holder_commitment_transaction_number = Readable::read(reader)?; let cur_counterparty_commitment_transaction_number = Readable::read(reader)?; let value_to_self_msat = Readable::read(reader)?; @@ -13623,8 +13601,8 @@ where let mut malformed_htlcs: Option> = None; let mut monitor_pending_update_adds: Option> = None; - let mut cur_holder_commitment_point_opt: Option = None; - let mut next_holder_commitment_point_opt: Option = None; + let mut holder_commitment_point_opt: Option = None; + let mut holder_commitment_point_next_advance_opt: Option = None; let mut is_manual_broadcast = None; let mut pending_funding = Some(Vec::new()); @@ -13664,8 +13642,8 @@ where (39, pending_outbound_blinding_points_opt, optional_vec), (41, holding_cell_blinding_points_opt, optional_vec), (43, malformed_htlcs, optional_vec), // Added in 0.0.119 - (45, cur_holder_commitment_point_opt, option), - (47, next_holder_commitment_point_opt, option), + (45, holder_commitment_point_opt, option), + (47, holder_commitment_point_next_advance_opt, option), (49, local_initiated_shutdown, option), (51, is_manual_broadcast, option), (53, funding_tx_broadcast_safe_event_emitted, option), @@ -13853,37 +13831,31 @@ where // If we're restoring this channel for the first time after an upgrade, then we require that the // signer be available so that we can immediately populate the current commitment point. Channel // restoration will fail if this is not possible. - let holder_commitment_point = match ( - cur_holder_commitment_point_opt, - next_holder_commitment_point_opt, - ) { - (Some(current), Some(next)) => HolderCommitmentPoint::Available { - transaction_number: cur_holder_commitment_transaction_number, - current, - next, - }, - (Some(current), _) => HolderCommitmentPoint::PendingNext { - transaction_number: cur_holder_commitment_transaction_number, - current, - }, - (_, _) => { - let current = holder_signer.get_per_commitment_point(cur_holder_commitment_transaction_number, &secp_ctx) - .expect("Must be able to derive the current commitment point upon channel restoration"); - let next = holder_signer - .get_per_commitment_point( - cur_holder_commitment_transaction_number - 1, - &secp_ctx, - ) - .expect( - "Must be able to derive the next commitment point upon channel restoration", - ); - HolderCommitmentPoint::Available { - transaction_number: cur_holder_commitment_transaction_number, - current, - next, - } - }, - }; + let holder_commitment_point = + match (holder_commitment_point_opt, holder_commitment_point_next_advance_opt) { + (Some(point), next_point) => HolderCommitmentPoint { + transaction_number: holder_commitment_transaction_number, + point, + next_point, + }, + (_, _) => { + let point = holder_signer.get_per_commitment_point(holder_commitment_transaction_number, &secp_ctx) + .expect("Must be able to derive the current commitment point upon channel restoration"); + let next_point = holder_signer + .get_per_commitment_point( + holder_commitment_transaction_number - 1, + &secp_ctx, + ) + .expect( + "Must be able to derive the next commitment point upon channel restoration", + ); + HolderCommitmentPoint { + transaction_number: holder_commitment_transaction_number, + point, + next_point: Some(next_point), + } + }, + }; Ok(FundedChannel { funding: FundingScope { From 8c48293953f09d746e134868edae31ec17d9c848 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Mon, 18 Aug 2025 11:40:12 -0500 Subject: [PATCH 2/7] Rename HolderCommitmentPoint::next_point HolderCommitmentPoint::next_point represents the point to use after advancing the point. However, HolderCommitmentPoint::point actually represents the next point we'd expect to receive. This will be renamed in the next commit, so to avoid clashing the existing next_point field needs to be renamed. --- lightning/src/ln/channel.rs | 49 +++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index a0cf5ec2788..d1a05b31010 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -1252,7 +1252,7 @@ pub(crate) struct ShutdownResult { struct HolderCommitmentPoint { transaction_number: u64, point: PublicKey, - next_point: Option, + pending_next_point: Option, } impl HolderCommitmentPoint { @@ -1263,12 +1263,12 @@ impl HolderCommitmentPoint { Some(HolderCommitmentPoint { transaction_number: INITIAL_COMMITMENT_NUMBER, point: signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER, secp_ctx).ok()?, - next_point: signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, secp_ctx).ok(), + pending_next_point: signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, secp_ctx).ok(), }) } pub fn can_advance(&self) -> bool { - self.next_point.is_some() + self.pending_next_point.is_some() } pub fn transaction_number(&self) -> u64 { @@ -1279,11 +1279,8 @@ impl HolderCommitmentPoint { self.point } - pub fn next_point(&self) -> Option { - self.next_point - } - - /// If we are pending the next commitment point, this method tries asking the signer again. + /// If we are pending advancing the next commitment point, this method tries asking the signer + /// again. pub fn try_resolve_pending( &mut self, signer: &ChannelSignerType, secp_ctx: &Secp256k1, logger: &L, ) where @@ -1291,20 +1288,20 @@ impl HolderCommitmentPoint { L::Target: Logger, { if !self.can_advance() { - let next = + let pending_next_point = signer.as_ref().get_per_commitment_point(self.transaction_number - 1, secp_ctx); - if let Ok(next) = next { + if let Ok(point) = pending_next_point { log_trace!( logger, - "Retrieved next per-commitment point {}", + "Retrieved per-commitment point {} for next advancement", self.transaction_number - 1 ); - self.next_point = Some(next); + self.pending_next_point = Some(point); } else { log_trace!( logger, - "Next per-commitment point {} is pending", - self.transaction_number + "Pending per-commitment point {} for next advancement", + self.transaction_number - 1 ); } } @@ -1327,11 +1324,11 @@ impl HolderCommitmentPoint { SP::Target: SignerProvider, L::Target: Logger, { - if let Some(next_point) = self.next_point { + if let Some(next_point) = self.pending_next_point { *self = Self { transaction_number: self.transaction_number - 1, point: next_point, - next_point: None, + pending_next_point: None, }; self.try_resolve_pending(signer, secp_ctx, logger); @@ -13202,7 +13199,7 @@ where // `HolderCommitmentPoint::point` will become optional when async signing is implemented. let holder_commitment_point = Some(self.holder_commitment_point.point()); - let holder_commitment_point_next_advance = self.holder_commitment_point.next_point(); + let holder_commitment_point_pending_next = self.holder_commitment_point.pending_next_point; write_tlv_fields!(writer, { (0, self.context.announcement_sigs, option), @@ -13241,7 +13238,7 @@ where (41, holding_cell_blinding_points, optional_vec), (43, malformed_htlcs, optional_vec), // Added in 0.0.119 (45, holder_commitment_point, option), - (47, holder_commitment_point_next_advance, option), + (47, holder_commitment_point_pending_next, option), (49, self.context.local_initiated_shutdown, option), // Added in 0.0.122 (51, is_manual_broadcast, option), // Added in 0.0.124 (53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124 @@ -13602,7 +13599,7 @@ where let mut monitor_pending_update_adds: Option> = None; let mut holder_commitment_point_opt: Option = None; - let mut holder_commitment_point_next_advance_opt: Option = None; + let mut holder_commitment_point_pending_next_opt: Option = None; let mut is_manual_broadcast = None; let mut pending_funding = Some(Vec::new()); @@ -13643,7 +13640,7 @@ where (41, holding_cell_blinding_points_opt, optional_vec), (43, malformed_htlcs, optional_vec), // Added in 0.0.119 (45, holder_commitment_point_opt, option), - (47, holder_commitment_point_next_advance_opt, option), + (47, holder_commitment_point_pending_next_opt, option), (49, local_initiated_shutdown, option), (51, is_manual_broadcast, option), (53, funding_tx_broadcast_safe_event_emitted, option), @@ -13832,27 +13829,27 @@ where // signer be available so that we can immediately populate the current commitment point. Channel // restoration will fail if this is not possible. let holder_commitment_point = - match (holder_commitment_point_opt, holder_commitment_point_next_advance_opt) { - (Some(point), next_point) => HolderCommitmentPoint { + match (holder_commitment_point_opt, holder_commitment_point_pending_next_opt) { + (Some(point), pending_next_point) => HolderCommitmentPoint { transaction_number: holder_commitment_transaction_number, point, - next_point, + pending_next_point, }, (_, _) => { let point = holder_signer.get_per_commitment_point(holder_commitment_transaction_number, &secp_ctx) .expect("Must be able to derive the current commitment point upon channel restoration"); - let next_point = holder_signer + let pending_next_point = holder_signer .get_per_commitment_point( holder_commitment_transaction_number - 1, &secp_ctx, ) .expect( - "Must be able to derive the next commitment point upon channel restoration", + "Must be able to derive the pending next commitment point upon channel restoration", ); HolderCommitmentPoint { transaction_number: holder_commitment_transaction_number, point, - next_point: Some(next_point), + pending_next_point: Some(pending_next_point), } }, }; From 27138ebe0c106eeec80f9cf75e7404171e1da9d3 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Mon, 18 Aug 2025 13:07:28 -0500 Subject: [PATCH 3/7] Rename HolderCommitmentPoint::point HolderCommitmentPoint::point represents the next point we expect to receive. Rename it to next_point to reflect that and similarly rename transaction_number. The next commit will add the current point, which is needed in splicing. --- lightning/src/ln/channel.rs | 108 +++++++++++++++++++----------------- 1 file changed, 56 insertions(+), 52 deletions(-) diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index d1a05b31010..7d4983f28cf 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -1250,8 +1250,8 @@ pub(crate) struct ShutdownResult { /// commitment points from our signer. #[derive(Debug, Copy, Clone)] struct HolderCommitmentPoint { - transaction_number: u64, - point: PublicKey, + next_transaction_number: u64, + next_point: PublicKey, pending_next_point: Option, } @@ -1261,8 +1261,8 @@ impl HolderCommitmentPoint { where SP::Target: SignerProvider { Some(HolderCommitmentPoint { - transaction_number: INITIAL_COMMITMENT_NUMBER, - point: signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER, secp_ctx).ok()?, + next_transaction_number: INITIAL_COMMITMENT_NUMBER, + next_point: signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER, secp_ctx).ok()?, pending_next_point: signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, secp_ctx).ok(), }) } @@ -1271,12 +1271,12 @@ impl HolderCommitmentPoint { self.pending_next_point.is_some() } - pub fn transaction_number(&self) -> u64 { - self.transaction_number + pub fn next_transaction_number(&self) -> u64 { + self.next_transaction_number } - pub fn point(&self) -> PublicKey { - self.point + pub fn next_point(&self) -> PublicKey { + self.next_point } /// If we are pending advancing the next commitment point, this method tries asking the signer @@ -1288,20 +1288,21 @@ impl HolderCommitmentPoint { L::Target: Logger, { if !self.can_advance() { - let pending_next_point = - signer.as_ref().get_per_commitment_point(self.transaction_number - 1, secp_ctx); + let pending_next_point = signer + .as_ref() + .get_per_commitment_point(self.next_transaction_number - 1, secp_ctx); if let Ok(point) = pending_next_point { log_trace!( logger, "Retrieved per-commitment point {} for next advancement", - self.transaction_number - 1 + self.next_transaction_number - 1 ); self.pending_next_point = Some(point); } else { log_trace!( logger, "Pending per-commitment point {} for next advancement", - self.transaction_number - 1 + self.next_transaction_number - 1 ); } } @@ -1326,8 +1327,8 @@ impl HolderCommitmentPoint { { if let Some(next_point) = self.pending_next_point { *self = Self { - transaction_number: self.transaction_number - 1, - point: next_point, + next_transaction_number: self.next_transaction_number - 1, + next_point, pending_next_point: None, }; @@ -1787,7 +1788,7 @@ where &mut funding, &mut signing_session, true, - chan.holder_commitment_point.transaction_number(), + chan.holder_commitment_point.next_transaction_number(), &&logger, )?; @@ -2001,7 +2002,7 @@ impl UnfundedChannelContext { fn transaction_number(&self) -> u64 { self.holder_commitment_point .as_ref() - .map(|point| point.transaction_number()) + .map(|point| point.next_transaction_number()) .unwrap_or(INITIAL_COMMITMENT_NUMBER) } } @@ -2745,7 +2746,7 @@ where let funding_script = self.funding().get_funding_redeemscript(); let commitment_data = self.context().build_commitment_transaction(self.funding(), - holder_commitment_point.transaction_number(), &holder_commitment_point.point(), + holder_commitment_point.next_transaction_number(), &holder_commitment_point.next_point(), true, false, logger); let initial_commitment_tx = commitment_data.tx; let trusted_tx = initial_commitment_tx.trust(); @@ -4192,7 +4193,7 @@ where let funding_script = funding.get_funding_redeemscript(); let commitment_data = self.build_commitment_transaction(funding, - holder_commitment_point.transaction_number(), &holder_commitment_point.point(), + holder_commitment_point.next_transaction_number(), &holder_commitment_point.next_point(), true, false, logger); let commitment_txid = { let trusted_tx = commitment_data.tx.trust(); @@ -6942,7 +6943,7 @@ where } let holder_commitment_point = &mut self.holder_commitment_point.clone(); - self.context.assert_no_commitment_advancement(holder_commitment_point.transaction_number(), "initial commitment_signed"); + self.context.assert_no_commitment_advancement(holder_commitment_point.next_transaction_number(), "initial commitment_signed"); let (channel_monitor, _) = self.initial_commitment_signed( self.context.channel_id(), msg.signature, holder_commitment_point, best_block, signer_provider, logger)?; @@ -8483,17 +8484,17 @@ where #[rustfmt::skip] fn get_last_revoke_and_ack(&mut self, logger: &L) -> Option where L::Target: Logger { - debug_assert!(self.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER - 2); + debug_assert!(self.holder_commitment_point.next_transaction_number() <= INITIAL_COMMITMENT_NUMBER - 2); self.holder_commitment_point.try_resolve_pending(&self.context.holder_signer, &self.context.secp_ctx, logger); let per_commitment_secret = self.context.holder_signer.as_ref() - .release_commitment_secret(self.holder_commitment_point.transaction_number() + 2).ok(); + .release_commitment_secret(self.holder_commitment_point.next_transaction_number() + 2).ok(); if let Some(per_commitment_secret) = per_commitment_secret { if self.holder_commitment_point.can_advance() { self.context.signer_pending_revoke_and_ack = false; return Some(msgs::RevokeAndACK { channel_id: self.context.channel_id, per_commitment_secret, - next_per_commitment_point: self.holder_commitment_point.point(), + next_per_commitment_point: self.holder_commitment_point.next_point(), #[cfg(taproot)] next_local_nonce: None, }) @@ -8501,12 +8502,12 @@ where } if !self.holder_commitment_point.can_advance() { log_trace!(logger, "Last revoke-and-ack pending in channel {} for sequence {} because the next per-commitment point is not available", - &self.context.channel_id(), self.holder_commitment_point.transaction_number()); + &self.context.channel_id(), self.holder_commitment_point.next_transaction_number()); } if per_commitment_secret.is_none() { log_trace!(logger, "Last revoke-and-ack pending in channel {} for sequence {} because the next per-commitment secret for {} is not available", - &self.context.channel_id(), self.holder_commitment_point.transaction_number(), - self.holder_commitment_point.transaction_number() + 2); + &self.context.channel_id(), self.holder_commitment_point.next_transaction_number(), + self.holder_commitment_point.next_transaction_number() + 2); } // Technically if HolderCommitmentPoint::can_advance is false, // we have a commitment point ready to send in an RAA, however we @@ -8515,7 +8516,7 @@ where // RAA here is a convenient way to make sure that post-funding // we're only ever waiting on one commitment point at a time. log_trace!(logger, "Last revoke-and-ack pending in channel {} for sequence {} because the next per-commitment point is not available", - &self.context.channel_id(), self.holder_commitment_point.transaction_number()); + &self.context.channel_id(), self.holder_commitment_point.next_transaction_number()); self.context.signer_pending_revoke_and_ack = true; None } @@ -8663,7 +8664,7 @@ where return Err(ChannelError::close("Peer sent an invalid channel_reestablish to force close in a non-standard way".to_owned())); } - let our_commitment_transaction = INITIAL_COMMITMENT_NUMBER - self.holder_commitment_point.transaction_number() - 1; + let our_commitment_transaction = INITIAL_COMMITMENT_NUMBER - self.holder_commitment_point.next_transaction_number() - 1; if msg.next_remote_commitment_number > 0 { let expected_point = self.context.holder_signer.as_ref() .get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - msg.next_remote_commitment_number + 1, &self.context.secp_ctx) @@ -8765,7 +8766,7 @@ where let is_awaiting_remote_revoke = self.context.channel_state.is_awaiting_remote_revoke(); let next_counterparty_commitment_number = INITIAL_COMMITMENT_NUMBER - self.context.cur_counterparty_commitment_transaction_number + if is_awaiting_remote_revoke { 1 } else { 0 }; - let channel_ready = if msg.next_local_commitment_number == 1 && INITIAL_COMMITMENT_NUMBER - self.holder_commitment_point.transaction_number() == 1 { + let channel_ready = if msg.next_local_commitment_number == 1 && INITIAL_COMMITMENT_NUMBER - self.holder_commitment_point.next_transaction_number() == 1 { // We should never have to worry about MonitorUpdateInProgress resending ChannelReady self.get_channel_ready(logger) } else { None }; @@ -9590,7 +9591,7 @@ where } pub fn get_cur_holder_commitment_transaction_number(&self) -> u64 { - self.holder_commitment_point.transaction_number() + 1 + self.holder_commitment_point.next_transaction_number() + 1 } pub fn get_cur_counterparty_commitment_transaction_number(&self) -> u64 { @@ -9714,7 +9715,7 @@ where debug_assert!(self.context.minimum_depth.unwrap_or(1) > 0); return true; } - if self.holder_commitment_point.transaction_number() == INITIAL_COMMITMENT_NUMBER - 1 && + if self.holder_commitment_point.next_transaction_number() == INITIAL_COMMITMENT_NUMBER - 1 && self.context.cur_counterparty_commitment_transaction_number == INITIAL_COMMITMENT_NUMBER - 1 { // If we're a 0-conf channel, we'll move beyond AwaitingChannelReady immediately even while // waiting for the initial monitor persistence. Thus, we check if our commitment @@ -9852,7 +9853,7 @@ where self.context.signer_pending_channel_ready = false; Some(msgs::ChannelReady { channel_id: self.context.channel_id(), - next_per_commitment_point: self.holder_commitment_point.point(), + next_per_commitment_point: self.holder_commitment_point.next_point(), short_channel_id_alias: Some(self.context.outbound_scid_alias), }) } else { @@ -10555,7 +10556,7 @@ where // next_local_commitment_number is the next commitment_signed number we expect to // receive (indicating if they need to resend one that we missed). - next_local_commitment_number: INITIAL_COMMITMENT_NUMBER - self.holder_commitment_point.transaction_number(), + next_local_commitment_number: INITIAL_COMMITMENT_NUMBER - self.holder_commitment_point.next_transaction_number(), // We have to set next_remote_commitment_number to the next revoke_and_ack we expect to // receive, however we track it by the next commitment number for a remote transaction // (which is one further, as they always revoke previous commitment transaction, not @@ -11963,7 +11964,7 @@ where let first_per_commitment_point = match self.unfunded_context.holder_commitment_point { Some(holder_commitment_point) if holder_commitment_point.can_advance() => { self.signer_pending_open_channel = false; - holder_commitment_point.point() + holder_commitment_point.next_point() }, _ => { log_trace!(_logger, "Unable to generate open_channel message, waiting for commitment point"); @@ -12035,7 +12036,7 @@ where Some(point) => point, None => return Err((self, ChannelError::close("Received funding_signed before our first commitment point was available".to_owned()))), }; - self.context.assert_no_commitment_advancement(holder_commitment_point.transaction_number(), "funding_signed"); + self.context.assert_no_commitment_advancement(holder_commitment_point.next_transaction_number(), "funding_signed"); let (channel_monitor, _) = match self.initial_commitment_signed( self.context.channel_id(), msg.signature, @@ -12237,7 +12238,7 @@ where let first_per_commitment_point = match self.unfunded_context.holder_commitment_point { Some(holder_commitment_point) if holder_commitment_point.can_advance() => { self.signer_pending_accept_channel = false; - holder_commitment_point.point() + holder_commitment_point.next_point() }, _ => { log_trace!(_logger, "Unable to generate accept_channel message, waiting for commitment point"); @@ -12311,7 +12312,7 @@ where Some(point) => point, None => return Err((self, ChannelError::close("Received funding_created before our first commitment point was available".to_owned()))), }; - self.context.assert_no_commitment_advancement(holder_commitment_point.transaction_number(), "funding_created"); + self.context.assert_no_commitment_advancement(holder_commitment_point.next_transaction_number(), "funding_created"); let funding_txo = OutPoint { txid: msg.funding_txid, index: msg.funding_output_index }; self.funding.channel_transaction_parameters.funding_outpoint = Some(funding_txo); @@ -12866,7 +12867,7 @@ where } self.context.destination_script.write(writer)?; - self.holder_commitment_point.transaction_number().write(writer)?; + self.holder_commitment_point.next_transaction_number().write(writer)?; self.context.cur_counterparty_commitment_transaction_number.write(writer)?; self.funding.value_to_self_msat.write(writer)?; @@ -13197,8 +13198,8 @@ where } let is_manual_broadcast = Some(self.context.is_manual_broadcast); - // `HolderCommitmentPoint::point` will become optional when async signing is implemented. - let holder_commitment_point = Some(self.holder_commitment_point.point()); + // `HolderCommitmentPoint::next_point` will become optional when async signing is implemented. + let holder_commitment_point_next = Some(self.holder_commitment_point.next_point()); let holder_commitment_point_pending_next = self.holder_commitment_point.pending_next_point; write_tlv_fields!(writer, { @@ -13237,7 +13238,7 @@ where (39, pending_outbound_blinding_points, optional_vec), (41, holding_cell_blinding_points, optional_vec), (43, malformed_htlcs, optional_vec), // Added in 0.0.119 - (45, holder_commitment_point, option), + (45, holder_commitment_point_next, option), (47, holder_commitment_point_pending_next, option), (49, self.context.local_initiated_shutdown, option), // Added in 0.0.122 (51, is_manual_broadcast, option), // Added in 0.0.124 @@ -13295,7 +13296,7 @@ where }; let destination_script = Readable::read(reader)?; - let holder_commitment_transaction_number = Readable::read(reader)?; + let holder_commitment_next_transaction_number = Readable::read(reader)?; let cur_counterparty_commitment_transaction_number = Readable::read(reader)?; let value_to_self_msat = Readable::read(reader)?; @@ -13598,7 +13599,7 @@ where let mut malformed_htlcs: Option> = None; let mut monitor_pending_update_adds: Option> = None; - let mut holder_commitment_point_opt: Option = None; + let mut holder_commitment_point_next_opt: Option = None; let mut holder_commitment_point_pending_next_opt: Option = None; let mut is_manual_broadcast = None; @@ -13639,7 +13640,7 @@ where (39, pending_outbound_blinding_points_opt, optional_vec), (41, holding_cell_blinding_points_opt, optional_vec), (43, malformed_htlcs, optional_vec), // Added in 0.0.119 - (45, holder_commitment_point_opt, option), + (45, holder_commitment_point_next_opt, option), (47, holder_commitment_point_pending_next_opt, option), (49, local_initiated_shutdown, option), (51, is_manual_broadcast, option), @@ -13829,26 +13830,29 @@ where // signer be available so that we can immediately populate the current commitment point. Channel // restoration will fail if this is not possible. let holder_commitment_point = - match (holder_commitment_point_opt, holder_commitment_point_pending_next_opt) { - (Some(point), pending_next_point) => HolderCommitmentPoint { - transaction_number: holder_commitment_transaction_number, - point, + match (holder_commitment_point_next_opt, holder_commitment_point_pending_next_opt) { + (Some(next_point), pending_next_point) => HolderCommitmentPoint { + next_transaction_number: holder_commitment_next_transaction_number, + next_point, pending_next_point, }, (_, _) => { - let point = holder_signer.get_per_commitment_point(holder_commitment_transaction_number, &secp_ctx) - .expect("Must be able to derive the current commitment point upon channel restoration"); + let next_point = holder_signer + .get_per_commitment_point(holder_commitment_next_transaction_number, &secp_ctx) + .expect( + "Must be able to derive the next commitment point upon channel restoration", + ); let pending_next_point = holder_signer .get_per_commitment_point( - holder_commitment_transaction_number - 1, + holder_commitment_next_transaction_number - 1, &secp_ctx, ) .expect( "Must be able to derive the pending next commitment point upon channel restoration", ); HolderCommitmentPoint { - transaction_number: holder_commitment_transaction_number, - point, + next_transaction_number: holder_commitment_next_transaction_number, + next_point, pending_next_point: Some(pending_next_point), } }, From a7ba4dd358a73ee6ab517335e7624870d1fead36 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Mon, 18 Aug 2025 14:23:15 -0500 Subject: [PATCH 4/7] Store current_point in HolderCommitmentPoint When splicing a channel, sending and receiving the initial commitment_signed message should use the current commitment point rather then the next one. Store this in HolderCommitmentPoint whenever it is advanced. --- lightning/src/ln/channel.rs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 7d4983f28cf..3d035b9bfea 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -1251,6 +1251,7 @@ pub(crate) struct ShutdownResult { #[derive(Debug, Copy, Clone)] struct HolderCommitmentPoint { next_transaction_number: u64, + current_point: Option, next_point: PublicKey, pending_next_point: Option, } @@ -1262,6 +1263,7 @@ impl HolderCommitmentPoint { { Some(HolderCommitmentPoint { next_transaction_number: INITIAL_COMMITMENT_NUMBER, + current_point: None, next_point: signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER, secp_ctx).ok()?, pending_next_point: signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, secp_ctx).ok(), }) @@ -1271,6 +1273,14 @@ impl HolderCommitmentPoint { self.pending_next_point.is_some() } + pub fn current_transaction_number(&self) -> u64 { + self.next_transaction_number + 1 + } + + pub fn current_point(&self) -> Option { + self.current_point + } + pub fn next_transaction_number(&self) -> u64 { self.next_transaction_number } @@ -1328,6 +1338,7 @@ impl HolderCommitmentPoint { if let Some(next_point) = self.pending_next_point { *self = Self { next_transaction_number: self.next_transaction_number - 1, + current_point: Some(self.next_point), next_point, pending_next_point: None, }; @@ -9591,7 +9602,7 @@ where } pub fn get_cur_holder_commitment_transaction_number(&self) -> u64 { - self.holder_commitment_point.next_transaction_number() + 1 + self.holder_commitment_point.current_transaction_number() } pub fn get_cur_counterparty_commitment_transaction_number(&self) -> u64 { @@ -10582,6 +10593,15 @@ where our_funding_inputs: Vec<(TxIn, Transaction, Weight)>, change_script: Option, funding_feerate_per_kw: u32, locktime: u32, ) -> Result { + if self.holder_commitment_point.current_point().is_none() { + return Err(APIError::APIMisuseError { + err: format!( + "Channel {} cannot be spliced, commitment point needs to be advanced once", + self.context.channel_id(), + ), + }); + } + // Check if a splice has been initiated already. // Note: only a single outstanding splice is supported (per spec) if self.pending_splice.is_some() { @@ -10683,6 +10703,13 @@ where // TODO(splicing): Add check that we are the quiescence acceptor + if self.holder_commitment_point.current_point().is_none() { + return Err(ChannelError::Warn(format!( + "Channel {} commitment point needs to be advanced once before spliced", + self.context.channel_id(), + ))); + } + // Check if a splice has been initiated already. if self.pending_splice.is_some() { return Err(ChannelError::WarnAndDisconnect(format!( @@ -13198,6 +13225,7 @@ where } let is_manual_broadcast = Some(self.context.is_manual_broadcast); + let holder_commitment_point_current = self.holder_commitment_point.current_point(); // `HolderCommitmentPoint::next_point` will become optional when async signing is implemented. let holder_commitment_point_next = Some(self.holder_commitment_point.next_point()); let holder_commitment_point_pending_next = self.holder_commitment_point.pending_next_point; @@ -13250,6 +13278,7 @@ where (59, self.funding.minimum_depth_override, option), // Added in 0.2 (60, self.context.historical_scids, optional_vec), // Added in 0.2 (61, fulfill_attribution_data, optional_vec), // Added in 0.2 + (63, holder_commitment_point_current, option), // Added in 0.2 }); Ok(()) @@ -13599,6 +13628,7 @@ where let mut malformed_htlcs: Option> = None; let mut monitor_pending_update_adds: Option> = None; + let mut holder_commitment_point_current_opt: Option = None; let mut holder_commitment_point_next_opt: Option = None; let mut holder_commitment_point_pending_next_opt: Option = None; let mut is_manual_broadcast = None; @@ -13652,6 +13682,7 @@ where (59, minimum_depth_override, option), // Added in 0.2 (60, historical_scids, optional_vec), // Added in 0.2 (61, fulfill_attribution_data, optional_vec), // Added in 0.2 + (63, holder_commitment_point_current_opt, option), // Added in 0.2 }); let holder_signer = signer_provider.derive_channel_signer(channel_keys_id); @@ -13833,6 +13864,7 @@ where match (holder_commitment_point_next_opt, holder_commitment_point_pending_next_opt) { (Some(next_point), pending_next_point) => HolderCommitmentPoint { next_transaction_number: holder_commitment_next_transaction_number, + current_point: None, next_point, pending_next_point, }, @@ -13852,6 +13884,7 @@ where ); HolderCommitmentPoint { next_transaction_number: holder_commitment_next_transaction_number, + current_point: holder_commitment_point_current_opt, next_point, pending_next_point: Some(pending_next_point), } From c8af714f2cadbbc6b18b5876b56976570b037383 Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Thu, 14 Aug 2025 15:03:56 -0500 Subject: [PATCH 5/7] Check correct commitment number/point in initial commitment_signed When splicing a channel, the initial commitment_signed received should use the same commitment number and point previously received prior to splicing the channel. Account for this by checking the commitment_signed against that one instead, which is now stored separately in FundedChannel. --- lightning/src/ln/channel.rs | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 3d035b9bfea..b2f88d2332e 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -4195,7 +4195,7 @@ where #[rustfmt::skip] fn validate_commitment_signed( - &self, funding: &FundingScope, holder_commitment_point: &HolderCommitmentPoint, + &self, funding: &FundingScope, transaction_number: u64, commitment_point: PublicKey, msg: &msgs::CommitmentSigned, logger: &L, ) -> Result<(HolderCommitmentTransaction, Vec<(HTLCOutputInCommitment, Option<&HTLCSource>)>), ChannelError> where @@ -4203,9 +4203,9 @@ where { let funding_script = funding.get_funding_redeemscript(); - let commitment_data = self.build_commitment_transaction(funding, - holder_commitment_point.next_transaction_number(), &holder_commitment_point.next_point(), - true, false, logger); + let commitment_data = self.build_commitment_transaction( + funding, transaction_number, &commitment_point, true, false, logger, + ); let commitment_txid = { let trusted_tx = commitment_data.tx.trust(); let bitcoin_tx = trusted_tx.built_transaction(); @@ -7003,9 +7003,15 @@ where }) .and_then(|funding_negotiation| funding_negotiation.as_funding()) .expect("Funding must exist for negotiated pending splice"); + let transaction_number = self.holder_commitment_point.current_transaction_number(); + let commitment_point = self + .holder_commitment_point + .current_point() + .expect("current should be set after receiving the initial commitment_signed"); let (holder_commitment_tx, _) = self.context.validate_commitment_signed( pending_splice_funding, - &self.holder_commitment_point, + transaction_number, + commitment_point, msg, logger, )?; @@ -7089,9 +7095,17 @@ where )); } + let transaction_number = self.holder_commitment_point.next_transaction_number(); + let commitment_point = self.holder_commitment_point.next_point(); let update = self .context - .validate_commitment_signed(&self.funding, &self.holder_commitment_point, msg, logger) + .validate_commitment_signed( + &self.funding, + transaction_number, + commitment_point, + msg, + logger, + ) .map(|(commitment_tx, htlcs_included)| { let (nondust_htlc_sources, dust_htlcs) = Self::get_commitment_htlc_data(&htlcs_included); @@ -7153,9 +7167,12 @@ where funding_txid )) })?; + let transaction_number = self.holder_commitment_point.next_transaction_number(); + let commitment_point = self.holder_commitment_point.next_point(); let (commitment_tx, htlcs_included) = self.context.validate_commitment_signed( funding, - &self.holder_commitment_point, + transaction_number, + commitment_point, msg, logger, )?; From 87db06abb7c726f469e894cb17d3d646d7f6fa5b Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Fri, 1 Aug 2025 12:58:09 -0500 Subject: [PATCH 6/7] Use correct commitment number/point in initial commitment_signed When splicing a channel, the initial commitment_signed should use the same commitment number and point previously sent. Account for this by adjusting these to use the previous commitment number and point, since the next expected one is stored. --- lightning/src/ln/channel.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index b2f88d2332e..5777ea406c7 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -5590,10 +5590,19 @@ where SP::Target: SignerProvider, L::Target: Logger, { + let mut commitment_number = self.cur_counterparty_commitment_transaction_number; + let mut commitment_point = self.counterparty_cur_commitment_point.unwrap(); + + // Use the previous commitment number and point when splicing since they shouldn't change. + if commitment_number != INITIAL_COMMITMENT_NUMBER { + commitment_number += 1; + commitment_point = self.counterparty_prev_commitment_point.unwrap(); + } + let commitment_data = self.build_commitment_transaction( funding, - self.cur_counterparty_commitment_transaction_number, - &self.counterparty_cur_commitment_point.unwrap(), + commitment_number, + &commitment_point, false, false, logger, @@ -7021,8 +7030,8 @@ where .context .build_commitment_transaction( pending_splice_funding, - self.context.cur_counterparty_commitment_transaction_number, - &self.context.counterparty_cur_commitment_point.unwrap(), + self.context.cur_counterparty_commitment_transaction_number + 1, + &self.context.counterparty_prev_commitment_point.unwrap(), false, false, logger, From 13c81a1566c85c453f05c1cf37dbb365d45ceb0f Mon Sep 17 00:00:00 2001 From: Jeffrey Czyz Date: Fri, 15 Aug 2025 14:56:17 -0500 Subject: [PATCH 7/7] Drop outdated async signing comment --- lightning/src/ln/channel.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 5777ea406c7..3c7a57cf958 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -13252,8 +13252,7 @@ where let is_manual_broadcast = Some(self.context.is_manual_broadcast); let holder_commitment_point_current = self.holder_commitment_point.current_point(); - // `HolderCommitmentPoint::next_point` will become optional when async signing is implemented. - let holder_commitment_point_next = Some(self.holder_commitment_point.next_point()); + let holder_commitment_point_next = self.holder_commitment_point.next_point(); let holder_commitment_point_pending_next = self.holder_commitment_point.pending_next_point; write_tlv_fields!(writer, { @@ -13292,7 +13291,7 @@ where (39, pending_outbound_blinding_points, optional_vec), (41, holding_cell_blinding_points, optional_vec), (43, malformed_htlcs, optional_vec), // Added in 0.0.119 - (45, holder_commitment_point_next, option), + (45, holder_commitment_point_next, required), (47, holder_commitment_point_pending_next, option), (49, self.context.local_initiated_shutdown, option), // Added in 0.0.122 (51, is_manual_broadcast, option), // Added in 0.0.124