-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add a send_request function to NetworkService #8008
Conversation
651052c
to
b2b9af4
Compare
The |
That's quite right: For Assuming the end user of the API would be the function caller this would of course be correct, but that is not the case in Polkadot, where subsystems communicate with the network bridge via message passing. |
The polkadot subsystem can just send its oneshot::Sender and you do |
That's true, but it felt stupid to create another sender/receiver pair when there is one already. Like the API got changed the very last moment from something I wanted to something else and then I change it right back again... Felt better to just expose what I want. |
I'd strongly prefer to have the same API as
I would encourage you to use a |
Hmm, not sure I can agree. The request code path is already quite hard to follow, with quite a few layers of indirection. Not exposing the API that is already there and is needed/preferred in Polkadot, just adds another layer. Given the fact that it is implemented internally as a sender/receiver pair also suggests that it is not an esoteric use case in Polkadot to prefer such an API, but rather something that is likely to come up often (every time someone uses message passing), as we already depend on such an API both in Substrate and in Polkadot, for good reasons.
How? There is poll_canceled to do precisely that. At least if I understood your concern correctly.
That is true, but obviously already handled on the Polkadot side. I agree, that this is less explicit than a constructor in |
Expanding on the reasoning, I would see the |
If that is about hiding implementation details and getting the nicer API, that all errors are contained in |
Yes my grief is about exposing implementation details. I'd rather not tie the networking API to channels.
What's wrong with |
I am not sure we should be seeing the channels as an implementation detail. As you mentioned, we already have a channel based interface for receiving incoming requests. It makes sense to me to offer such an interface also for sending requests (at least optionally, as suggested with Do we have plans on getting rid of the channel internally? Exposing a channel based API even in that case, would not be an issue, but I agree that if that is the case we should have a solid case of exposing such an API to be a good user interface, as then we would end up just making it up for the user facing code.
For simple use cases, but not as nice for communication via message passing which is not uncommon in multithreaded environments (Polkadot and Substrate being good examples). It is of course not a terrible issue to create a channel based interface on top, but I would also rather not needlessly complicate things more.
It feels a bit clunky and needlessly dynamic, in particular I am not sure I understand why I should prefer it over a Receiver. But I guess, that boils down to whether we want channels in the public API or not.
I am also not sure about this. If Polkadot was somehow esoteric with patterns no-one other should ever use, then yes. But if it is just a user of our API, then its needs should absolutely inform our API design. Of course we should also not delve into featuritis, that would not help either :-) |
I looked at your Polkadot PR, and I now realize that you're creating the channel ahead of time in a total different part of the code. I'll do another review. |
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 think it would make sense if the only difference between request
and send_request
/other-name is that the latter sends the response on the channel.
Ok, I introduced the I did shorten the name though from
|
48599f8
to
cf9fb3d
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.
Generally looks ok to me, I just left some small suggestions for naming and API comments that you can choose to ignore if you don't consider them an improvement. However, if I understand correctly, this relies on the automatic dialing of libp2p-request-response
. Note that substrate's RequestResponsesBehaviour
still considers it an error if an inner RequestResponseBehaviour
emits a DialPeer
command. This error logging should probably be removed then to avoid confusion.
Thanks a lot @romanb! Lots of good catches! |
Why does the github-actions keep adding 'A7-needspolkadotpr`, when this is clearly not the case? Because I referenced this PR from a Polkadot PR? |
This function delivers responses via a provided sender and also allows for sending requests to currently not connected peers.
for more readable function calls.
spaces/tabs Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
Documentation fix Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
Typo. Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
Better docs. Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
Typo. Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
Doc improvements. Co-authored-by: Roman Borschel <romanb@users.noreply.github.com>
This is now valid behaviour.
As suggested by @romanb.
af4da2f
to
05cf554
Compare
044bff8
to
f67f50b
Compare
f67f50b
to
d4f6baa
Compare
This function differs from the already provided
request
method in two ways.This PR changes the signature of some apparently only internally used
send_request
functions to accept an additional boolean parameter.