-
Notifications
You must be signed in to change notification settings - Fork 431
Drop Deref indirection for most trait parameters
#4311
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
base: main
Are you sure you want to change the base?
Drop Deref indirection for most trait parameters
#4311
Conversation
|
👋 I see @wpaulino was un-assigned. |
|
If this looks good and works for language bindings, I/claude can do it for all the other traits. I feel like this is a solid improvement. |
|
@TheBlueMatt would appreciate conceptual review to make sure this works for the language bindings. |
|
Actually, it looks like this might not work for 1.75 ( |
It means updating the generation logic to support it, but it certainly isn't directly problematic.
You can write it as |
|
Conceptually tho yea imo we should do this. Its "the right way" to do it in rust. |
1c6cf54 to
584fec7
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4311 +/- ##
==========================================
- Coverage 86.58% 86.53% -0.06%
==========================================
Files 158 158
Lines 102367 102571 +204
Branches 102367 102571 +204
==========================================
+ Hits 88636 88757 +121
- Misses 11316 11398 +82
- Partials 2415 2416 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
tnull
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that you'll need to bump lightning-liquidity's version to 0.3.0+git to get the SemVer checks to pass, as it's an API-breaking change.
Useful for upcoming commits where we otherwise break SemVer checks by changing the ALiquidityManager associated types.
584fec7 to
ad7aaa5
Compare
|
Is the |
Yes, I will un-draft the PR once all the traits are complete :) |
|
🔔 1st Reminder Hey @TheBlueMatt! This PR has been waiting for your review. |
ad7aaa5 to
028f1fb
Compare
| fn message_received(&self); | ||
| } | ||
|
|
||
| impl<T: ChannelMessageHandler + ?Sized, C: Deref<Target = T>> ChannelMessageHandler for C { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really better than using Arc instead of Deref, and accepting that for no-std the API might look slightly different?
There aren't that many no-std projects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah maybe we should resolve this here #4309 (comment) before moving forward with this direction? Is it still difficult to add new trait params now that we have Claude?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ask Claude to add a logger to ChannelMonitor, and then report back 😂
Reduces generics and verbosity across the codebase, should provide equivalent behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
028f1fb to
3630b91
Compare
Deref indirection for ChannelManager, etcDeref indirection for most trait parameters
3630b91 to
2ceb510
Compare
|
@tnull do you have any idea if the LDK Node API CI failure is easy to fix on the LDK Node end? Otherwise I can drop the |
Reduces generics and verbosity across the codebase, should provide equivalent behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Reduces generics and verbosity across the codebase, should provide equivalent behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Reduces generics and verbosity across the codebase, should provide equivalent behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Reduces generics and verbosity across the codebase, should provide equivalent behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Reduces generics and verbosity across the codebase, should provide equivalent behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Reduces generics and verbosity across the codebase, should provide equivalent behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Reduces generics and verbosity across the codebase, should provide equivalent behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Reduces generics and verbosity across the codebase, should provide equivalent behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Reduces generics and verbosity across the codebase, should provide equivalent behavior. Unfortunately the same improvement can't be made for KVStoreSync and Persist, due to the blanket implementation where all KVStoreSync traits implement Persist resulting in conflicting implementations. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Reduces generics and verbosity across the codebase, should provide equivalent behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Reduces generics and verbosity across the codebase, should provide equivalent behavior. This could be split into multiple commits (e.g. one for OnionMessenger message handler types, one for PeerManager message handler types) but it would require adding a new IgnoringOnionMessageHandler type for the messenger handlers, due to the IgnoringMessageHandler's Deref implementation conflicting otherwise. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Reduces generics and verbosity across the codebase, should provide equivalent behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Reduces generics and verbosity across the codebase, should provide equivalent behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Reduces generics and verbosity across the codebase, should provide equivalent behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Reduces generics and verbosity across the codebase, should provide equivalent behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2ceb510 to
db87b32
Compare
It is now the responsibility of |
I'm aware, but I'm not sure if it's something that should be fixed or whether the new |
|
Fair enough. It does look like its just a conflict cause there's a deref-bounded auto-impl, which shouldn't be crazy to fix. Would have to go actually try to be sure though. |
|
@valentinewallace we just merged this PR #4305 which has a |
| fn sign_message(&self, msg: &[u8]) -> Result<String, ()>; | ||
| } | ||
|
|
||
| impl<T: NodeSigner + ?Sized, N: Deref<Target = T>> NodeSigner for N { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, this means our types can now take their type parameterizations by value, too, instead of only by reference. Is there any concern with users misusing this?
They can already do this, of course, by instantiating two objects of the same type to parameterize two different types by references to them. But it's at least more obviously wrong (for types where this matters), but isn't as obvious now that users would be able to easily parameterize each type by instantiating the type parameter inline instead of passing an Arc or a reference.
In other words, some of our types are expected to share references. Maybe this is more of a documentation concern?
| impl< | ||
| ES: EntropySource + Clone, | ||
| NS: Deref + Clone, | ||
| NS: NodeSigner + Clone, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, could be a footgun if a user implements both NodeSigner and Clone for a type and then passes it by value to one of our structs instead of just implementing NodeSigner and passing a clonable reference to it.
Reduces generics and verbosity across the codebase, should provide equivalent behavior.
Inspired by #4309 (comment). Basically, instead of
Derefindirection we insteadimpl<T: Trait, D: Deref<Target = Trait>> Trait for Dfor all our traits.The majority of the codebase's traits are done in this PR, but we do skip a good amount still. In a lot of cases traits are skipped because of compiler complaints about (potential-) conflicting trait implementations, but also ran into some lifetime issues and some
c_bindingsissues.