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

companion #8738 (jsonrpsee) #823

Merged
merged 17 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
1,322 changes: 493 additions & 829 deletions Cargo.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use cumulus_primitives_core::ParaId;
use cumulus_test_service::{initial_head_data, run_relay_chain_validator_node, Keyring::*};
use futures::join;

#[substrate_test_utils::test]
#[substrate_test_utils::test(flavor = "multi_thread")]
#[ignore]
async fn sync_blocks_from_tip_without_being_connected_to_a_collator() {
let mut builder = sc_cli::LoggerBuilder::new("");
Expand Down
2 changes: 1 addition & 1 deletion client/pov-recovery/tests/pov_recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::sync::Arc;
/// If there is a block of the parachain included/backed by the relay chain that isn't circulated in
/// the parachain network, we need to recover the PoV from the relay chain. Using this PoV we can
/// recover the block, import it and share it with the other nodes of the parachain network.
#[substrate_test_utils::test]
#[substrate_test_utils::test(flavor = "multi_thread")]
#[ignore]
async fn pov_recovery() {
let mut builder = sc_cli::LoggerBuilder::new("");
Expand Down
2 changes: 1 addition & 1 deletion client/relay-chain-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ parking_lot = "0.12.0"
derive_more = "0.99.2"
async-trait = "0.1.53"
thiserror = "1.0.31"
jsonrpsee-core = "0.11.0"
jsonrpsee-core = "0.12.0"
parity-scale-codec = "3.1.2"
2 changes: 1 addition & 1 deletion client/relay-chain-rpc-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ futures = "0.3.21"
futures-timer = "3.0.2"
parity-scale-codec = "3.1.2"
parking_lot = "0.12.0"
jsonrpsee = { version = "0.11.0", features = ["client"] }
jsonrpsee = { version = "0.12.0", features = ["client"] }
tracing = "0.1.34"
async-trait = "0.1.53"
url = "2.2.2"
Expand Down
2 changes: 1 addition & 1 deletion pallets/parachain-system/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ std = [

runtime-benchmarks = [
"sp-runtime/runtime-benchmarks"
]
]
2 changes: 1 addition & 1 deletion parachain-template/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ log = "0.4.17"
codec = { package = "parity-scale-codec", version = "3.0.0" }
serde = { version = "1.0.137", features = ["derive"] }
hex-literal = "0.3.4"
jsonrpc-core = "18.0.0"
jsonrpsee = { version = "0.12.0", features = ["server"] }

# Local
parachain-template-runtime = { path = "../runtime" }
Expand Down
19 changes: 10 additions & 9 deletions parachain-template/node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};

/// A type representing all RPC extensions.
pub type RpcExtension = jsonrpc_core::IoHandler<sc_rpc::Metadata>;
pub type RpcExtension = jsonrpsee::RpcModule<()>;

/// Full client dependencies
pub struct FullDeps<C, P> {
Expand All @@ -30,7 +30,9 @@ pub struct FullDeps<C, P> {
}

/// Instantiate all RPC extensions.
pub fn create_full<C, P>(deps: FullDeps<C, P>) -> RpcExtension
pub fn create_full<C, P>(
deps: FullDeps<C, P>,
) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<Block>
+ HeaderBackend<Block>
Expand All @@ -44,14 +46,13 @@ where
C::Api: BlockBuilder<Block>,
P: TransactionPool + Sync + Send + 'static,
{
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
use substrate_frame_rpc_system::{FullSystem, SystemApi};
use pallet_transaction_payment_rpc::{TransactionPaymentApiServer, TransactionPaymentRpc};
use substrate_frame_rpc_system::{SystemApiServer, SystemRpc};

let mut io = jsonrpc_core::IoHandler::default();
let mut module = RpcExtension::new(());
let FullDeps { client, pool, deny_unsafe } = deps;

io.extend_with(SystemApi::to_delegate(FullSystem::new(client.clone(), pool, deny_unsafe)));
io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new(client)));

io
module.merge(SystemRpc::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?;
module.merge(TransactionPaymentRpc::new(client.clone()).into_rpc())?;
Ok(module)
}
13 changes: 8 additions & 5 deletions parachain-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
// std
use std::{sync::Arc, time::Duration};

// rpc
use jsonrpsee::RpcModule;

use cumulus_client_cli::CollatorOptions;
// Local Runtime Types
use parachain_template_runtime::{
Expand Down Expand Up @@ -222,7 +225,7 @@ where
Executor: sc_executor::NativeExecutionDispatch + 'static,
RB: Fn(
Arc<TFullClient<Block, RuntimeApi, Executor>>,
) -> Result<jsonrpc_core::IoHandler<sc_rpc::Metadata>, sc_service::Error>
) -> Result<RpcModule<()>, sc_service::Error>
+ Send
+ 'static,
BIQ: FnOnce(
Expand Down Expand Up @@ -301,7 +304,7 @@ where
warp_sync: None,
})?;

let rpc_extensions_builder = {
let rpc_builder = {
let client = client.clone();
let transaction_pool = transaction_pool.clone();

Expand All @@ -312,12 +315,12 @@ where
deny_unsafe,
};

Ok(crate::rpc::create_full(deps))
crate::rpc::create_full(deps).map_err(Into::into)
})
};

sc_service::spawn_tasks(sc_service::SpawnTasksParams {
rpc_extensions_builder,
rpc_builder,
client: client.clone(),
transaction_pool: transaction_pool.clone(),
task_manager: &mut task_manager,
Expand Down Expand Up @@ -461,7 +464,7 @@ pub async fn start_parachain_node(
polkadot_config,
collator_options,
id,
|_| Ok(Default::default()),
|_| Ok(RpcModule::new(())),
parachain_build_import_queue,
|client,
prometheus_registry,
Expand Down
2 changes: 1 addition & 1 deletion polkadot-parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ statemint-runtime = { path = "statemint" }
statemine-runtime = { path = "statemine" }
westmint-runtime = { path = "westmint" }
canvas-kusama-runtime = { path = "canvas-kusama" }
jsonrpc-core = "18.0.0"
jsonrpsee = { version = "0.12.0", features = ["server"] }
parachains-common = { path = "parachains-common" }

# Substrate
Expand Down
41 changes: 23 additions & 18 deletions polkadot-parachains/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

use std::sync::Arc;

use pallet_contracts_rpc::{Contracts, ContractsApi};
use parachains_common::{AccountId, Balance, Block, BlockNumber, Hash, Index as Nonce};
use sc_client_api::AuxStore;
pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor};
Expand All @@ -30,7 +29,7 @@ use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};

/// A type representing all RPC extensions.
pub type RpcExtension = jsonrpc_core::IoHandler<sc_rpc::Metadata>;
pub type RpcExtension = jsonrpsee::RpcModule<()>;

/// Full client dependencies
pub struct FullDeps<C, P> {
Expand All @@ -43,7 +42,9 @@ pub struct FullDeps<C, P> {
}

/// Instantiate all RPC extensions.
pub fn create_full<C, P>(deps: FullDeps<C, P>) -> RpcExtension
pub fn create_full<C, P>(
deps: FullDeps<C, P>,
) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<Block>
+ HeaderBackend<Block>
Expand All @@ -57,20 +58,22 @@ where
C::Api: BlockBuilder<Block>,
P: TransactionPool + Sync + Send + 'static,
{
use frame_rpc_system::{FullSystem, SystemApi};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
use frame_rpc_system::{SystemApiServer, SystemRpc};
use pallet_transaction_payment_rpc::{TransactionPaymentApiServer, TransactionPaymentRpc};

let mut io = jsonrpc_core::IoHandler::default();
let mut module = RpcExtension::new(());
let FullDeps { client, pool, deny_unsafe } = deps;

io.extend_with(SystemApi::to_delegate(FullSystem::new(client.clone(), pool, deny_unsafe)));
io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new(client.clone())));
module.merge(SystemRpc::new(client.clone(), pool, deny_unsafe).into_rpc())?;
module.merge(TransactionPaymentRpc::new(client.clone()).into_rpc())?;

io
Ok(module)
}

/// Instantiate all RPCs we want at the canvas-kusama chain.
pub fn create_canvas_kusama<C, P>(deps: FullDeps<C, P>) -> RpcExtension
pub fn create_canvas_kusama<C, P>(
deps: FullDeps<C, P>,
) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<Block>
+ sc_client_api::BlockBackend<Block>
Expand All @@ -86,16 +89,18 @@ where
C::Api: BlockBuilder<Block>,
P: TransactionPool + Sync + Send + 'static,
{
use frame_rpc_system::{FullSystem, SystemApi};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
use frame_rpc_system::{SystemApiServer, SystemRpc};
use pallet_contracts_rpc::{ContractsApiServer, ContractsRpc};
use pallet_transaction_payment_rpc::{TransactionPaymentApiServer, TransactionPaymentRpc};
use sc_rpc::dev::{Dev, DevApiServer};

let mut io = jsonrpc_core::IoHandler::default();
let mut module = RpcExtension::new(());
let FullDeps { client, pool, deny_unsafe } = deps;

io.extend_with(SystemApi::to_delegate(FullSystem::new(client.clone(), pool, deny_unsafe)));
io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new(client.clone())));
io.extend_with(ContractsApi::to_delegate(Contracts::new(client.clone())));
io.extend_with(sc_rpc::dev::DevApi::to_delegate(sc_rpc::dev::Dev::new(client, deny_unsafe)));
module.merge(SystemRpc::new(client.clone(), pool, deny_unsafe).into_rpc())?;
module.merge(TransactionPaymentRpc::new(client.clone()).into_rpc())?;
module.merge(ContractsRpc::new(client.clone()).into_rpc())?;
module.merge(Dev::new(client, deny_unsafe).into_rpc())?;

io
Ok(module)
}
32 changes: 17 additions & 15 deletions polkadot-parachains/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ use cumulus_relay_chain_rpc_interface::RelayChainRPCInterface;
use polkadot_service::CollatorPair;
use sp_core::Pair;

use jsonrpsee::RpcModule;

use crate::rpc;
pub use parachains_common::{AccountId, Balance, Block, BlockNumber, Hash, Header, Index as Nonce};

Expand Down Expand Up @@ -340,7 +342,7 @@ where
sc_client_api::StateBackendFor<TFullBackend<Block>, Block>: sp_api::StateBackend<BlakeTwo256>,
RB: Fn(
Arc<TFullClient<Block, RuntimeApi, WasmExecutor<HostFunctions>>>,
) -> Result<jsonrpc_core::IoHandler<sc_rpc::Metadata>, sc_service::Error>
) -> Result<jsonrpsee::RpcModule<()>, sc_service::Error>
+ Send
+ 'static,
BIQ: FnOnce(
Expand Down Expand Up @@ -421,10 +423,10 @@ where
})?;

let rpc_client = client.clone();
let rpc_extensions_builder = Box::new(move |_, _| rpc_ext_builder(rpc_client.clone()));
let rpc_builder = Box::new(move |_, _| rpc_ext_builder(rpc_client.clone()));

sc_service::spawn_tasks(sc_service::SpawnTasksParams {
rpc_extensions_builder,
rpc_builder,
client: client.clone(),
transaction_pool: transaction_pool.clone(),
task_manager: &mut task_manager,
Expand Down Expand Up @@ -542,7 +544,7 @@ where
sc_client_api::StateBackendFor<TFullBackend<Block>, Block>: sp_api::StateBackend<BlakeTwo256>,
RB: Fn(
Arc<TFullClient<Block, RuntimeApi, WasmExecutor<HostFunctions>>>,
) -> Result<jsonrpc_core::IoHandler<sc_rpc::Metadata>, sc_service::Error>
) -> Result<jsonrpsee::RpcModule<()>, sc_service::Error>
+ Send
+ 'static,
BIQ: FnOnce(
Expand Down Expand Up @@ -621,7 +623,7 @@ where
warp_sync: None,
})?;

let rpc_extensions_builder = {
let rpc_builder = {
let client = client.clone();
let transaction_pool = transaction_pool.clone();

Expand All @@ -632,12 +634,12 @@ where
deny_unsafe,
};

Ok(rpc::create_full(deps))
rpc::create_full(deps).map_err(Into::into)
})
};

sc_service::spawn_tasks(sc_service::SpawnTasksParams {
rpc_extensions_builder,
rpc_builder,
client: client.clone(),
transaction_pool: transaction_pool.clone(),
task_manager: &mut task_manager,
Expand Down Expand Up @@ -782,7 +784,7 @@ pub async fn start_rococo_parachain_node(
polkadot_config,
collator_options,
id,
|_| Ok(Default::default()),
|_| Ok(RpcModule::new(())),
rococo_parachain_build_import_queue,
|client,
prometheus_registry,
Expand Down Expand Up @@ -925,7 +927,7 @@ where
polkadot_config,
collator_options,
id,
|_| Ok(Default::default()),
|_| Ok(RpcModule::new(())),
shell_build_import_queue,
|client,
prometheus_registry,
Expand Down Expand Up @@ -1200,7 +1202,7 @@ where
polkadot_config,
collator_options,
id,
|_| Ok(Default::default()),
|_| Ok(RpcModule::new(())),
statemint_build_import_queue::<_, AuraId>,
|client,
prometheus_registry,
Expand Down Expand Up @@ -1365,7 +1367,7 @@ where
sc_client_api::StateBackendFor<TFullBackend<Block>, Block>: sp_api::StateBackend<BlakeTwo256>,
RB: Fn(
Arc<TFullClient<Block, RuntimeApi, WasmExecutor<HostFunctions>>>,
) -> Result<jsonrpc_core::IoHandler<sc_rpc::Metadata>, sc_service::Error>
) -> Result<jsonrpsee::RpcModule<()>, sc_service::Error>
+ Send
+ 'static,
BIQ: FnOnce(
Expand Down Expand Up @@ -1444,7 +1446,7 @@ where
warp_sync: None,
})?;

let rpc_extensions_builder = {
let rpc_builder = {
let client = client.clone();
let transaction_pool = transaction_pool.clone();

Expand All @@ -1455,12 +1457,12 @@ where
deny_unsafe,
};

Ok(crate::rpc::create_canvas_kusama(deps))
crate::rpc::create_canvas_kusama(deps).map_err(Into::into)
})
};

sc_service::spawn_tasks(sc_service::SpawnTasksParams {
rpc_extensions_builder,
rpc_builder,
client: client.clone(),
transaction_pool: transaction_pool.clone(),
task_manager: &mut task_manager,
Expand Down Expand Up @@ -1603,7 +1605,7 @@ pub async fn start_canvas_kusama_node(
polkadot_config,
collator_options,
id,
|_| Ok(Default::default()),
|_| Ok(RpcModule::new(())),
canvas_kusama_build_import_queue,
|client,
prometheus_registry,
Expand Down
2 changes: 1 addition & 1 deletion test/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
async-trait = "0.1.53"
codec = { package = "parity-scale-codec", version = "3.0.0" }
criterion = { version = "0.3.5", features = [ "async_tokio" ] }
jsonrpc-core = "18.0.0"
jsonrpsee = { version = "0.12.0", features = ["server"] }
parking_lot = "0.12.0"
rand = "0.8.5"
serde = { version = "1.0.137", features = ["derive"] }
Expand Down
Loading