-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Plumb RPC listener up to caller #5038
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
Changes from 4 commits
6afa9b4
2a41755
63409c5
52619cb
edb42bb
1a13c3c
370990a
c360b6d
77cbb97
37472e1
1f81d96
c518301
e71565b
70c6ff1
7491090
ff4bf3d
50197cb
a8efb66
5e690bf
f19f5de
37ee0ab
20fc75a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ | |
| use crate::{ | ||
| build_network_future, build_system_rpc_future, | ||
| client::{Client, ClientConfig}, | ||
| config::{Configuration, KeystoreConfig, PrometheusConfig}, | ||
| config::{Configuration, KeystoreConfig, Multiaddr, PrometheusConfig}, | ||
| error::Error, | ||
| metrics::MetricsService, | ||
| start_rpc_servers, BuildGenesisBlock, GenesisBlockBuilder, RpcHandlers, SpawnTaskHandle, | ||
|
|
@@ -43,6 +43,7 @@ use sc_executor::{ | |
| use sc_keystore::LocalKeystore; | ||
| use sc_network::{ | ||
| config::{FullNetworkConfiguration, SyncMode}, | ||
| multiaddr::Protocol, | ||
| service::{ | ||
| traits::{PeerStore, RequestResponseConfig}, | ||
| NotificationMetrics, | ||
|
|
@@ -507,8 +508,21 @@ where | |
| ) | ||
| }; | ||
|
|
||
| let rpc = start_rpc_servers(&config, gen_rpc_module, rpc_id_provider)?; | ||
| let rpc_handlers = RpcHandlers(Arc::new(gen_rpc_module(sc_rpc::DenyUnsafe::No)?.into())); | ||
| let (rpc, listen_addr) = start_rpc_servers(&config, gen_rpc_module, rpc_id_provider)?; | ||
|
|
||
| let listen_addrs = match listen_addr { | ||
| Some(socket_addr) => { | ||
| let mut multiaddr: Multiaddr = socket_addr.ip().into(); | ||
| multiaddr.push(Protocol::Tcp(socket_addr.port())); | ||
| vec![multiaddr] | ||
| }, | ||
| None => vec![], | ||
| }; | ||
|
|
||
| let rpc_handlers = RpcHandlers { | ||
|
||
| rpc_module: Arc::new(gen_rpc_module(sc_rpc::DenyUnsafe::No)?.into()), | ||
| listen_addresses: Box::new(listen_addrs), | ||
| }; | ||
|
|
||
| // Spawn informant task | ||
| spawn_handle.spawn( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ mod client; | |
| mod metrics; | ||
| mod task_manager; | ||
|
|
||
| use crate::config::Multiaddr; | ||
| use std::{collections::HashMap, net::SocketAddr}; | ||
|
|
||
| use codec::{Decode, Encode}; | ||
|
|
@@ -47,6 +48,7 @@ use sc_network::{ | |
| }; | ||
| use sc_network_sync::SyncingService; | ||
| use sc_network_types::PeerId; | ||
| use sc_rpc_server::ServerAndListenAddress; | ||
| use sc_utils::mpsc::TracingUnboundedReceiver; | ||
| use sp_blockchain::HeaderMetadata; | ||
| use sp_consensus::SyncOracle; | ||
|
|
@@ -98,7 +100,10 @@ const DEFAULT_PROTOCOL_ID: &str = "sup"; | |
|
|
||
| /// RPC handlers that can perform RPC queries. | ||
| #[derive(Clone)] | ||
| pub struct RpcHandlers(Arc<RpcModule<()>>); | ||
| pub struct RpcHandlers { | ||
| rpc_module: Arc<RpcModule<()>>, | ||
| listen_addresses: Box<Vec<Multiaddr>>, | ||
niklasad1 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| impl RpcHandlers { | ||
| /// Starts an RPC query. | ||
|
|
@@ -120,12 +125,17 @@ impl RpcHandlers { | |
| // This limit is used to prevent panics and is large enough. | ||
| const TOKIO_MPSC_MAX_SIZE: usize = tokio::sync::Semaphore::MAX_PERMITS; | ||
|
|
||
| self.0.raw_json_request(json_query, TOKIO_MPSC_MAX_SIZE).await | ||
| self.rpc_module.raw_json_request(json_query, TOKIO_MPSC_MAX_SIZE).await | ||
| } | ||
|
|
||
| /// Provides access to the underlying `RpcModule` | ||
| pub fn handle(&self) -> Arc<RpcModule<()>> { | ||
| self.0.clone() | ||
| self.rpc_module.clone() | ||
| } | ||
|
|
||
| /// Provides access to listen addresses | ||
| pub fn listen_addresses(&self) -> &[Multiaddr] { | ||
| &self.listen_addresses[..] | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -372,7 +382,7 @@ pub fn start_rpc_servers<R>( | |
| config: &Configuration, | ||
| gen_rpc_module: R, | ||
| rpc_id_provider: Option<Box<dyn RpcSubscriptionIdProvider>>, | ||
| ) -> Result<Box<dyn std::any::Any + Send + Sync>, error::Error> | ||
| ) -> Result<(Box<dyn std::any::Any + Send + Sync>, Option<SocketAddr>), error::Error> | ||
|
||
| where | ||
| R: Fn(sc_rpc::DenyUnsafe) -> Result<RpcModule<()>, Error>, | ||
| { | ||
|
|
@@ -419,7 +429,9 @@ where | |
| match tokio::task::block_in_place(|| { | ||
| config.tokio_handle.block_on(sc_rpc_server::start_server(server_config)) | ||
| }) { | ||
| Ok(server) => Ok(Box::new(waiting::Server(Some(server)))), | ||
| Ok(ServerAndListenAddress { handle, listen_addr }) => { | ||
| Ok((Box::new(waiting::Server(Some(handle))), listen_addr)) | ||
| }, | ||
| Err(e) => Err(Error::Application(e)), | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.