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

Allow getting multiple Receiver #52

Merged
merged 1 commit into from
Sep 23, 2024

Conversation

rustaceanrob
Copy link
Collaborator

i realized that only allowing &mut Receiver<NodeMessage> may be a bit too limiting in the LN context. there is no API limitation preventing multiple Receiver<NodeMessage> out at one time, so i go ahead with that here

cc @ValuedMammal

src/lib.rs Outdated
Comment on lines 303 to 315
/// When generating a new channel [`Receiver`], a message must be consumed by _all_ [`Receiver`] before it is removed from memory.
/// For channels that process data slowly, this can cause messages to build up in the channel, and may even cause errors if too many messages
/// are held in the channel at one time. For the best results, applications may not want to call this method at all, or only a few times.
pub fn channel_receiver(&self) -> Receiver<NodeMessage> {
self.client.receiver()
Copy link
Collaborator

Choose a reason for hiding this comment

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

This all looks good to me. My one formatting nit would be to wrap the comments at 100 columns.

I tested this briefly in tests/client.rs by getting a new Receiver and saw all the node messages come through. I imagine this is useful for somebody interested in getting node messages with a "no frills" interface (I guess that was already possible when it returned &mut Receiver?). You mentioned lightning as a motivating factor, is there a specific pain point you're referring to? because it seems like a subtle change to me but I'm still de-crusting the intricacies of channels.

Copy link
Collaborator Author

@rustaceanrob rustaceanrob Sep 23, 2024

Choose a reason for hiding this comment

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

conceptually the message channel is just a block of memory in the stack that will hold messages that threads can share. for the broadcast channel, the messages will stick around on the stack (or their pointers will stick around) until all of the receivers have gotten the message.

i was thinking the LN context will use the Client by building a Node directly, but i am not so sure that is the case anymore. after looking through ldk-node i see they just use Wallet. with out current API, if a user chooses to use the builder, they won't be able to call update and get a &mut Receiver simultaneously, at least to my knowledge. in the ldk-node case, they might want to do this since they are working with Wallet, but will still need to look at blocks for revocation transactions

on style, i believe the default is 80, so i'll add a .rustfmt.toml file with that configured?

@rustaceanrob
Copy link
Collaborator Author

i had struggles with the .rustfmt.toml file so i didn't add it. sorry this should have been two separate comments but i added wrapping to the comments

Copy link
Collaborator

@ValuedMammal ValuedMammal left a comment

Choose a reason for hiding this comment

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

ACK f97514e

@ValuedMammal
Copy link
Collaborator

Appreciate you @rustaceanrob !

@ValuedMammal ValuedMammal merged commit 1e1d37a into bitcoindevkit:master Sep 23, 2024
2 checks passed
@rustaceanrob rustaceanrob deleted the client-09-21 branch September 23, 2024 16:23
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.

2 participants