Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
RpcHandler
  • Loading branch information
seunlanlege committed Jul 31, 2020
commit 5f61b4f7816feb7aaf56f6e94b1e2080101b7ce7
5 changes: 3 additions & 2 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ pub fn new_full(config: Configuration)
}

pub fn new_light_base(config: Configuration) -> Result<(
TaskManager, Arc<RpcHandlers>, Arc<LightClient>,
TaskManager, RpcHandlers, Arc<LightClient>,
Arc<NetworkService<Block, <Block as BlockT>::Hash>>,
Arc<sc_transaction_pool::LightPool<Block, LightClient, sc_network::config::OnDemand<Block>>>
), ServiceError> {
Expand Down Expand Up @@ -429,7 +429,8 @@ pub fn new_light_base(config: Configuration) -> Result<(

/// Builds a new service for a light client.
pub fn new_light(config: Configuration) -> Result<TaskManager, ServiceError> {
new_light_base(config).map(|(task_manager, _, _, _, _)| {
new_light_base(config).map(|(mut task_manager, rpc_handler, _, _, _)| {
task_manager.keep_alive(rpc_handler);
task_manager
})
}
Expand Down
6 changes: 3 additions & 3 deletions client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ pub fn build_offchain_workers<TBl, TBackend, TCl>(
/// Spawn the tasks that are required to run a node.
pub fn spawn_tasks<TBl, TBackend, TExPool, TRpc, TCl>(
params: SpawnTasksParams<TBl, TCl, TExPool, TRpc, TBackend>,
) -> Result<Arc<RpcHandlers>, Error>
) -> Result<RpcHandlers, Error>
where
TCl: ProvideRuntimeApi<TBl> + HeaderMetadata<TBl, Error=sp_blockchain::Error> + Chain<TBl> +
BlockBackend<TBl> + BlockIdTo<TBl, Error=sp_blockchain::Error> + ProofProvider<TBl> +
Expand Down Expand Up @@ -540,7 +540,7 @@ pub fn spawn_tasks<TBl, TBackend, TExPool, TRpc, TCl>(
);
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(gen_handler(sc_rpc::DenyUnsafe::No));

// Telemetry
let telemetry = config.telemetry_endpoints.clone().and_then(|endpoints| {
Expand Down Expand Up @@ -579,7 +579,7 @@ pub fn spawn_tasks<TBl, TBackend, TExPool, TRpc, TCl>(
config.informant_output_format,
));

task_manager.keep_alive((telemetry, config.base_path, rpc, rpc_handlers.clone()));
task_manager.keep_alive((telemetry, config.base_path, rpc));

Ok(rpc_handlers)
}
Expand Down
9 changes: 6 additions & 3 deletions client/service/src/task_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,12 @@ impl TaskManager {
}
}

/// Set what the task manager should keep alivei
pub(super) fn keep_alive<T: 'static + Send + Sync>(&mut self, to_keep_alive: T) {
self.keep_alive = Box::new(to_keep_alive);
Copy link
Contributor

Choose a reason for hiding this comment

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

@expenses I was sure that you did make a tuple magic thingy here that would make this function callable multiple times 🤔 why was is it gone? I'm missing something...

Copy link
Member

Choose a reason for hiding this comment

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

You mean keep_alive((SOmehing, else, yolo))

Copy link
Contributor

Choose a reason for hiding this comment

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

I totally mean S0mething, else, yolo.

I think she refactored her code before pushing and since keep_alive here is privat-ish she didn't foresee it could be misused.

Clearly something to fix, it's a pitfall.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah SOmething :P You should change your font to distinguish O and 0 :P

Copy link
Contributor

Choose a reason for hiding this comment

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

The mix between the monospace font and sans font tricked my eyes

/// Set what the task manager should keep alive, can be called multiple times.
pub fn keep_alive<T: 'static + Send + Sync>(&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));
}
}

Expand Down
4 changes: 2 additions & 2 deletions utils/browser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use wasm_bindgen::prelude::*;
use futures::{
prelude::*, channel::{oneshot, mpsc}, compat::*, future::{ready, ok, select}
};
use std::{pin::Pin, sync::Arc};
use std::pin::Pin;
use sc_chain_spec::Extension;
use libp2p_wasm_ext::{ExtTransport, ffi};

Expand Down Expand Up @@ -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<RpcHandlers>) -> 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
Expand Down