Skip to content

Correct variable names in ChannelMonitor and DRY tests - #1494

Merged
TheBlueMatt merged 4 commits into
lightningdevkit:mainfrom
TheBlueMatt:2022-05-mon-cleanups-renames
May 26, 2022
Merged

Correct variable names in ChannelMonitor and DRY tests#1494
TheBlueMatt merged 4 commits into
lightningdevkit:mainfrom
TheBlueMatt:2022-05-mon-cleanups-renames

Conversation

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

While working on #1466, i noticed a few things in ChannelMonitor are confusingly- (or mis-)named, plus monitor_tests.rs had some obvious DRY'ability. This gets those out of the way so that changes to address #1466 are simpler to read.

Several fields used in tracking on-chain HTLC outputs were
named `input_idx` despite referring to the output index in the
commitment transaction. Here they are all renamed
`commitment_tx_output_idx` for clarity.
tnull
tnull previously approved these changes May 24, 2022

@tnulltnull left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Assigning 108 as #1495 depends on it.

arik-so
arik-so previously approved these changes May 25, 2022

@arik-soarik-so left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved with comment

channel_value_satoshis: u64,
// first is the idx of the first of the two revocation points
their_cur_revocation_points: Option<(u64, PublicKey, Option<PublicKey>)>,
their_cur_per_commitment_points: Option<(u64, PublicKey, Option<PublicKey>)>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like variable names are free, so we could spell out "current" or "latest"

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ambiguous?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, just marginally easier on the reader

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, I'm trying to avoid writing out too long variable names so that rustfmt doesn't break things into more lines...unless its critical I'd prefer not to.

}
let preimage = if htlc.offered { if let Some(p) = self.payment_preimages.get(&htlc.payment_hash) { Some(*p) } else { None } } else { None };
if preimage.is_some() || !htlc.offered {
let counterparty_htlc_outp = if htlc.offered { PackageSolvingData::CounterpartyOfferedHTLCOutput(CounterpartyOfferedHTLCOutput::build(*revocation_point, self.counterparty_commitment_params.counterparty_delayed_payment_base_key, self.counterparty_commitment_params.counterparty_htlc_base_key, preimage.unwrap(), htlc.clone())) } else { PackageSolvingData::CounterpartyReceivedHTLCOutput(CounterpartyReceivedHTLCOutput::build(*revocation_point, self.counterparty_commitment_params.counterparty_delayed_payment_base_key, self.counterparty_commitment_params.counterparty_htlc_base_key, htlc.clone())) };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol how was this ever one line

Comment threadlightning/src/ln/monitor_tests.rs
Comment threadlightning/src/chain/channelmonitor.rs
@TheBlueMatt
TheBlueMatt dismissed stale reviews from arik-so and tnull via 1f69c96May 25, 2022 23:09
@TheBlueMatt
TheBlueMattforce-pushed the 2022-05-mon-cleanups-renames branch from 190a6b9 to 1f69c96CompareMay 25, 2022 23:09
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

Merging #1494 (190a6b9) into main (75ca50f) will decrease coverage by 0.00%.
The diff coverage is 93.90%.

❗ Current head 190a6b9 differs from pull request most recent head 1f69c96. Consider uploading reports for the commit 1f69c96 to get more accurate results

@@ Coverage Diff @@## main #1494 +/- ##
==========================================
- Coverage 90.93% 90.93% -0.01% 
==========================================
Files 77 77 Lines 42394 42359 -35 Branches 42394 42359 -35 ==========================================
- Hits 38553 38521 -32 + Misses 3841 3838 -3 
Impacted FilesCoverage Δ
lightning/src/chain/channelmonitor.rs91.12% <91.93%> (+0.05%)⬆️
lightning/src/ln/channel.rs88.57% <100.00%> (ø)
lightning/src/ln/channelmanager.rs84.66% <100.00%> (ø)
lightning/src/ln/monitor_tests.rs100.00% <100.00%> (ø)
lightning/src/ln/functional_tests.rs97.16% <0.00%> (+0.04%)⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 75ca50f...1f69c96. Read the comment docs.

In `HTLCUpdate` and `OnchainEvent` tracking, we store the HTLC
value (rounded down to whole satoshis). This is somewhat
confusingly referred to as the `onchain_value_satoshis` even though
it refers to the commitment transaction output value, not the value
available on chain (which may have been reduced by an
HTLC-Timeout/HTLC-Success transaction).
The `ChannelMonitor` had a field for the counterparty's
`cur_revocation_points`. Somewhat confusingly, this actually stored
the counterparty's *per-commitment* points, not the (derived)
revocation points.
Here we correct this by simply renaming the references as
appropriate. Note the update in `channel.rs` makes the variable
names align correctly.
@TheBlueMatt
TheBlueMattforce-pushed the 2022-05-mon-cleanups-renames branch from 1f69c96 to d443b79CompareMay 26, 2022 00:50
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Squashed without changes:

$ git diff-tree -U1 1f69c964 d443b797
$

@arik-soarik-so left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-ACKing

@TheBlueMatt
TheBlueMatt merged commit 08ab658 into lightningdevkit:mainMay 26, 2022
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants

@TheBlueMatt@codecov-commenter@tnull@arik-so@wpaulino