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

Introduce OffersMessageFlow #3412

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

shaavan
Copy link
Contributor

@shaavan shaavan commented Nov 18, 2024

This PR introduces a new data structure to separate the functions and fields related to Offers Message from ChannelManager.

The change ensures a clear separation of responsibilities for BOLT12 messages, improving modularity and maintainability.

TODO:

  • Refine commit messages
  • Add detailed documentation

@shaavan
Copy link
Contributor Author

shaavan commented Nov 19, 2024

Updated from pr3412.01 to pr3412.02 (diff):

Changes:

  1. Fix ci
  2. Update commit messages

@jkczyz jkczyz self-requested a review November 19, 2024 15:36
Copy link
Contributor

@jkczyz jkczyz left a comment

Choose a reason for hiding this comment

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

FYI, I reviewed this offline with @shaavan. So there will be some changes to the OffersMessageFlow trait parameterization to keep ChannelManager specifics from leaking.

return Err(Bolt12SemanticError::UnsupportedChain);
}

let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
Copy link
Contributor

Choose a reason for hiding this comment

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

@TheBlueMatt Do you know why we need the PersistenceNotifierGuard here? This code sends an invoice for a refund (i.e., an inbound payment). IIUC, we don't persist pending_offers_messages, so it seems we don't need it.

@shaavan
Copy link
Contributor Author

shaavan commented Nov 29, 2024

Updated from pr3412.02 to pr3412.03 (diff):

Addressed @jkczyz comments:

Changes:

  1. Update & Expand Documentation.
  2. Move dnssec code in flow.rs
  3. Simplified OffersMessageFlow trait parametrisation.
  4. Move OffersMessageFlow only function from offersmessagecommons to flow.rs

@shaavan
Copy link
Contributor Author

shaavan commented Nov 30, 2024

Updated from pr3412.03 to pr3412.04 (diff):

Changes:

  1. Rebase on main.
  2. Fix CI.

@shaavan
Copy link
Contributor Author

shaavan commented Dec 6, 2024

Updated from pr3412.04 to pr3412.05 (diff):

Addressed @jkczyz's (offline) comments.

Changes:

  1. Moved the OffersMessageCommons trait definition to flow.rs, as it is a more logical location for its definition.
  2. Temporarily removed async Bolt12 message support, with the reasoning documented in the corresponding commit message.
  3. Introduced network_pubkey and extended_key fields in OffersMessageFlow to streamline the overall refactoring by reducing code movement.

@shaavan shaavan force-pushed the offersmessageflow branch 2 times, most recently from 4911f9f to 9d0c511 Compare December 6, 2024 16:00
@shaavan
Copy link
Contributor Author

shaavan commented Dec 6, 2024

Updated from pr3412.05 to pr3412.06 (diff):

Changes:

  1. Rebase on main to resolve merge conflicts
  2. Fix CI

Copy link

codecov bot commented Dec 6, 2024

Codecov Report

Attention: Patch coverage is 88.71795% with 88 lines in your changes missing coverage. Please review.

Project coverage is 89.78%. Comparing base (641e40f) to head (189b2aa).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/offers/flow.rs 86.03% 66 Missing and 15 partials ⚠️
lightning/src/ln/channelmanager.rs 96.66% 3 Missing ⚠️
lightning/src/ln/offers_tests.rs 96.66% 3 Missing ⚠️
lightning/src/onion_message/offers.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3412      +/-   ##
==========================================
+ Coverage   89.72%   89.78%   +0.05%     
==========================================
  Files         130      131       +1     
  Lines      107614   108190     +576     
  Branches   107614   108190     +576     
==========================================
+ Hits        96559    97137     +578     
+ Misses       8660     8659       -1     
+ Partials     2395     2394       -1     

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

lightning/src/offers/flow.rs Outdated Show resolved Hide resolved
@shaavan
Copy link
Contributor Author

shaavan commented Dec 11, 2024

Updated from pr3412.06 to pr3412.07 (diff):
Addressed @TheBlueMatt comment

Changes:

  1. Corrected code for cfg[(async_payments)]
  2. Remove stale todo. reference
  3. Fix CI

To decouple offers and onion message-related code from `ChannelManager`,
this commit introduces the `message_received` function in `Offer/OnionMessageHandler`.

Currently, the function focuses on handling the retry logic for `InvoiceRequest`
messages. Moving this responsibility ensures a cleaner separation of concerns
and sets the foundation for managing offers/onion messages directly within the
appropriate handler.
Since `ChannelMessageHandler`'s `message_received` function was solely
used for handling invoice request retries. This function has been
removed from `ChannelMessageHandler`, and the relevant code has been
migrated to `OffersMessageHandler`'s `message_received`.

This ensures invoice request retries are now handled in the appropriate context.
This commit temporarily removes support for async BOLT12
message handling to enable a smoother transition in the
upcoming refactor.

The current implementation of async handling is abrupt,
as it requires delving into the synchronous case and
generating an event mid-flow based on the `manual_handling`
flag. This approach adds unnecessary complexity and coupling.

A later commit will introduce a new struct, `OffersMessageFlow`,
designed to handle and create offer messages. This new struct
will support async handling in a more structured way by allowing
users to implement a parameterized trait for asynchronous message
handling.

Removing the existing async support now ensures a cleaner and more
seamless migration of offer-related code from `ChannelManager` to
`OffersMessageFlow`.
This commit introduces a new struct, `OffersMessageFlow`,
to extract all offers message-related code out of `ChannelManager`.

By moving this logic into a dedicated struct, it creates
a foundation for separating responsibilities and sets up
a base for further code restructuring in subsequent commits.
A new trait, `OffersMessageCommons`, is introduced to encapsulate
functions that are commonly used by both BOLT12-related functionality
and other parts of `ChannelManager`.

This enables a clean transition of BOLT12 code to `OffersMessageFlow`
by moving shared functions into the new trait, ensuring they remain
accessible to both `ChannelManager` and the refactored BOLT12 code.
This commit introduces the `OffersMessageHandler` implementation
for `OffersMessageFlow`, enabling direct access to offer-specific
functionality through `OffersMessageFlow`.

With `OffersMessageFlow` now serving as the source of `OffersMessageHandler`
implementation, the implementation in `ChannelManager` is no longer needed
and has been safely removed.
- This commit introduces a new struct, `AnOffersMessageFlow`,
  which generically implements `OffersMessageFlow`.
- In subsequent commits, this struct will be utilized for
  documentation purposes.
- The _persistence_guard here was not serving any purpose, and hence can
  be removed in this refactoring.
@shaavan
Copy link
Contributor Author

shaavan commented Dec 12, 2024

Updated from pr3412.07 to pr3412.08 (diff):

Changes:

  1. Rebase on main, to resolve merge conflicts.

@shaavan
Copy link
Contributor Author

shaavan commented Dec 12, 2024

Updated from pr3412.08 to pr3412.09 (diff):

Changes:

  1. Introduce create_blinded_paths in flow.rs
  2. This allows removing additional function from OffersMessageCommons trait, and hence simplifying it.

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.

3 participants