Skip to content

Commit 053e9e2

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 1f8a7d7 commit 053e9e2

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
@@ -2499,7 +2499,7 @@ where
24992499
// Our commitment numbers start at 2^48-1 and count down, whereas the ones used in transaction
25002500
// generation start at 0 and count up...this simplifies some parts of implementation at the
25012501
// cost of others, but should really just be changed.
2502-
cur_counterparty_commitment_transaction_number: u64,
2502+
counterparty_next_commitment_transaction_number: u64,
25032503
pending_inbound_htlcs: Vec<InboundHTLCOutput>,
25042504
pending_outbound_htlcs: Vec<OutboundHTLCOutput>,
25052505
holding_cell_htlc_updates: Vec<HTLCUpdateAwaitingACK>,
@@ -2798,7 +2798,7 @@ where
27982798
};
27992799
let context = self.context();
28002800
let commitment_data = context.build_commitment_transaction(self.funding(),
2801-
context.cur_counterparty_commitment_transaction_number,
2801+
context.counterparty_next_commitment_transaction_number,
28022802
&context.counterparty_cur_commitment_point.unwrap(), false, false, logger);
28032803
let counterparty_initial_commitment_tx = commitment_data.tx;
28042804
let counterparty_trusted_tx = counterparty_initial_commitment_tx.trust();
@@ -2859,7 +2859,7 @@ where
28592859
counterparty_initial_commitment_tx.clone(),
28602860
);
28612861

2862-
self.context_mut().cur_counterparty_commitment_transaction_number -= 1;
2862+
self.context_mut().counterparty_next_commitment_transaction_number -= 1;
28632863

28642864
Ok((channel_monitor, counterparty_initial_commitment_tx))
28652865
}
@@ -3224,7 +3224,7 @@ where
32243224
shutdown_scriptpubkey,
32253225
destination_script,
32263226

3227-
cur_counterparty_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
3227+
counterparty_next_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
32283228

32293229
pending_inbound_htlcs: Vec::new(),
32303230
pending_outbound_htlcs: Vec::new(),
@@ -3462,7 +3462,7 @@ where
34623462
shutdown_scriptpubkey,
34633463
destination_script,
34643464

3465-
cur_counterparty_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
3465+
counterparty_next_commitment_transaction_number: INITIAL_COMMITMENT_NUMBER,
34663466

34673467
pending_inbound_htlcs: Vec::new(),
34683468
pending_outbound_htlcs: Vec::new(),
@@ -5540,7 +5540,7 @@ where
55405540
if is_splice {
55415541
debug_assert_eq!(
55425542
holder_commitment_transaction_number,
5543-
self.cur_counterparty_commitment_transaction_number,
5543+
self.counterparty_next_commitment_transaction_number,
55445544
);
55455545
// TODO(splicing) Forced error, as the use case is not complete
55465546
return Err(msgs::TxAbort {
@@ -5572,7 +5572,7 @@ where
55725572
&self, holder_commitment_transaction_number: u64, msg_name: &str,
55735573
) {
55745574
if self.commitment_secrets.get_min_seen_secret() != (1 << 48)
5575-
|| self.cur_counterparty_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER
5575+
|| self.counterparty_next_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER
55765576
|| holder_commitment_transaction_number != INITIAL_COMMITMENT_NUMBER
55775577
{
55785578
debug_assert!(
@@ -5590,7 +5590,7 @@ where
55905590
SP::Target: SignerProvider,
55915591
L::Target: Logger,
55925592
{
5593-
let mut commitment_number = self.cur_counterparty_commitment_transaction_number;
5593+
let mut commitment_number = self.counterparty_next_commitment_transaction_number;
55945594
let mut commitment_point = self.counterparty_cur_commitment_point.unwrap();
55955595

55965596
// Use the previous commitment number and point when splicing since they shouldn't change.
@@ -6752,11 +6752,11 @@ where
67526752
// They probably disconnected/reconnected and re-sent the channel_ready, which is
67536753
// required, or they're sending a fresh SCID alias.
67546754
let expected_point =
6755-
if self.context.cur_counterparty_commitment_transaction_number == INITIAL_COMMITMENT_NUMBER - 1 {
6755+
if self.context.counterparty_next_commitment_transaction_number == INITIAL_COMMITMENT_NUMBER - 1 {
67566756
// If they haven't ever sent an updated point, the point they send should match
67576757
// the current one.
67586758
self.context.counterparty_cur_commitment_point
6759-
} else if self.context.cur_counterparty_commitment_transaction_number == INITIAL_COMMITMENT_NUMBER - 2 {
6759+
} else if self.context.counterparty_next_commitment_transaction_number == INITIAL_COMMITMENT_NUMBER - 2 {
67606760
// If we've advanced the commitment number once, the second commitment point is
67616761
// at `counterparty_prev_commitment_point`, which is not yet revoked.
67626762
debug_assert!(self.context.counterparty_prev_commitment_point.is_some());
@@ -7003,7 +7003,7 @@ where
70037003
.context
70047004
.build_commitment_transaction(
70057005
pending_splice_funding,
7006-
self.context.cur_counterparty_commitment_transaction_number + 1,
7006+
self.context.counterparty_next_commitment_transaction_number + 1,
70077007
&self.context.counterparty_prev_commitment_point.unwrap(),
70087008
false,
70097009
false,
@@ -7626,7 +7626,7 @@ where
76267626
ChannelSignerType::Ecdsa(ecdsa) => {
76277627
ecdsa
76287628
.validate_counterparty_revocation(
7629-
self.context.cur_counterparty_commitment_transaction_number + 1,
7629+
self.context.counterparty_next_commitment_transaction_number + 1,
76307630
&secret,
76317631
)
76327632
.map_err(|_| {
@@ -7641,7 +7641,7 @@ where
76417641
self.context
76427642
.commitment_secrets
76437643
.provide_secret(
7644-
self.context.cur_counterparty_commitment_transaction_number + 1,
7644+
self.context.counterparty_next_commitment_transaction_number + 1,
76457645
msg.per_commitment_secret,
76467646
)
76477647
.map_err(|_| {
@@ -7651,7 +7651,7 @@ where
76517651
let mut monitor_update = ChannelMonitorUpdate {
76527652
update_id: self.context.latest_monitor_update_id,
76537653
updates: vec![ChannelMonitorUpdateStep::CommitmentSecret {
7654-
idx: self.context.cur_counterparty_commitment_transaction_number + 1,
7654+
idx: self.context.counterparty_next_commitment_transaction_number + 1,
76557655
secret: msg.per_commitment_secret,
76567656
}],
76577657
channel_id: Some(self.context.channel_id()),
@@ -7666,7 +7666,7 @@ where
76667666
self.context.counterparty_prev_commitment_point =
76677667
self.context.counterparty_cur_commitment_point;
76687668
self.context.counterparty_cur_commitment_point = Some(msg.next_per_commitment_point);
7669-
self.context.cur_counterparty_commitment_transaction_number -= 1;
7669+
self.context.counterparty_next_commitment_transaction_number -= 1;
76707670

76717671
if self.context.announcement_sigs_state == AnnouncementSigsState::Committed {
76727672
self.context.announcement_sigs_state = AnnouncementSigsState::PeerReceived;
@@ -8403,7 +8403,7 @@ where
84038403
}
84048404
let funding_signed = if self.context.signer_pending_funding && !self.funding.is_outbound() {
84058405
let commitment_data = self.context.build_commitment_transaction(&self.funding,
8406-
self.context.cur_counterparty_commitment_transaction_number + 1,
8406+
self.context.counterparty_next_commitment_transaction_number + 1,
84078407
&self.context.counterparty_cur_commitment_point.unwrap(), false, false, logger);
84088408
let counterparty_initial_commitment_tx = commitment_data.tx;
84098409
self.context.get_funding_signed_msg(&self.funding.channel_transaction_parameters, logger, counterparty_initial_commitment_tx)
@@ -8769,12 +8769,12 @@ where
87698769
)));
87708770
};
87718771

8772-
// We increment cur_counterparty_commitment_transaction_number only upon receipt of
8772+
// We increment counterparty_next_commitment_transaction_number only upon receipt of
87738773
// revoke_and_ack, not on sending commitment_signed, so we add one if have
87748774
// AwaitingRemoteRevoke set, which indicates we sent a commitment_signed but haven't gotten
87758775
// the corresponding revoke_and_ack back yet.
87768776
let is_awaiting_remote_revoke = self.context.channel_state.is_awaiting_remote_revoke();
8777-
let next_counterparty_commitment_number = INITIAL_COMMITMENT_NUMBER - self.context.cur_counterparty_commitment_transaction_number + if is_awaiting_remote_revoke { 1 } else { 0 };
8777+
let next_counterparty_commitment_number = INITIAL_COMMITMENT_NUMBER - self.context.counterparty_next_commitment_transaction_number + if is_awaiting_remote_revoke { 1 } else { 0 };
87788778

87798779
let channel_ready = if msg.next_local_commitment_number == 1 && INITIAL_COMMITMENT_NUMBER - self.holder_commitment_point.next_transaction_number() == 1 {
87808780
// We should never have to worry about MonitorUpdateInProgress resending ChannelReady
@@ -9605,12 +9605,12 @@ where
96059605
}
96069606

96079607
pub fn get_cur_counterparty_commitment_transaction_number(&self) -> u64 {
9608-
self.context.cur_counterparty_commitment_transaction_number + 1
9608+
self.context.counterparty_next_commitment_transaction_number + 1
96099609
- if self.context.channel_state.is_awaiting_remote_revoke() { 1 } else { 0 }
96109610
}
96119611

96129612
pub fn get_revoked_counterparty_commitment_transaction_number(&self) -> u64 {
9613-
self.context.cur_counterparty_commitment_transaction_number + 2
9613+
self.context.counterparty_next_commitment_transaction_number + 2
96149614
}
96159615

96169616
#[cfg(any(test, feature = "_externalize_tests"))]
@@ -9726,7 +9726,7 @@ where
97269726
return true;
97279727
}
97289728
if self.holder_commitment_point.next_transaction_number() == INITIAL_COMMITMENT_NUMBER - 1 &&
9729-
self.context.cur_counterparty_commitment_transaction_number == INITIAL_COMMITMENT_NUMBER - 1 {
9729+
self.context.counterparty_next_commitment_transaction_number == INITIAL_COMMITMENT_NUMBER - 1 {
97309730
// If we're a 0-conf channel, we'll move beyond AwaitingChannelReady immediately even while
97319731
// waiting for the initial monitor persistence. Thus, we check if our commitment
97329732
// transaction numbers have both been iterated only exactly once (for the
@@ -10513,7 +10513,7 @@ where
1051310513
#[rustfmt::skip]
1051410514
fn get_channel_reestablish<L: Deref>(&mut self, logger: &L) -> msgs::ChannelReestablish where L::Target: Logger {
1051510515
assert!(self.context.channel_state.is_peer_disconnected());
10516-
assert_ne!(self.context.cur_counterparty_commitment_transaction_number, INITIAL_COMMITMENT_NUMBER);
10516+
assert_ne!(self.context.counterparty_next_commitment_transaction_number, INITIAL_COMMITMENT_NUMBER);
1051710517
// This is generally the first function which gets called on any given channel once we're
1051810518
// up and running normally. Thus, we take this opportunity to attempt to resolve the
1051910519
// `holder_commitment_point` to get any keys which we are currently missing.
@@ -10528,8 +10528,8 @@ where
1052810528
// valid, and valid in fuzzing mode's arbitrary validity criteria:
1052910529
let mut pk = [2; 33]; pk[1] = 0xff;
1053010530
let dummy_pubkey = PublicKey::from_slice(&pk).unwrap();
10531-
let remote_last_secret = if self.context.cur_counterparty_commitment_transaction_number + 1 < INITIAL_COMMITMENT_NUMBER {
10532-
let remote_last_secret = self.context.commitment_secrets.get_secret(self.context.cur_counterparty_commitment_transaction_number + 2).unwrap();
10531+
let remote_last_secret = if self.context.counterparty_next_commitment_transaction_number + 1 < INITIAL_COMMITMENT_NUMBER {
10532+
let remote_last_secret = self.context.commitment_secrets.get_secret(self.context.counterparty_next_commitment_transaction_number + 2).unwrap();
1053310533
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());
1053410534
remote_last_secret
1053510535
} else {
@@ -10552,10 +10552,10 @@ where
1055210552
// receive, however we track it by the next commitment number for a remote transaction
1055310553
// (which is one further, as they always revoke previous commitment transaction, not
1055410554
// the one we send) so we have to decrement by 1. Note that if
10555-
// cur_counterparty_commitment_transaction_number is INITIAL_COMMITMENT_NUMBER we will have
10555+
// counterparty_next_commitment_transaction_number is INITIAL_COMMITMENT_NUMBER we will have
1055610556
// dropped this channel on disconnect as it hasn't yet reached AwaitingChannelReady so we can't
1055710557
// overflow here.
10558-
next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.context.cur_counterparty_commitment_transaction_number - 1,
10558+
next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.context.counterparty_next_commitment_transaction_number - 1,
1055910559
your_last_per_commitment_secret: remote_last_secret,
1056010560
my_current_per_commitment_point: dummy_pubkey,
1056110561
next_funding_txid: self.maybe_get_next_funding_txid(),
@@ -11174,7 +11174,7 @@ where
1117411174
ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTXInfo {
1117511175
commitment_txid: counterparty_commitment_tx.trust().txid(),
1117611176
htlc_outputs,
11177-
commitment_number: self.context.cur_counterparty_commitment_transaction_number,
11177+
commitment_number: self.context.counterparty_next_commitment_transaction_number,
1117811178
their_per_commitment_point: self.context.counterparty_cur_commitment_point.unwrap(),
1117911179
feerate_per_kw: Some(counterparty_commitment_tx.feerate_per_kw()),
1118011180
to_broadcaster_value_sat: Some(counterparty_commitment_tx.to_broadcaster_value_sat()),
@@ -11231,7 +11231,7 @@ where
1123111231
L::Target: Logger,
1123211232
{
1123311233
let commitment_data = self.context.build_commitment_transaction(
11234-
funding, self.context.cur_counterparty_commitment_transaction_number,
11234+
funding, self.context.counterparty_next_commitment_transaction_number,
1123511235
&self.context.counterparty_cur_commitment_point.unwrap(), false, true, logger,
1123611236
);
1123711237
let counterparty_commitment_tx = commitment_data.tx;
@@ -11282,7 +11282,7 @@ where
1128211282
self.build_commitment_no_state_update(funding, logger);
1128311283

1128411284
let commitment_data = self.context.build_commitment_transaction(
11285-
funding, self.context.cur_counterparty_commitment_transaction_number,
11285+
funding, self.context.counterparty_next_commitment_transaction_number,
1128611286
&self.context.counterparty_cur_commitment_point.unwrap(), false, true, logger,
1128711287
);
1128811288
let counterparty_commitment_tx = commitment_data.tx;
@@ -11850,7 +11850,7 @@ where
1185011850
#[rustfmt::skip]
1185111851
fn get_funding_created_msg<L: Deref>(&mut self, logger: &L) -> Option<msgs::FundingCreated> where L::Target: Logger {
1185211852
let commitment_data = self.context.build_commitment_transaction(&self.funding,
11853-
self.context.cur_counterparty_commitment_transaction_number,
11853+
self.context.counterparty_next_commitment_transaction_number,
1185411854
&self.context.counterparty_cur_commitment_point.unwrap(), false, false, logger);
1185511855
let counterparty_initial_commitment_tx = commitment_data.tx;
1185611856
let signature = match &self.context.holder_signer {
@@ -12875,7 +12875,7 @@ where
1287512875
self.context.destination_script.write(writer)?;
1287612876

1287712877
self.holder_commitment_point.next_transaction_number().write(writer)?;
12878-
self.context.cur_counterparty_commitment_transaction_number.write(writer)?;
12878+
self.context.counterparty_next_commitment_transaction_number.write(writer)?;
1287912879
self.funding.value_to_self_msat.write(writer)?;
1288012880

1288112881
let mut dropped_inbound_htlcs = 0;
@@ -13305,7 +13305,7 @@ where
1330513305
let destination_script = Readable::read(reader)?;
1330613306

1330713307
let holder_commitment_next_transaction_number = Readable::read(reader)?;
13308-
let cur_counterparty_commitment_transaction_number = Readable::read(reader)?;
13308+
let counterparty_next_commitment_transaction_number = Readable::read(reader)?;
1330913309
let value_to_self_msat = Readable::read(reader)?;
1331013310

1331113311
let pending_inbound_htlc_count: u64 = Readable::read(reader)?;
@@ -13934,7 +13934,7 @@ where
1393413934
shutdown_scriptpubkey,
1393513935
destination_script,
1393613936

13937-
cur_counterparty_commitment_transaction_number,
13937+
counterparty_next_commitment_transaction_number,
1393813938

1393913939
holder_max_accepted_htlcs,
1394013940
pending_inbound_htlcs,

0 commit comments

Comments
 (0)