diff --git a/Cargo.lock b/Cargo.lock index 197751bedb15d..ec5af8aca4ecf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6973,6 +6973,7 @@ dependencies = [ "futures 0.3.5", "futures-timer 3.0.2", "hash-db", + "jsonrpc-core", "jsonrpc-pubsub", "lazy_static", "log", diff --git a/bin/node/cli/src/service.rs b/bin/node/cli/src/service.rs index cd98c26809644..f9ff096ad4b54 100644 --- a/bin/node/cli/src/service.rs +++ b/bin/node/cli/src/service.rs @@ -341,7 +341,7 @@ pub fn new_full(config: Configuration) } pub fn new_light_base(config: Configuration) -> Result<( - TaskManager, Arc, Arc, + TaskManager, RpcHandlers, Arc, Arc::Hash>>, Arc>> ), ServiceError> { diff --git a/client/service/Cargo.toml b/client/service/Cargo.toml index 3ad91dc3ea39b..6462549403b6f 100644 --- a/client/service/Cargo.toml +++ b/client/service/Cargo.toml @@ -26,7 +26,8 @@ test-helpers = [] derive_more = "0.99.2" futures01 = { package = "futures", version = "0.1.29" } futures = { version = "0.3.4", features = ["compat"] } -jsonrpc-pubsub = "14.2.0" +jsonrpc-pubsub = "14.2" +jsonrpc-core = "14.2" rand = "0.7.3" parking_lot = "0.10.0" lazy_static = "1.4.0" diff --git a/client/service/src/builder.rs b/client/service/src/builder.rs index eedc4582299d3..8ad95511f77d3 100644 --- a/client/service/src/builder.rs +++ b/client/service/src/builder.rs @@ -442,7 +442,7 @@ pub fn build_offchain_workers( /// Spawn the tasks that are required to run a node. pub fn spawn_tasks( params: SpawnTasksParams, -) -> Result, Error> +) -> Result where TCl: ProvideRuntimeApi + HeaderMetadata + Chain + BlockBackend + BlockIdTo + ProofProvider + @@ -540,7 +540,7 @@ pub fn spawn_tasks( ); let rpc = start_rpc_servers(&config, gen_handler)?; // This is used internally, so don't restrict access to unsafe RPC - let rpc_handlers = Arc::new(RpcHandlers(gen_handler(sc_rpc::DenyUnsafe::No))); + let rpc_handlers = RpcHandlers(Arc::new(gen_handler(sc_rpc::DenyUnsafe::No).into())); // Telemetry let telemetry = config.telemetry_endpoints.clone().and_then(|endpoints| { diff --git a/client/service/src/lib.rs b/client/service/src/lib.rs index e8d2ab8285c3c..d19b9f5ea247d 100644 --- a/client/service/src/lib.rs +++ b/client/service/src/lib.rs @@ -96,7 +96,8 @@ impl MallocSizeOfWasm for T {} impl MallocSizeOfWasm for T {} /// RPC handlers that can perform RPC queries. -pub struct RpcHandlers(sc_rpc_server::RpcHandler); +#[derive(Clone)] +pub struct RpcHandlers(Arc>); impl RpcHandlers { /// Starts an RPC query. @@ -115,6 +116,11 @@ impl RpcHandlers { .map(|res| res.expect("this should never fail")) .boxed() } + + /// Provides access to the underlying `MetaIoHandler` + pub fn io_handler(&self) -> Arc> { + self.0.clone() + } } /// Sinks to propagate network status updates. diff --git a/client/service/src/task_manager/mod.rs b/client/service/src/task_manager/mod.rs index 6925d27f4e5ca..88a44e1360d7f 100644 --- a/client/service/src/task_manager/mod.rs +++ b/client/service/src/task_manager/mod.rs @@ -336,9 +336,12 @@ impl TaskManager { } } - /// Set what the task manager should keep alive. - pub(super) fn keep_alive(&mut self, to_keep_alive: T) { - self.keep_alive = Box::new(to_keep_alive); + /// Set what the task manager should keep alive, can be called multiple times. + pub fn keep_alive(&mut self, to_keep_alive: T) { + // allows this fn to safely called multiple times. + use std::mem; + let old = mem::replace(&mut self.keep_alive, Box::new(())); + self.keep_alive = Box::new((to_keep_alive, old)); } /// Register another TaskManager to terminate and gracefully shutdown when the parent diff --git a/utils/browser/src/lib.rs b/utils/browser/src/lib.rs index 718a9b9751154..ffd0a134be19e 100644 --- a/utils/browser/src/lib.rs +++ b/utils/browser/src/lib.rs @@ -27,7 +27,7 @@ use wasm_bindgen::prelude::*; use futures::{ prelude::*, channel::{oneshot, mpsc}, compat::*, future::{ready, ok, select} }; -use std::{sync::Arc, pin::Pin}; +use std::pin::Pin; use sc_chain_spec::Extension; use libp2p_wasm_ext::{ExtTransport, ffi}; @@ -124,7 +124,7 @@ struct RpcMessage { } /// Create a Client object that connects to a service. -pub fn start_client(mut task_manager: TaskManager, rpc_handlers: Arc) -> Client { +pub fn start_client(mut task_manager: TaskManager, rpc_handlers: RpcHandlers) -> Client { // We dispatch a background task responsible for processing the service. // // The main action performed by the code below consists in polling the service with