Skip to content

Commit 27138eb

Browse files
committed
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.
1 parent 8c48293 commit 27138eb

File tree

1 file changed

+56
-52
lines changed

1 file changed

+56
-52
lines changed

lightning/src/ln/channel.rs

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,8 +1250,8 @@ pub(crate) struct ShutdownResult {
12501250
/// commitment points from our signer.
12511251
#[derive(Debug, Copy, Clone)]
12521252
struct HolderCommitmentPoint {
1253-
transaction_number: u64,
1254-
point: PublicKey,
1253+
next_transaction_number: u64,
1254+
next_point: PublicKey,
12551255
pending_next_point: Option<PublicKey>,
12561256
}
12571257

@@ -1261,8 +1261,8 @@ impl HolderCommitmentPoint {
12611261
where SP::Target: SignerProvider
12621262
{
12631263
Some(HolderCommitmentPoint {
1264-
transaction_number: INITIAL_COMMITMENT_NUMBER,
1265-
point: signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER, secp_ctx).ok()?,
1264+
next_transaction_number: INITIAL_COMMITMENT_NUMBER,
1265+
next_point: signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER, secp_ctx).ok()?,
12661266
pending_next_point: signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, secp_ctx).ok(),
12671267
})
12681268
}
@@ -1271,12 +1271,12 @@ impl HolderCommitmentPoint {
12711271
self.pending_next_point.is_some()
12721272
}
12731273

1274-
pub fn transaction_number(&self) -> u64 {
1275-
self.transaction_number
1274+
pub fn next_transaction_number(&self) -> u64 {
1275+
self.next_transaction_number
12761276
}
12771277

1278-
pub fn point(&self) -> PublicKey {
1279-
self.point
1278+
pub fn next_point(&self) -> PublicKey {
1279+
self.next_point
12801280
}
12811281

12821282
/// If we are pending advancing the next commitment point, this method tries asking the signer
@@ -1288,20 +1288,21 @@ impl HolderCommitmentPoint {
12881288
L::Target: Logger,
12891289
{
12901290
if !self.can_advance() {
1291-
let pending_next_point =
1292-
signer.as_ref().get_per_commitment_point(self.transaction_number - 1, secp_ctx);
1291+
let pending_next_point = signer
1292+
.as_ref()
1293+
.get_per_commitment_point(self.next_transaction_number - 1, secp_ctx);
12931294
if let Ok(point) = pending_next_point {
12941295
log_trace!(
12951296
logger,
12961297
"Retrieved per-commitment point {} for next advancement",
1297-
self.transaction_number - 1
1298+
self.next_transaction_number - 1
12981299
);
12991300
self.pending_next_point = Some(point);
13001301
} else {
13011302
log_trace!(
13021303
logger,
13031304
"Pending per-commitment point {} for next advancement",
1304-
self.transaction_number - 1
1305+
self.next_transaction_number - 1
13051306
);
13061307
}
13071308
}
@@ -1326,8 +1327,8 @@ impl HolderCommitmentPoint {
13261327
{
13271328
if let Some(next_point) = self.pending_next_point {
13281329
*self = Self {
1329-
transaction_number: self.transaction_number - 1,
1330-
point: next_point,
1330+
next_transaction_number: self.next_transaction_number - 1,
1331+
next_point,
13311332
pending_next_point: None,
13321333
};
13331334

@@ -1787,7 +1788,7 @@ where
17871788
&mut funding,
17881789
&mut signing_session,
17891790
true,
1790-
chan.holder_commitment_point.transaction_number(),
1791+
chan.holder_commitment_point.next_transaction_number(),
17911792
&&logger,
17921793
)?;
17931794

@@ -2001,7 +2002,7 @@ impl UnfundedChannelContext {
20012002
fn transaction_number(&self) -> u64 {
20022003
self.holder_commitment_point
20032004
.as_ref()
2004-
.map(|point| point.transaction_number())
2005+
.map(|point| point.next_transaction_number())
20052006
.unwrap_or(INITIAL_COMMITMENT_NUMBER)
20062007
}
20072008
}
@@ -2745,7 +2746,7 @@ where
27452746
let funding_script = self.funding().get_funding_redeemscript();
27462747

27472748
let commitment_data = self.context().build_commitment_transaction(self.funding(),
2748-
holder_commitment_point.transaction_number(), &holder_commitment_point.point(),
2749+
holder_commitment_point.next_transaction_number(), &holder_commitment_point.next_point(),
27492750
true, false, logger);
27502751
let initial_commitment_tx = commitment_data.tx;
27512752
let trusted_tx = initial_commitment_tx.trust();
@@ -4192,7 +4193,7 @@ where
41924193
let funding_script = funding.get_funding_redeemscript();
41934194

41944195
let commitment_data = self.build_commitment_transaction(funding,
4195-
holder_commitment_point.transaction_number(), &holder_commitment_point.point(),
4196+
holder_commitment_point.next_transaction_number(), &holder_commitment_point.next_point(),
41964197
true, false, logger);
41974198
let commitment_txid = {
41984199
let trusted_tx = commitment_data.tx.trust();
@@ -6942,7 +6943,7 @@ where
69426943
}
69436944

69446945
let holder_commitment_point = &mut self.holder_commitment_point.clone();
6945-
self.context.assert_no_commitment_advancement(holder_commitment_point.transaction_number(), "initial commitment_signed");
6946+
self.context.assert_no_commitment_advancement(holder_commitment_point.next_transaction_number(), "initial commitment_signed");
69466947

69476948
let (channel_monitor, _) = self.initial_commitment_signed(
69486949
self.context.channel_id(), msg.signature, holder_commitment_point, best_block, signer_provider, logger)?;
@@ -8483,30 +8484,30 @@ where
84838484

84848485
#[rustfmt::skip]
84858486
fn get_last_revoke_and_ack<L: Deref>(&mut self, logger: &L) -> Option<msgs::RevokeAndACK> where L::Target: Logger {
8486-
debug_assert!(self.holder_commitment_point.transaction_number() <= INITIAL_COMMITMENT_NUMBER - 2);
8487+
debug_assert!(self.holder_commitment_point.next_transaction_number() <= INITIAL_COMMITMENT_NUMBER - 2);
84878488
self.holder_commitment_point.try_resolve_pending(&self.context.holder_signer, &self.context.secp_ctx, logger);
84888489
let per_commitment_secret = self.context.holder_signer.as_ref()
8489-
.release_commitment_secret(self.holder_commitment_point.transaction_number() + 2).ok();
8490+
.release_commitment_secret(self.holder_commitment_point.next_transaction_number() + 2).ok();
84908491
if let Some(per_commitment_secret) = per_commitment_secret {
84918492
if self.holder_commitment_point.can_advance() {
84928493
self.context.signer_pending_revoke_and_ack = false;
84938494
return Some(msgs::RevokeAndACK {
84948495
channel_id: self.context.channel_id,
84958496
per_commitment_secret,
8496-
next_per_commitment_point: self.holder_commitment_point.point(),
8497+
next_per_commitment_point: self.holder_commitment_point.next_point(),
84978498
#[cfg(taproot)]
84988499
next_local_nonce: None,
84998500
})
85008501
}
85018502
}
85028503
if !self.holder_commitment_point.can_advance() {
85038504
log_trace!(logger, "Last revoke-and-ack pending in channel {} for sequence {} because the next per-commitment point is not available",
8504-
&self.context.channel_id(), self.holder_commitment_point.transaction_number());
8505+
&self.context.channel_id(), self.holder_commitment_point.next_transaction_number());
85058506
}
85068507
if per_commitment_secret.is_none() {
85078508
log_trace!(logger, "Last revoke-and-ack pending in channel {} for sequence {} because the next per-commitment secret for {} is not available",
8508-
&self.context.channel_id(), self.holder_commitment_point.transaction_number(),
8509-
self.holder_commitment_point.transaction_number() + 2);
8509+
&self.context.channel_id(), self.holder_commitment_point.next_transaction_number(),
8510+
self.holder_commitment_point.next_transaction_number() + 2);
85108511
}
85118512
// Technically if HolderCommitmentPoint::can_advance is false,
85128513
// we have a commitment point ready to send in an RAA, however we
@@ -8515,7 +8516,7 @@ where
85158516
// RAA here is a convenient way to make sure that post-funding
85168517
// we're only ever waiting on one commitment point at a time.
85178518
log_trace!(logger, "Last revoke-and-ack pending in channel {} for sequence {} because the next per-commitment point is not available",
8518-
&self.context.channel_id(), self.holder_commitment_point.transaction_number());
8519+
&self.context.channel_id(), self.holder_commitment_point.next_transaction_number());
85198520
self.context.signer_pending_revoke_and_ack = true;
85208521
None
85218522
}
@@ -8663,7 +8664,7 @@ where
86638664
return Err(ChannelError::close("Peer sent an invalid channel_reestablish to force close in a non-standard way".to_owned()));
86648665
}
86658666

8666-
let our_commitment_transaction = INITIAL_COMMITMENT_NUMBER - self.holder_commitment_point.transaction_number() - 1;
8667+
let our_commitment_transaction = INITIAL_COMMITMENT_NUMBER - self.holder_commitment_point.next_transaction_number() - 1;
86678668
if msg.next_remote_commitment_number > 0 {
86688669
let expected_point = self.context.holder_signer.as_ref()
86698670
.get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - msg.next_remote_commitment_number + 1, &self.context.secp_ctx)
@@ -8765,7 +8766,7 @@ where
87658766
let is_awaiting_remote_revoke = self.context.channel_state.is_awaiting_remote_revoke();
87668767
let next_counterparty_commitment_number = INITIAL_COMMITMENT_NUMBER - self.context.cur_counterparty_commitment_transaction_number + if is_awaiting_remote_revoke { 1 } else { 0 };
87678768

8768-
let channel_ready = if msg.next_local_commitment_number == 1 && INITIAL_COMMITMENT_NUMBER - self.holder_commitment_point.transaction_number() == 1 {
8769+
let channel_ready = if msg.next_local_commitment_number == 1 && INITIAL_COMMITMENT_NUMBER - self.holder_commitment_point.next_transaction_number() == 1 {
87698770
// We should never have to worry about MonitorUpdateInProgress resending ChannelReady
87708771
self.get_channel_ready(logger)
87718772
} else { None };
@@ -9590,7 +9591,7 @@ where
95909591
}
95919592

95929593
pub fn get_cur_holder_commitment_transaction_number(&self) -> u64 {
9593-
self.holder_commitment_point.transaction_number() + 1
9594+
self.holder_commitment_point.next_transaction_number() + 1
95949595
}
95959596

95969597
pub fn get_cur_counterparty_commitment_transaction_number(&self) -> u64 {
@@ -9714,7 +9715,7 @@ where
97149715
debug_assert!(self.context.minimum_depth.unwrap_or(1) > 0);
97159716
return true;
97169717
}
9717-
if self.holder_commitment_point.transaction_number() == INITIAL_COMMITMENT_NUMBER - 1 &&
9718+
if self.holder_commitment_point.next_transaction_number() == INITIAL_COMMITMENT_NUMBER - 1 &&
97189719
self.context.cur_counterparty_commitment_transaction_number == INITIAL_COMMITMENT_NUMBER - 1 {
97199720
// If we're a 0-conf channel, we'll move beyond AwaitingChannelReady immediately even while
97209721
// waiting for the initial monitor persistence. Thus, we check if our commitment
@@ -9852,7 +9853,7 @@ where
98529853
self.context.signer_pending_channel_ready = false;
98539854
Some(msgs::ChannelReady {
98549855
channel_id: self.context.channel_id(),
9855-
next_per_commitment_point: self.holder_commitment_point.point(),
9856+
next_per_commitment_point: self.holder_commitment_point.next_point(),
98569857
short_channel_id_alias: Some(self.context.outbound_scid_alias),
98579858
})
98589859
} else {
@@ -10555,7 +10556,7 @@ where
1055510556

1055610557
// next_local_commitment_number is the next commitment_signed number we expect to
1055710558
// receive (indicating if they need to resend one that we missed).
10558-
next_local_commitment_number: INITIAL_COMMITMENT_NUMBER - self.holder_commitment_point.transaction_number(),
10559+
next_local_commitment_number: INITIAL_COMMITMENT_NUMBER - self.holder_commitment_point.next_transaction_number(),
1055910560
// We have to set next_remote_commitment_number to the next revoke_and_ack we expect to
1056010561
// receive, however we track it by the next commitment number for a remote transaction
1056110562
// (which is one further, as they always revoke previous commitment transaction, not
@@ -11963,7 +11964,7 @@ where
1196311964
let first_per_commitment_point = match self.unfunded_context.holder_commitment_point {
1196411965
Some(holder_commitment_point) if holder_commitment_point.can_advance() => {
1196511966
self.signer_pending_open_channel = false;
11966-
holder_commitment_point.point()
11967+
holder_commitment_point.next_point()
1196711968
},
1196811969
_ => {
1196911970
log_trace!(_logger, "Unable to generate open_channel message, waiting for commitment point");
@@ -12035,7 +12036,7 @@ where
1203512036
Some(point) => point,
1203612037
None => return Err((self, ChannelError::close("Received funding_signed before our first commitment point was available".to_owned()))),
1203712038
};
12038-
self.context.assert_no_commitment_advancement(holder_commitment_point.transaction_number(), "funding_signed");
12039+
self.context.assert_no_commitment_advancement(holder_commitment_point.next_transaction_number(), "funding_signed");
1203912040

1204012041
let (channel_monitor, _) = match self.initial_commitment_signed(
1204112042
self.context.channel_id(), msg.signature,
@@ -12237,7 +12238,7 @@ where
1223712238
let first_per_commitment_point = match self.unfunded_context.holder_commitment_point {
1223812239
Some(holder_commitment_point) if holder_commitment_point.can_advance() => {
1223912240
self.signer_pending_accept_channel = false;
12240-
holder_commitment_point.point()
12241+
holder_commitment_point.next_point()
1224112242
},
1224212243
_ => {
1224312244
log_trace!(_logger, "Unable to generate accept_channel message, waiting for commitment point");
@@ -12311,7 +12312,7 @@ where
1231112312
Some(point) => point,
1231212313
None => return Err((self, ChannelError::close("Received funding_created before our first commitment point was available".to_owned()))),
1231312314
};
12314-
self.context.assert_no_commitment_advancement(holder_commitment_point.transaction_number(), "funding_created");
12315+
self.context.assert_no_commitment_advancement(holder_commitment_point.next_transaction_number(), "funding_created");
1231512316

1231612317
let funding_txo = OutPoint { txid: msg.funding_txid, index: msg.funding_output_index };
1231712318
self.funding.channel_transaction_parameters.funding_outpoint = Some(funding_txo);
@@ -12866,7 +12867,7 @@ where
1286612867
}
1286712868
self.context.destination_script.write(writer)?;
1286812869

12869-
self.holder_commitment_point.transaction_number().write(writer)?;
12870+
self.holder_commitment_point.next_transaction_number().write(writer)?;
1287012871
self.context.cur_counterparty_commitment_transaction_number.write(writer)?;
1287112872
self.funding.value_to_self_msat.write(writer)?;
1287212873

@@ -13197,8 +13198,8 @@ where
1319713198
}
1319813199
let is_manual_broadcast = Some(self.context.is_manual_broadcast);
1319913200

13200-
// `HolderCommitmentPoint::point` will become optional when async signing is implemented.
13201-
let holder_commitment_point = Some(self.holder_commitment_point.point());
13201+
// `HolderCommitmentPoint::next_point` will become optional when async signing is implemented.
13202+
let holder_commitment_point_next = Some(self.holder_commitment_point.next_point());
1320213203
let holder_commitment_point_pending_next = self.holder_commitment_point.pending_next_point;
1320313204

1320413205
write_tlv_fields!(writer, {
@@ -13237,7 +13238,7 @@ where
1323713238
(39, pending_outbound_blinding_points, optional_vec),
1323813239
(41, holding_cell_blinding_points, optional_vec),
1323913240
(43, malformed_htlcs, optional_vec), // Added in 0.0.119
13240-
(45, holder_commitment_point, option),
13241+
(45, holder_commitment_point_next, option),
1324113242
(47, holder_commitment_point_pending_next, option),
1324213243
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
1324313244
(51, is_manual_broadcast, option), // Added in 0.0.124
@@ -13295,7 +13296,7 @@ where
1329513296
};
1329613297
let destination_script = Readable::read(reader)?;
1329713298

13298-
let holder_commitment_transaction_number = Readable::read(reader)?;
13299+
let holder_commitment_next_transaction_number = Readable::read(reader)?;
1329913300
let cur_counterparty_commitment_transaction_number = Readable::read(reader)?;
1330013301
let value_to_self_msat = Readable::read(reader)?;
1330113302

@@ -13598,7 +13599,7 @@ where
1359813599
let mut malformed_htlcs: Option<Vec<(u64, u16, [u8; 32])>> = None;
1359913600
let mut monitor_pending_update_adds: Option<Vec<msgs::UpdateAddHTLC>> = None;
1360013601

13601-
let mut holder_commitment_point_opt: Option<PublicKey> = None;
13602+
let mut holder_commitment_point_next_opt: Option<PublicKey> = None;
1360213603
let mut holder_commitment_point_pending_next_opt: Option<PublicKey> = None;
1360313604
let mut is_manual_broadcast = None;
1360413605

@@ -13639,7 +13640,7 @@ where
1363913640
(39, pending_outbound_blinding_points_opt, optional_vec),
1364013641
(41, holding_cell_blinding_points_opt, optional_vec),
1364113642
(43, malformed_htlcs, optional_vec), // Added in 0.0.119
13642-
(45, holder_commitment_point_opt, option),
13643+
(45, holder_commitment_point_next_opt, option),
1364313644
(47, holder_commitment_point_pending_next_opt, option),
1364413645
(49, local_initiated_shutdown, option),
1364513646
(51, is_manual_broadcast, option),
@@ -13829,26 +13830,29 @@ where
1382913830
// signer be available so that we can immediately populate the current commitment point. Channel
1383013831
// restoration will fail if this is not possible.
1383113832
let holder_commitment_point =
13832-
match (holder_commitment_point_opt, holder_commitment_point_pending_next_opt) {
13833-
(Some(point), pending_next_point) => HolderCommitmentPoint {
13834-
transaction_number: holder_commitment_transaction_number,
13835-
point,
13833+
match (holder_commitment_point_next_opt, holder_commitment_point_pending_next_opt) {
13834+
(Some(next_point), pending_next_point) => HolderCommitmentPoint {
13835+
next_transaction_number: holder_commitment_next_transaction_number,
13836+
next_point,
1383613837
pending_next_point,
1383713838
},
1383813839
(_, _) => {
13839-
let point = holder_signer.get_per_commitment_point(holder_commitment_transaction_number, &secp_ctx)
13840-
.expect("Must be able to derive the current commitment point upon channel restoration");
13840+
let next_point = holder_signer
13841+
.get_per_commitment_point(holder_commitment_next_transaction_number, &secp_ctx)
13842+
.expect(
13843+
"Must be able to derive the next commitment point upon channel restoration",
13844+
);
1384113845
let pending_next_point = holder_signer
1384213846
.get_per_commitment_point(
13843-
holder_commitment_transaction_number - 1,
13847+
holder_commitment_next_transaction_number - 1,
1384413848
&secp_ctx,
1384513849
)
1384613850
.expect(
1384713851
"Must be able to derive the pending next commitment point upon channel restoration",
1384813852
);
1384913853
HolderCommitmentPoint {
13850-
transaction_number: holder_commitment_transaction_number,
13851-
point,
13854+
next_transaction_number: holder_commitment_next_transaction_number,
13855+
next_point,
1385213856
pending_next_point: Some(pending_next_point),
1385313857
}
1385413858
},

0 commit comments

Comments
 (0)