-
Notifications
You must be signed in to change notification settings - Fork 406
Provide Dummy routing and channel message handlers for users #814
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
Provide Dummy routing and channel message handlers for users #814
Conversation
a2691e3
to
bfef079
Compare
bfef079
to
c70e7c1
Compare
Overhauled to just provide dummy implementations instead. |
Codecov Report
@@ Coverage Diff @@
## main #814 +/- ##
==========================================
- Coverage 91.06% 90.73% -0.34%
==========================================
Files 48 48
Lines 25495 25575 +80
==========================================
- Hits 23218 23205 -13
- Misses 2277 2370 +93
Continue to review full report at Codecov.
|
lightning/src/ln/peer_handler.rs
Outdated
/// Provides references to trait impls which handle different types of messages. | ||
pub struct MessageHandler<CM: Deref, RM: Deref> where | ||
CM::Target: ChannelMessageHandler, | ||
RM::Target: RoutingMessageHandler { | ||
/// A message handler which handles messages specific to channels. Usually this is just a | ||
/// ChannelManager object. | ||
/// ChannelManager object or a DummyChannelHandler. |
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.
This comment applies to PeerManager::new(..)
function:
could we make message_handler
an optional parameter to that function, and insert these two dummies if it's None
?
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.
You probably never actually want to create a MessageHandler with both set to dummy values...you won't ever do anything. Maybe I misunderstood your 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.
Oh oops true. Revised suggestion: could we make PeerManager::new(..)
be parameterized by a CM
and an RM
separately (and not parameterized by a MessageHandler struct), and have the RM
be optional? I feel like that would cover the majority of use cases (which does not include building a routing-only node..)
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.
I actually think both are likely, its totally reasonable to run a thing to fetch the routing graph. Added the constructors.
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.
LGTM!
925c7fb
to
751cd7e
Compare
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.
ACK changes
751cd7e
to
f3575d4
Compare
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.
Looks good after my last nits :)
10f671a
to
d5b9a08
Compare
// Any messages which are related to a specific channel generate an error message to let the | ||
// peer know we don't care about channels. | ||
fn handle_open_channel(&self, their_node_id: &PublicKey, _their_features: InitFeatures, msg: &msgs::OpenChannel) { | ||
ErroringMessageHandler::push_error(self, their_node_id, msg.temporary_channel_id); |
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.
nit: could write as self.push_error
?
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.
No :/. Because of the (somewhat anti-pattern of) impl Deref for X { type Target = X; }
which we do on the handlers, trying to access self
directly gives you a recursion limit error in rustc.
We currently "support" not having a router or channel in memory by forcing users to implement the same, but its trivial to provide our own dummy implementations.
43fde8f
to
d95f145
Compare
Squashed with no diff. |
This is largely useful for bindings, and the off-github discussion around lightningdevkit#814 concluded these should be pub, but the PR was not updated to capture this. Now that the bindings support generation for the structs, expose them.
This is largely useful for bindings, and the off-github discussion around lightningdevkit#814 concluded these should be pub, but the PR was not updated to capture this. Now that the bindings support generation for the structs, expose them.
This is largely useful for bindings, and the off-github discussion around lightningdevkit#814 concluded these should be pub, but the PR was not updated to capture this. Now that the bindings support generation for the structs, expose them.
impl Deref for IgnoringMessageHandler { | ||
type Target = IgnoringMessageHandler; | ||
fn deref(&self) -> &Self { self } | ||
} |
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.
Was wondering why Deref
was needed but forgot to ask. It's clear to me now, but I'm wondering if MessageHandler
really needs to be parameterized by types implementing Deref
s as not doing so would avoid this anti-pattern.
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.
Hmm, the Derefs are there because you almost certainly need multiple references to a ChannelManager (or NetworkGraph), eg via an Arc. We originally parametrized things by Derefs with targets to the implementations, but looking back it may have made more sense to implement the traits for Derefs to implementations. We could also implement the traits on Deref for only our specific types.
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.
I see. One thought that just came to mind -- but I haven't spent much time mulling over -- is to have a standard implementation of the trait that calls out to a ChannelManager
rather than having ChannelManager
implement the trait directly. This wouldn't be much different than the currently implementation which delegates to internal methods, but it could be freely moved.
The advantage being that users could define their own handler if the standard one didn't suffice while still leveraging ChannelManager
's interface. Or even reuse the standard implementation but tack on functionality kinda like Read
wrappers do. For example, a wrapper could log network messages before delegating to the internal standard implementation.
Then the standard implementation itself could take a Borrow<ChannelManager>
to offer flexibility similar to Deref
in what sort of pointer it accepts. Or something like this. Not pressing or anything, but having a more composable interface could be valuable.
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.
Hmm, I wonder if it makes sense to swap a bunch of our Deref use for Borrow? Indirection may work, but it'd be nice to try other things and see if they're sufficient before we jump to more indirection IMO.
This is largely useful for bindings, and the off-github discussion around lightningdevkit#814 concluded these should be pub, but the PR was not updated to capture this. Now that the bindings support generation for the structs, expose them.
This is largely useful for bindings, and the off-github discussion around lightningdevkit#814 concluded these should be pub, but the PR was not updated to capture this. Now that the bindings support generation for the structs, expose them.
We currently "support" not having a router or channel in memory by
forcing users to implement the handler trait and ignore every
message. Instead, we can just do that ourselves to simplify the API.