Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Add a JSON-RPC request for reserved nodes #8704

Merged
6 commits merged into from
May 3, 2021
Merged

Conversation

kpp
Copy link
Contributor

@kpp kpp commented Apr 30, 2021

Fixes #8147

Adds a reservedPeers rpc call to return peers added/removed through addReservedPeer and removeReservedPeer.

Is there something left for follow-up PRs?

Yes. The work is in progress

@kpp kpp added A0-please_review Pull request needs code review. B3-apinoteworthy C1-low PR touches the given topic and has a low impact on builders. labels Apr 30, 2021
@kpp kpp requested a review from tomaka April 30, 2021 13:42
@github-actions github-actions bot added A3-in_progress Pull request is in progress. No review needed at this stage. and removed A0-please_review Pull request needs code review. labels Apr 30, 2021
@kpp kpp changed the title WIP: Add a JSON-RPC layer for reserved nodes Add a JSON-RPC layer for reserved nodes May 3, 2021
@kpp kpp marked this pull request as ready for review May 3, 2021 09:41
@github-actions github-actions bot added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels May 3, 2021
@tomaka
Copy link
Contributor

tomaka commented May 3, 2021

There's a problem in the design:

When you process the JSON-RPC request in the service, you call reserved_peers, which sends a message to the peerset, then you do rx.await.
However in order for rx.await to actually receive something, the peerset has to process the message. And this processing is done in the networking code as well. And this networking code doesn't run because you're blocking with await.
In other words, this will deadlock.

There are two ways I can see to fix that:

  • Don't do await immediately, but spawn a background task or create some sort of FuturesUnordered that allows the future to run "in parallel".
  • Change the call to reserved_peers to be synchronous and immediately return the list.

The second is IMO a way better solution on principle, but it potentially introduces a race condition in the peerset: if there are some pending AddReservedPeer or RemoveReservedPeer messages in the peerset's channel, they will not be taken into account. I think that this is fine, but we should document it and open an issue.

@kpp
Copy link
Contributor Author

kpp commented May 3, 2021

Change the call to reserved_peers to be synchronous and immediately return the list.

I don't think I can do that, because I can request Peerset asynchronously via PeersetHandle. So there should be some way to sit and block on Receiver.

Don't do await immediately, but spawn a background task

I thought about it, however there is no executors in the dependency list of the crate.

So I would prefer one of the given solutions:

  1. Add another background task-stream, poll in in futures::select!{, .map and send message back to sender,
  2. Return Vec<String> from Peerset instead of Vec<PeerId> - this will allow us to pass sender without .awaiting.

@tomaka
Copy link
Contributor

tomaka commented May 3, 2021

don't think I can do that, because I can request Peerset asynchronously via PeersetHandle. So there should be some way to sit and block on Receiver.

You definitely can. The method you added is on the NetworkWorker, which indirectly holds the Peerset (see here, example). Just use &mut self instead of &self and access everything mutably.

Copy link
Contributor

@tomaka tomaka left a comment

Choose a reason for hiding this comment

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

👍

client/service/src/lib.rs Outdated Show resolved Hide resolved
Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
@tomaka
Copy link
Contributor

tomaka commented May 3, 2021

bot merge

@ghost
Copy link

ghost commented May 3, 2021

Waiting for commit status.

@ghost
Copy link

ghost commented May 3, 2021

Bot will approve on the behalf of @tomaka, since they are a team lead, in an attempt to reach the minimum approval count

@ghost ghost merged commit d2f66e0 into master May 3, 2021
@ghost ghost deleted the rpc_reserved_nodes_8147 branch May 3, 2021 12:17
@tomaka tomaka changed the title Add a JSON-RPC layer for reserved nodes Add a JSON-RPC request for reserved nodes May 12, 2021
nazar-pc pushed a commit to autonomys/substrate that referenced this pull request Aug 8, 2021
* Add boilerplate for JSON-RPC layer for reserved nodes

* Add more boilerplate for JSON-RPC layer for reserved nodes

* Make JSON-RPC layer for reserved nodes async

* Use more realistic data in reserver_peers tests

* Make JSON-RPC layer for reserved nodes blocking

* Apply tomaka's suggestion to reduce .into_iter() for an iter

Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>

Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add way to query back reserved nodes through JSON-RPC layer
2 participants