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

Commit

Permalink
Remove RpcHandlers and associated machinery (#9266)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdplm authored Jul 3, 2021
1 parent 9ffba18 commit 1b61b1a
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 278 deletions.
6 changes: 3 additions & 3 deletions bin/node/cli/src/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ async fn start_inner(
info!("👤 Role: {:?}", config.role);

// Create the service. This is the most heavy initialization step.
let (task_manager, rpc_handlers) =
let task_manager =
crate::service::new_light_base(config)
.map(|(components, rpc_handlers, _, _, _)| (components, rpc_handlers))
.map(|(task_manager, _, _, _)| task_manager)
.map_err(|e| format!("{:?}", e))?;

Ok(browser_utils::start_client(task_manager, rpc_handlers))
Ok(browser_utils::start_client(task_manager))
}
2 changes: 1 addition & 1 deletion bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ pub(crate) mod tests {
Ok(sc_service_test::TestNetComponents::new(task_manager, client, network, transaction_pool))
},
|config| {
let (keep_alive, _, client, network, transaction_pool) = new_light_base(config)?;
let (keep_alive, client, network, transaction_pool) = new_light_base(config)?;
Ok(sc_service_test::TestNetComponents::new(keep_alive, client, network, transaction_pool))
}
);
Expand Down
39 changes: 17 additions & 22 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ use std::sync::Arc;
use sc_consensus_babe;
use node_primitives::Block;
use node_runtime::RuntimeApi;
use sc_service::{
config::Configuration, error::Error as ServiceError, RpcHandlers, TaskManager,
};
use sc_service::{config::Configuration, error::Error as ServiceError, TaskManager};
use sc_network::{Event, NetworkService};
use sp_runtime::traits::Block as BlockT;
use futures::prelude::*;
Expand Down Expand Up @@ -456,7 +454,6 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {

pub fn new_light_base(mut config: Configuration) -> Result<(
TaskManager,
RpcHandlers,
Arc<LightClient>,
Arc<NetworkService<Block, <Block as BlockT>::Hash>>,
Arc<sc_transaction_pool::LightPool<Block, LightClient, sc_network::config::OnDemand<Block>>>
Expand Down Expand Up @@ -583,25 +580,23 @@ pub fn new_light_base(mut config: Configuration) -> Result<(
}

// TODO: (dp) implement rpsee builder here for all RPC modules available to the light client.
let rpc_handlers =
sc_service::spawn_tasks(sc_service::SpawnTasksParams {
on_demand: Some(on_demand),
remote_blockchain: Some(backend.remote_blockchain()),
// TODO(niklasad1): implement.
rpc_builder: Box::new(|_, _| RpcModule::new(())),
client: client.clone(),
transaction_pool: transaction_pool.clone(),
keystore: keystore_container.sync_keystore(),
config, backend, system_rpc_tx,
network: network.clone(),
task_manager: &mut task_manager,
telemetry: telemetry.as_mut(),
})?;
sc_service::spawn_tasks(sc_service::SpawnTasksParams {
on_demand: Some(on_demand),
remote_blockchain: Some(backend.remote_blockchain()),
// TODO(niklasad1): implement.
rpc_builder: Box::new(|_, _| RpcModule::new(())),
client: client.clone(),
transaction_pool: transaction_pool.clone(),
keystore: keystore_container.sync_keystore(),
config, backend, system_rpc_tx,
network: network.clone(),
task_manager: &mut task_manager,
telemetry: telemetry.as_mut(),
})?;

network_starter.start_network();
Ok((
task_manager,
rpc_handlers,
client,
network,
transaction_pool,
Expand All @@ -612,7 +607,7 @@ pub fn new_light_base(mut config: Configuration) -> Result<(
pub fn new_light(
config: Configuration,
) -> Result<TaskManager, ServiceError> {
new_light_base(config).map(|(task_manager, _, _, _, _)| {
new_light_base(config).map(|(task_manager, _, _, _)| {
task_manager
})
}
Expand Down Expand Up @@ -694,7 +689,7 @@ mod tests {
Ok((node, setup_handles.unwrap()))
},
|config| {
let (keep_alive, _, client, network, transaction_pool) = new_light_base(config)?;
let (keep_alive, client, network, transaction_pool) = new_light_base(config)?;
Ok(sc_service_test::TestNetComponents::new(keep_alive, client, network, transaction_pool))
},
|service, &mut (ref mut block_import, ref babe_link)| {
Expand Down Expand Up @@ -856,7 +851,7 @@ mod tests {
Ok(sc_service_test::TestNetComponents::new(task_manager, client, network, transaction_pool))
},
|config| {
let (keep_alive, _, client, network, transaction_pool) = new_light_base(config)?;
let (keep_alive, client, network, transaction_pool) = new_light_base(config)?;
Ok(sc_service_test::TestNetComponents::new(keep_alive, client, network, transaction_pool))
},
vec![
Expand Down
14 changes: 3 additions & 11 deletions client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{
error::Error, MallocSizeOfWasm, RpcHandlers,
error::Error, MallocSizeOfWasm,
start_rpc_servers, build_network_future, TransactionPoolAdapter, TaskManager, SpawnTaskHandle,
metrics::MetricsService,
client::{light, Client, ClientConfig},
Expand Down Expand Up @@ -500,7 +500,7 @@ pub fn build_offchain_workers<TBl, TCl>(
/// Spawn the tasks that are required to run a node.
pub fn spawn_tasks<TBl, TBackend, TExPool, TCl>(
params: SpawnTasksParams<TBl, TCl, TExPool, TBackend>,
) -> Result<RpcHandlers, Error>
) -> Result<(), 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 @@ -616,14 +616,6 @@ pub fn spawn_tasks<TBl, TBackend, TExPool, TCl>(
// we could spawn it in the background but then the errors must be handled via a channel or something
let rpc = futures::executor::block_on(start_rpc_servers(&config, gen_rpc_module))?;

// NOTE(niklasad1): dummy type for now.
let noop_rpc_handlers = RpcHandlers;
// This is used internally, so don't restrict access to unsafe RPC
// let rpc_handlers = RpcHandlers(Arc::new(gen_handler(
// sc_rpc::DenyUnsafe::No,
// sc_rpc_server::RpcMiddleware::new(rpc_metrics, "inbrowser")
// ).into()));

// Spawn informant task
spawn_handle.spawn("informant", sc_informant::build(
client.clone(),
Expand All @@ -636,7 +628,7 @@ pub fn spawn_tasks<TBl, TBackend, TExPool, TCl>(
// this will not shutdown the server.
task_manager.keep_alive((config.base_path, rpc));

Ok(noop_rpc_handlers)
Ok(())
}

async fn transaction_notifications<TBl, TExPool>(
Expand Down
44 changes: 1 addition & 43 deletions client/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use std::pin::Pin;
use std::collections::HashMap;
use std::task::Poll;

use futures::{Future, FutureExt, Stream, StreamExt, stream};
use futures::{FutureExt, Stream, StreamExt, stream};
use sc_network::PeerId;
use log::{warn, debug, error};
use codec::{Encode, Decode};
Expand Down Expand Up @@ -94,26 +94,6 @@ impl<T: MallocSizeOf> MallocSizeOfWasm for T {}
#[cfg(target_os = "unknown")]
impl<T> MallocSizeOfWasm for T {}

/// RPC handlers that can perform RPC queries.
#[derive(Clone)]
pub struct RpcHandlers;

impl RpcHandlers {
/// Starts an RPC query.
///
/// The query is passed as a string and must be a JSON text similar to what an HTTP client
/// would for example send.
///
/// Returns a `Future` that contains the optional response.
///
/// If the request subscribes you to events, the `Sender` in the `RpcSession` object is used to
/// send back spontaneous events.
pub fn rpc_query(&self, _mem: &RpcSession, _request: &str)
-> Pin<Box<dyn Future<Output = Option<String>> + Send>> {
todo!();
}
}

/// An incomplete set of chain components, but enough to run the chain ops subcommands.
pub struct PartialComponents<Client, Backend, SelectChain, ImportQueue, TransactionPool, Other> {
/// A shared client instance.
Expand Down Expand Up @@ -367,28 +347,6 @@ fn start_rpc_servers<
Ok(Box::new(()))
}

/// An RPC session. Used to perform in-memory RPC queries (ie. RPC queries that don't go through
/// the HTTP or WebSockets server).
#[derive(Clone)]
pub struct RpcSession {
metadata: (),
}

// TODO: (dp) Should be safe to remove but has some scary fallout for util/browser we need to understand better.
impl RpcSession {
/// Creates an RPC session.
///
/// The `sender` is stored inside the `RpcSession` and is used to communicate spontaneous JSON
/// messages.
///
/// The `RpcSession` must be kept alive in order to receive messages on the sender.
pub fn new(_sender: futures01::sync::mpsc::Sender<String>) -> RpcSession {
RpcSession {
metadata: (),
}
}
}

/// Transaction pool adapter.
pub struct TransactionPoolAdapter<C, P> {
imports_external_transactions: bool,
Expand Down
Loading

0 comments on commit 1b61b1a

Please sign in to comment.