Skip to content

Parameterize the OnionMessageContents in message handler traits #3261

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

Conversation

TheBlueMatt
Copy link
Collaborator

Our onion message handlers generally have one or more methods which return either a ResponseInstruction or a PendingOnionMessage parameterized with the expected message type (enum) of the message handler. This is generally fine, there's not much reason for a message handler of one type to return a response of a different type, but there's also not much reason to restrict it from doing so, either.

Sadly, that restriction is also impossible to represent in our bindings - our bindings concretize all structs, enums, and traits into a single concrete instance with generics set to our concrete trait instances (which hold a jump table). This prevents us from having multiple instances of ResponseInstruction or PendingOnionMessage structs for different message types.

Instead, we simply add an associated type to our onion message handlers, allowing them to return any type they want (or for the bindings to make them dynamic on the internal jump table but static at compile-time).

Our onion message handlers generally have one or more methods which
return either a `ResponseInstruction` or a `PendingOnionMessage`
parameterized with the expected message type (enum) of the message
handler. This is generally fine, there's not much reason for a
message handler of one type to return a response of a different
type, but there's also not much reason to restrict it from doing
so, either.

Sadly, that restriction is also impossible to represent in our
bindings - our bindings concretize all structs, enums, and traits
into a single concrete instance with generics set to our concrete
trait instances (which hold a jump table). This prevents us from
having multiple instances of `ResponseInstruction` or
`PendingOnionMessage` structs for different message types.

Instead, we simply add an associated type to our onion message
handlers, allowing them to return any type they want (or for the
bindings to make them dynamic on the internal jump table but static
at compile-time).
@TheBlueMatt TheBlueMatt added this to the 0.0.124 milestone Aug 21, 2024
@TheBlueMatt
Copy link
Collaborator Author

Hmm, actually this isn't sufficient for bindings on its own, we'll still fail because we have trait implementations in-crate that return types other than a generic one...instead I think we'll need to #[cfg(c_bindings)] it and make methods return a (Message, ResponseInstruction) pair.

Copy link

codecov bot commented Aug 21, 2024

Codecov Report

Attention: Patch coverage is 20.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 89.81%. Comparing base (bbfa15e) to head (d841ef4).

Files Patch % Lines
lightning/src/ln/channelmanager.rs 0.00% 1 Missing ⚠️
lightning/src/ln/peer_handler.rs 0.00% 1 Missing ⚠️
lightning/src/onion_message/async_payments.rs 0.00% 1 Missing ⚠️
lightning/src/onion_message/functional_tests.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3261   +/-   ##
=======================================
  Coverage   89.80%   89.81%           
=======================================
  Files         125      125           
  Lines      102867   102867           
  Branches   102867   102867           
=======================================
+ Hits        92381    92387    +6     
- Misses       7765     7766    +1     
+ Partials     2721     2714    -7     

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

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.

1 participant