Skip to content

Correct variable names in ChannelMonitor and DRY tests #1494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

TheBlueMatt
Copy link
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
Copy link
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

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

LGTM!

@TheBlueMatt
Copy link
Collaborator Author

Assigning 108 as #1495 depends on it.

arik-so
arik-so previously approved these changes May 25, 2022
Copy link
Contributor

@arik-so arik-so left a comment

Choose a reason for hiding this comment

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

approved with comment

@@ -620,7 +620,7 @@ pub(crate) struct ChannelMonitorImpl<Signer: Sign> {
funding_redeemscript: Script,
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
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
Collaborator Author

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
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
Collaborator Author

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.

@@ -2142,7 +2143,19 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
}
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
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

@TheBlueMatt TheBlueMatt dismissed stale reviews from arik-so and tnull via 1f69c96 May 25, 2022 23:09
@TheBlueMatt TheBlueMatt force-pushed the 2022-05-mon-cleanups-renames branch from 190a6b9 to 1f69c96 Compare May 25, 2022 23:09
@codecov-commenter
Copy link

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 Files Coverage Δ
lightning/src/chain/channelmonitor.rs 91.12% <91.93%> (+0.05%) ⬆️
lightning/src/ln/channel.rs 88.57% <100.00%> (ø)
lightning/src/ln/channelmanager.rs 84.66% <100.00%> (ø)
lightning/src/ln/monitor_tests.rs 100.00% <100.00%> (ø)
lightning/src/ln/functional_tests.rs 97.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 TheBlueMatt force-pushed the 2022-05-mon-cleanups-renames branch from 1f69c96 to d443b79 Compare May 26, 2022 00:50
@TheBlueMatt
Copy link
Collaborator Author

Squashed without changes:

$ git diff-tree -U1 1f69c964 d443b797
$

Copy link
Contributor

@arik-so arik-so left a comment

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:main May 26, 2022
Sign up for free to 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