Skip to content
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

move static channelmanager functions into their own file #2739

Merged

Conversation

Evanfeenstra
Copy link
Contributor

@Evanfeenstra Evanfeenstra commented Nov 16, 2023

  • new ln::onion_payment file with static functions from channelmanager.rs.
  • cleaned up test_peel_payment_onion and moved into ln::onion_payment.
  • made PendingHTLCInfo.payment_hash public (mistake from peel_payment_onion static fn in channelmanager #2700).
  • made UpdateAddHTLC.onion_routing_packet public, so that peel_payment_onion can be used externally.
  • some better comments on newly public fields.

@jkczyz
Copy link
Contributor

jkczyz commented Nov 17, 2023

I think channelmanager_utils is too broad. Let's use a more restrictive name lest it become another grab bag of utilities, even if only related to ChannelManager. Examples of other modules that we've refactored out are inbound_payment and outbound_payment. Maybe onion_payment in contrast to onion_message? Open to other ideas.

Copy link
Member

@shaavan shaavan left a comment

Choose a reason for hiding this comment

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

Concept ACK

The refactoring looks fantastic on my initial review, and the additional comments are really helpful! I'll take another pass at the added code to see if there are any further improvements we can make to this pull request. Superb work!

/// Used to track when we should expire pending HTLCs that go unclaimed.
incoming_cltv_expiry: u32,
/// Optional shared secret for phantom node.
/// Shared secret derived using a phantom node secret key. If this field is Some, the
/// payment was sent to a phantom node (one hop behond the current node), but can be
Copy link
Member

Choose a reason for hiding this comment

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

small nit:

Suggested change
/// payment was sent to a phantom node (one hop behond the current node), but can be
/// payment was sent to a phantom node (one hop behind the current node), but can be

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hehe thanks for catching that!

@Evanfeenstra
Copy link
Contributor Author

I think channelmanager_utils is too broad. Let's use a more restrictive name lest it become another grab bag of utilities, even if only related to ChannelManager. Examples of other modules that we've refactored out are inbound_payment and outbound_payment. Maybe onion_payment in contrast to onion_message? Open to other ideas.

Good point, I renamed the module to onion_payment

Copy link
Member

@shaavan shaavan left a comment

Choose a reason for hiding this comment

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

ACK mod nit.

This is a refactoring PR that moves static channelmanger functions to their own file.

I have used the following line command to notice the essential differences introduced by refactoring:

git diff HEAD^ --color-moved-ws=ignore-all-space --color-moved=dimmed-zebra

Essential Changes in the PR:

  1. Updated comments for members of PendingHTLCRouting enum. The comments look clean and clear and present a better understanding of the member variables.
  2. Modified the visibility of moved code to pub(super). Since these are utilities of channelManager and are not meant to be used in the rest of the codebase, this visibility is the most apt one for it.
  3. Removed create_payment_onion function. Instead, use the create_payment_onion function defined in ln::onion_utils::create_payment_onion;

The refactoring looks clean and clear, and other than the small nits, this PR is good to be merged.

@@ -118,14 +119,19 @@ pub enum PendingHTLCRouting {
short_channel_id: u64, // This should be NonZero<u64> eventually when we bump MSRV
},
/// An HTLC paid to an invoice we generated.
Copy link
Member

Choose a reason for hiding this comment

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

Small nit:

In the following line, we are saying we don't know yet if the invoice was generated by us. So adding a "supposedly" will make the comments more coherent here.

Suggested change
/// An HTLC paid to an invoice we generated.
/// An HTLC paid to an invoice (supposedly) generated by us.

/// acceptance. If the payment is to be received, and the amount matches the expected amount for
/// a given invoice, this indicates the [`msgs::UpdateAddHTLC`], once fully committed in the
/// channel, will generate an [`Event::PaymentClaimable`].
///
Copy link
Member

Choose a reason for hiding this comment

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

nit by linter:

Suggested change
///
///

@@ -0,0 +1,499 @@
//! Utilities for channelmanager.rs
//!
Copy link
Member

Choose a reason for hiding this comment

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

nit by linter:

Suggested change
//!
//!

@codecov-commenter
Copy link

codecov-commenter commented Nov 25, 2023

Codecov Report

Attention: 36 lines in your changes are missing coverage. Please review.

Comparison is base (70ea110) 88.55% compared to head (8c588cf) 88.51%.
Report is 29 commits behind head on main.

❗ Current head 8c588cf differs from pull request most recent head 9f4dcd0. Consider uploading reports for the commit 9f4dcd0 to get more accurate results

Files Patch % Lines
lightning/src/ln/onion_payment.rs 90.10% 29 Missing and 7 partials ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2739      +/-   ##
==========================================
- Coverage   88.55%   88.51%   -0.04%     
==========================================
  Files         113      114       +1     
  Lines       89323    89305      -18     
  Branches    89323    89305      -18     
==========================================
- Hits        79097    79052      -45     
- Misses       7860     7882      +22     
- Partials     2366     2371       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Evanfeenstra
Copy link
Contributor Author

ok, rebased to main and incorporated the nits by @shaavan

Copy link
Member

@shaavan shaavan left a comment

Choose a reason for hiding this comment

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

Code review ACK

Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

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

Fine to save these for follow-up if we want to get the initial code move in.

lightning/src/ln/onion_payment.rs Outdated Show resolved Hide resolved
lightning/src/ln/onion_payment.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
lightning/src/ln/onion_payment.rs Outdated Show resolved Hide resolved
lightning/src/ln/channelmanager.rs Outdated Show resolved Hide resolved
@Evanfeenstra
Copy link
Contributor Author

Fine to save these for follow-up if we want to get the initial code move in.

Ok I went ahead and incorporated these nits. Thanks!

@valentinewallace
Copy link
Contributor

Will wait til @TheBlueMatt ACK's the docs to merge.

@valentinewallace
Copy link
Contributor

Going to land this since it's largely a code move and we can continue iterating on the docs if necessary in #2752.

@valentinewallace valentinewallace merged commit f07f4b9 into lightningdevkit:main Nov 29, 2023
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants