Skip to content

Commit 9d7ec5f

Browse files
committed
Rename ChannelContext::cur_counterparty_commitment_transaction_number
To align with the "current" and "next" nomenclature used by HolderCommitmentPoint, update the naming of the counterparty commitment transaction number field to use "next" instead of "current".
1 parent 6f78d57 commit 9d7ec5f

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

lightning/src/ln/channel.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2525,7 +2525,7 @@ where
25252525
// Our commitment numbers start at 2^48-1 and count down, whereas the ones used in transaction
25262526
// generation start at 0 and count up...this simplifies some parts of implementation at the
25272527
// cost of others, but should really just be changed.
2528-
cur_counterparty_commitment_transaction_number: u64,
2528+
counterparty_next_commitment_transaction_number: u64,
25292529
pending_inbound_htlcs: Vec<InboundHTLCOutput>,
25302530
pending_outbound_htlcs: Vec<OutboundHTLCOutput>,
25312531
holding_cell_htlc_updates: Vec<HTLCUpdateAwaitingACK>,
@@ -2820,7 +2820,7 @@ where
28202820
};
28212821
let context = self.context();
28222822
let commitment_data = context.build_commitment_transaction(self.funding(),
2823-
context.cur_counterparty_commitment_transaction_number,
2823+
context.counterparty_next_commitment_transaction_number,
28242824
&context.counterparty_cur_commitment_point.unwrap(), false, false, logger);
28252825
let counterparty_initial_commitment_tx = commitment_data.tx;
28262826
let counterparty_trusted_tx = counterparty_initial_commitment_tx.trust();
@@ -2881,7 +2881,7 @@ where
28812881
counterparty_initial_commitment_tx.clone(),
28822882
);
28832883

2884-
self.context_mut().cur_counterparty_commitment_transaction_number -= 1;
2884+
self.context_mut().counterparty_next_commitment_transaction_number -= 1;
28852885

28862886
Ok((channel_monitor, counterparty_initial_commitment_tx))
28872887
}
@@ -3246,7 +3246,7 @@ where
32463246
shutdown_scriptpubkey,
32473247
destination_script,
32483248

3249-
cur_counterparty_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
3249+
counterparty_next_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
32503250

32513251
pending_inbound_htlcs: Vec::new(),
32523252
pending_outbound_htlcs: Vec::new(),
@@ -3482,7 +3482,7 @@ where
34823482
shutdown_scriptpubkey,
34833483
destination_script,
34843484

3485-
cur_counterparty_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
3485+
counterparty_next_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
34863486

34873487
pending_inbound_htlcs: Vec::new(),
34883488
pending_outbound_htlcs: Vec::new(),
@@ -5558,7 +5558,7 @@ where
55585558
if is_splice {
55595559
debug_assert_eq!(
55605560
holder_commitment_transaction_number,
5561-
self.cur_counterparty_commitment_transaction_number,
5561+
self.counterparty_next_commitment_transaction_number,
55625562
);
55635563
// TODO(splicing) Forced error, as the use case is not complete
55645564
return Err(msgs::TxAbort {
@@ -5590,7 +5590,7 @@ where
55905590
&self, holder_commitment_transaction_number: u64, msg_name: &str,
55915591
) {
55925592
if self.commitment_secrets.get_min_seen_secret() != (1 << 48)
5593-
|| self.cur_counterparty_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER
5593+
|| self.counterparty_next_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER
55945594
|| holder_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER
55955595
{
55965596
debug_assert!(
@@ -5608,7 +5608,7 @@ where
56085608
SP::Target: SignerProvider,
56095609
L::Target: Logger,
56105610
{
5611-
let mut commitment_number = self.cur_counterparty_commitment_transaction_number;
5611+
let mut commitment_number = self.counterparty_next_commitment_transaction_number;
56125612
let mut commitment_point = self.counterparty_cur_commitment_point.unwrap();
56135613

56145614
// Use the previous commitment number and point when splicing since they shouldn't change.
@@ -6776,11 +6776,11 @@ where
67766776
// They probably disconnected/reconnected and re-sent the channel_ready, which is
67776777
// required, or they're sending a fresh SCID alias.
67786778
let expected_point =
6779-
if self.context.cur_counterparty_commitment_transaction_number == INITIAL_COMMITMENT_NUMBER - 1 {
6779+
if self.context.counterparty_next_commitment_transaction_number == INITIAL_COMMITMENT_NUMBER - 1 {
67806780
// If they haven't ever sent an updated point, the point they send should match
67816781
// the current one.
67826782
self.context.counterparty_cur_commitment_point
6783-
} else if self.context.cur_counterparty_commitment_transaction_number == INITIAL_COMMITMENT_NUMBER - 2 {
6783+
} else if self.context.counterparty_next_commitment_transaction_number == INITIAL_COMMITMENT_NUMBER - 2 {
67846784
// If we've advanced the commitment number once, the second commitment point is
67856785
// at `counterparty_prev_commitment_point`, which is not yet revoked.
67866786
debug_assert!(self.context.counterparty_prev_commitment_point.is_some());
@@ -7027,7 +7027,7 @@ where
70277027
.context
70287028
.build_commitment_transaction(
70297029
pending_splice_funding,
7030-
self.context.cur_counterparty_commitment_transaction_number + 1,
7030+
self.context.counterparty_next_commitment_transaction_number + 1,
70317031
&self.context.counterparty_prev_commitment_point.unwrap(),
70327032
false,
70337033
false,
@@ -7650,7 +7650,7 @@ where
76507650
ChannelSignerType::Ecdsa(ecdsa) => {
76517651
ecdsa
76527652
.validate_counterparty_revocation(
7653-
self.context.cur_counterparty_commitment_transaction_number + 1,
7653+
self.context.counterparty_next_commitment_transaction_number + 1,
76547654
&secret,
76557655
)
76567656
.map_err(|_| {
@@ -7665,7 +7665,7 @@ where
76657665
self.context
76667666
.commitment_secrets
76677667
.provide_secret(
7668-
self.context.cur_counterparty_commitment_transaction_number + 1,
7668+
self.context.counterparty_next_commitment_transaction_number + 1,
76697669
msg.per_commitment_secret,
76707670
)
76717671
.map_err(|_| {
@@ -7675,7 +7675,7 @@ where
76757675
let mut monitor_update = ChannelMonitorUpdate {
76767676
update_id: self.context.latest_monitor_update_id,
76777677
updates: vec![ChannelMonitorUpdateStep::CommitmentSecret {
7678-
idx: self.context.cur_counterparty_commitment_transaction_number + 1,
7678+
idx: self.context.counterparty_next_commitment_transaction_number + 1,
76797679
secret: msg.per_commitment_secret,
76807680
}],
76817681
channel_id: Some(self.context.channel_id()),
@@ -7690,7 +7690,7 @@ where
76907690
self.context.counterparty_prev_commitment_point =
76917691
self.context.counterparty_cur_commitment_point;
76927692
self.context.counterparty_cur_commitment_point = Some(msg.next_per_commitment_point);
7693-
self.context.cur_counterparty_commitment_transaction_number -= 1;
7693+
self.context.counterparty_next_commitment_transaction_number -= 1;
76947694

76957695
if self.context.announcement_sigs_state == AnnouncementSigsState::Committed {
76967696
self.context.announcement_sigs_state = AnnouncementSigsState::PeerReceived;
@@ -8429,7 +8429,7 @@ where
84298429
}
84308430
let funding_signed = if self.context.signer_pending_funding && !self.funding.is_outbound() {
84318431
let commitment_data = self.context.build_commitment_transaction(&self.funding,
8432-
self.context.cur_counterparty_commitment_transaction_number + 1,
8432+
self.context.counterparty_next_commitment_transaction_number + 1,
84338433
&self.context.counterparty_cur_commitment_point.unwrap(), false, false, logger);
84348434
let counterparty_initial_commitment_tx = commitment_data.tx;
84358435
self.context.get_funding_signed_msg(&self.funding.channel_transaction_parameters, logger, counterparty_initial_commitment_tx)
@@ -8795,12 +8795,12 @@ where
87958795
)));
87968796
};
87978797

8798-
// We increment cur_counterparty_commitment_transaction_number only upon receipt of
8798+
// We increment counterparty_next_commitment_transaction_number only upon receipt of
87998799
// revoke_and_ack, not on sending commitment_signed, so we add one if have
88008800
// AwaitingRemoteRevoke set, which indicates we sent a commitment_signed but haven't gotten
88018801
// the corresponding revoke_and_ack back yet.
88028802
let is_awaiting_remote_revoke = self.context.channel_state.is_awaiting_remote_revoke();
8803-
let next_counterparty_commitment_number = INITIAL_COMMITMENT_NUMBER - self.context.cur_counterparty_commitment_transaction_number + if is_awaiting_remote_revoke { 1 } else { 0 };
8803+
let next_counterparty_commitment_number = INITIAL_COMMITMENT_NUMBER - self.context.counterparty_next_commitment_transaction_number + if is_awaiting_remote_revoke { 1 } else { 0 };
88048804

88058805
let channel_ready = if msg.next_local_commitment_number == 1 && INITIAL_COMMITMENT_NUMBER - self.holder_commitment_point.next_transaction_number() == 1 {
88068806
// We should never have to worry about MonitorUpdateInProgress resending ChannelReady
@@ -9631,12 +9631,12 @@ where
96319631
}
96329632

96339633
pub fn get_cur_counterparty_commitment_transaction_number(&self) -> u64 {
9634-
self.context.cur_counterparty_commitment_transaction_number + 1
9634+
self.context.counterparty_next_commitment_transaction_number + 1
96359635
- if self.context.channel_state.is_awaiting_remote_revoke() { 1 } else { 0 }
96369636
}
96379637

96389638
pub fn get_revoked_counterparty_commitment_transaction_number(&self) -> u64 {
9639-
let ret = self.context.cur_counterparty_commitment_transaction_number + 2;
9639+
let ret = self.context.counterparty_next_commitment_transaction_number + 2;
96409640
debug_assert_eq!(self.context.commitment_secrets.get_min_seen_secret(), ret);
96419641
ret
96429642
}
@@ -9754,7 +9754,7 @@ where
97549754
return true;
97559755
}
97569756
if self.holder_commitment_point.next_transaction_number() == INITIAL_COMMITMENT_NUMBER - 1 &&
9757-
self.context.cur_counterparty_commitment_transaction_number == INITIAL_COMMITMENT_NUMBER - 1 {
9757+
self.context.counterparty_next_commitment_transaction_number == INITIAL_COMMITMENT_NUMBER - 1 {
97589758
// If we're a 0-conf channel, we'll move beyond AwaitingChannelReady immediately even while
97599759
// waiting for the initial monitor persistence. Thus, we check if our commitment
97609760
// transaction numbers have both been iterated only exactly once (for the
@@ -10541,7 +10541,7 @@ where
1054110541
#[rustfmt::skip]
1054210542
fn get_channel_reestablish<L: Deref>(&mut self, logger: &L) -> msgs::ChannelReestablish where L::Target: Logger {
1054310543
assert!(self.context.channel_state.is_peer_disconnected());
10544-
assert_ne!(self.context.cur_counterparty_commitment_transaction_number, INITIAL_COMMITMENT_NUMBER);
10544+
assert_ne!(self.context.counterparty_next_commitment_transaction_number, INITIAL_COMMITMENT_NUMBER);
1054510545
// This is generally the first function which gets called on any given channel once we're
1054610546
// up and running normally. Thus, we take this opportunity to attempt to resolve the
1054710547
// `holder_commitment_point` to get any keys which we are currently missing.
@@ -10556,8 +10556,8 @@ where
1055610556
// valid, and valid in fuzzing mode's arbitrary validity criteria:
1055710557
let mut pk = [2; 33]; pk[1] = 0xff;
1055810558
let dummy_pubkey = PublicKey::from_slice(&pk).unwrap();
10559-
let remote_last_secret = if self.context.cur_counterparty_commitment_transaction_number + 1 < INITIAL_COMMITMENT_NUMBER {
10560-
let remote_last_secret = self.context.commitment_secrets.get_secret(self.context.cur_counterparty_commitment_transaction_number + 2).unwrap();
10559+
let remote_last_secret = if self.context.counterparty_next_commitment_transaction_number + 1 < INITIAL_COMMITMENT_NUMBER {
10560+
let remote_last_secret = self.context.commitment_secrets.get_secret(self.context.counterparty_next_commitment_transaction_number + 2).unwrap();
1056110561
log_trace!(logger, "Enough info to generate a Data Loss Protect with per_commitment_secret {} for channel {}", log_bytes!(remote_last_secret), &self.context.channel_id());
1056210562
remote_last_secret
1056310563
} else {
@@ -10580,10 +10580,10 @@ where
1058010580
// receive, however we track it by the next commitment number for a remote transaction
1058110581
// (which is one further, as they always revoke previous commitment transaction, not
1058210582
// the one we send) so we have to decrement by 1. Note that if
10583-
// cur_counterparty_commitment_transaction_number is INITIAL_COMMITMENT_NUMBER we will have
10583+
// counterparty_next_commitment_transaction_number is INITIAL_COMMITMENT_NUMBER we will have
1058410584
// dropped this channel on disconnect as it hasn't yet reached AwaitingChannelReady so we can't
1058510585
// overflow here.
10586-
next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.context.cur_counterparty_commitment_transaction_number - 1,
10586+
next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.context.counterparty_next_commitment_transaction_number - 1,
1058710587
your_last_per_commitment_secret: remote_last_secret,
1058810588
my_current_per_commitment_point: dummy_pubkey,
1058910589
next_funding_txid: self.maybe_get_next_funding_txid(),
@@ -11202,7 +11202,7 @@ where
1120211202
ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTXInfo {
1120311203
commitment_txid: counterparty_commitment_tx.trust().txid(),
1120411204
htlc_outputs,
11205-
commitment_number: self.context.cur_counterparty_commitment_transaction_number,
11205+
commitment_number: self.context.counterparty_next_commitment_transaction_number,
1120611206
their_per_commitment_point: self.context.counterparty_cur_commitment_point.unwrap(),
1120711207
feerate_per_kw: Some(counterparty_commitment_tx.feerate_per_kw()),
1120811208
to_broadcaster_value_sat: Some(counterparty_commitment_tx.to_broadcaster_value_sat()),
@@ -11259,7 +11259,7 @@ where
1125911259
L::Target: Logger,
1126011260
{
1126111261
let commitment_data = self.context.build_commitment_transaction(
11262-
funding, self.context.cur_counterparty_commitment_transaction_number,
11262+
funding, self.context.counterparty_next_commitment_transaction_number,
1126311263
&self.context.counterparty_cur_commitment_point.unwrap(), false, true, logger,
1126411264
);
1126511265
let counterparty_commitment_tx = commitment_data.tx;
@@ -11310,7 +11310,7 @@ where
1131011310
self.build_commitment_no_state_update(funding, logger);
1131111311

1131211312
let commitment_data = self.context.build_commitment_transaction(
11313-
funding, self.context.cur_counterparty_commitment_transaction_number,
11313+
funding, self.context.counterparty_next_commitment_transaction_number,
1131411314
&self.context.counterparty_cur_commitment_point.unwrap(), false, true, logger,
1131511315
);
1131611316
let counterparty_commitment_tx = commitment_data.tx;
@@ -11879,7 +11879,7 @@ where
1187911879
#[rustfmt::skip]
1188011880
fn get_funding_created_msg<L: Deref>(&mut self, logger: &L) -> Option<msgs::FundingCreated> where L::Target: Logger {
1188111881
let commitment_data = self.context.build_commitment_transaction(&self.funding,
11882-
self.context.cur_counterparty_commitment_transaction_number,
11882+
self.context.counterparty_next_commitment_transaction_number,
1188311883
&self.context.counterparty_cur_commitment_point.unwrap(), false, false, logger);
1188411884
let counterparty_initial_commitment_tx = commitment_data.tx;
1188511885
let signature = match &self.context.holder_signer {
@@ -12910,7 +12910,7 @@ where
1291012910
self.context.destination_script.write(writer)?;
1291112911

1291212912
self.holder_commitment_point.next_transaction_number().write(writer)?;
12913-
self.context.cur_counterparty_commitment_transaction_number.write(writer)?;
12913+
self.context.counterparty_next_commitment_transaction_number.write(writer)?;
1291412914
self.funding.value_to_self_msat.write(writer)?;
1291512915

1291612916
let mut dropped_inbound_htlcs = 0;
@@ -13341,7 +13341,7 @@ where
1334113341
let destination_script = Readable::read(reader)?;
1334213342

1334313343
let holder_commitment_next_transaction_number = Readable::read(reader)?;
13344-
let cur_counterparty_commitment_transaction_number = Readable::read(reader)?;
13344+
let counterparty_next_commitment_transaction_number = Readable::read(reader)?;
1334513345
let value_to_self_msat = Readable::read(reader)?;
1334613346

1334713347
let pending_inbound_htlc_count: u64 = Readable::read(reader)?;
@@ -13973,7 +13973,7 @@ where
1397313973
shutdown_scriptpubkey,
1397413974
destination_script,
1397513975

13976-
cur_counterparty_commitment_transaction_number,
13976+
counterparty_next_commitment_transaction_number,
1397713977

1397813978
holder_max_accepted_htlcs,
1397913979
pending_inbound_htlcs,

0 commit comments

Comments
 (0)