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

companion for #8783 - jsonrpsee #4344

Merged
merged 30 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
23787e2
add jsonrpsee glue code
niklasad1 Nov 1, 2021
24b0def
diener --substrate dp-jsonrpsee-integration-2
niklasad1 Apr 6, 2022
95e8078
cargo fmt
niklasad1 Apr 6, 2022
d683d98
update substrate
niklasad1 Apr 7, 2022
fbf8d2c
Merge remote-tracking branch 'origin/master' into dp-jsonrpsee-integr…
niklasad1 Apr 19, 2022
5695664
fix build
niklasad1 Apr 19, 2022
be4ac88
update substrate
niklasad1 Apr 19, 2022
f36321d
fix tests
niklasad1 Apr 19, 2022
2c8032b
Merge remote-tracking branch 'origin/master' into dp-jsonrpsee-integr…
niklasad1 Apr 19, 2022
fe61446
update substrate
niklasad1 Apr 19, 2022
b479cc3
update substrate
niklasad1 Apr 19, 2022
85676a4
revert Cargo.toml
niklasad1 Apr 19, 2022
9f5db3d
revert changes in Cargo.toml
niklasad1 Apr 21, 2022
2965d72
Merge remote-tracking branch 'origin/master' into dp-jsonrpsee-integr…
niklasad1 Apr 21, 2022
9c782d9
jsonrpsee v0.11
niklasad1 Apr 21, 2022
5bfa866
fix staking miner
niklasad1 Apr 21, 2022
10c080b
Merge remote-tracking branch 'origin/master' into dp-jsonrpsee-integr…
niklasad1 May 6, 2022
47e6cf4
chore: update jsonrpsee v0.12
niklasad1 May 6, 2022
1b57f20
update companion
niklasad1 May 7, 2022
2650665
update companion
niklasad1 May 7, 2022
5293ac2
fix changes in substrate
niklasad1 May 7, 2022
8796c6d
revert requires_full_sync removal
niklasad1 May 7, 2022
3881cfe
fix: read WS address from polkadot output
niklasad1 May 9, 2022
663fc65
Merge remote-tracking branch 'origin/master' into dp-jsonrpsee-integr…
niklasad1 May 9, 2022
9c28fcb
fit nits
niklasad1 May 9, 2022
dda90eb
Merge remote-tracking branch 'origin/master' into dp-jsonrpsee-integr…
niklasad1 May 9, 2022
0816d8e
fix more nits
niklasad1 May 9, 2022
5c7d30e
Merge remote-tracking branch 'origin/master' into dp-jsonrpsee-integr…
May 10, 2022
66113d3
update lockfile for {"substrate"}
May 10, 2022
8c41516
cargo fmt
niklasad1 May 10, 2022
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
510 changes: 323 additions & 187 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion node/metrics/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::collections::HashMap;

const DEFAULT_PROMETHEUS_PORT: u16 = 9616;

#[substrate_test_utils::test]
#[substrate_test_utils::test(flavor = "multi_thread")]
Copy link

Choose a reason for hiding this comment

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

@niklasad1 is it something like this that maybe leads to the issue with port 9944 being hardcoded in the test code being hit?

Copy link
Member Author

Choose a reason for hiding this comment

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

most likely, I have pushed the latest stuff that hopefully fixes that.

async fn runtime_can_publish_metrics() {
let mut alice_config =
node_config(|| {}, tokio::runtime::Handle::current(), Alice, Vec::new(), true);
Expand Down
2 changes: 1 addition & 1 deletion node/network/protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ rand = "0.8"
derive_more = "0.99"

[dev-dependencies]
rand_chacha = "0.3.1"
rand_chacha = "0.3.1"
2 changes: 1 addition & 1 deletion node/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,4 @@ runtime-metrics = [
"polkadot-runtime-parachains/runtime-metrics"
]

staging-client = ["polkadot-node-core-provisioner/staging-client"]
staging-client = ["polkadot-node-core-provisioner/staging-client"]
7 changes: 5 additions & 2 deletions node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,10 @@ fn new_partial<RuntimeApi, ExecutorDispatch, ChainSelection>(
sc_consensus::DefaultImportQueue<Block, FullClient<RuntimeApi, ExecutorDispatch>>,
sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,
(
impl service::RpcExtensionBuilder,
impl Fn(
polkadot_rpc::DenyUnsafe,
polkadot_rpc::SubscriptionTaskExecutor,
) -> Result<polkadot_rpc::RpcExtension, SubstrateServiceError>,
(
babe::BabeBlockImport<
Block,
Expand Down Expand Up @@ -938,7 +941,7 @@ where
client: client.clone(),
keystore: keystore_container.sync_keystore(),
network: network.clone(),
rpc_extensions_builder: Box::new(rpc_extensions_builder),
rpc_builder: Box::new(rpc_extensions_builder),
transaction_pool: transaction_pool.clone(),
task_manager: &mut task_manager,
system_rpc_tx,
Expand Down
4 changes: 4 additions & 0 deletions node/test/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,13 @@ pub fn node_config(
rpc_ws: None,
rpc_ipc: None,
rpc_max_payload: None,
rpc_max_request_size: None,
rpc_max_response_size: None,
rpc_ws_max_connections: None,
rpc_cors: None,
rpc_methods: Default::default(),
rpc_id_provider: None,
rpc_max_subs_per_conn: None,
ws_max_out_buffer_capacity: None,
prometheus_config: None,
telemetry_endpoints: None,
Expand Down
2 changes: 1 addition & 1 deletion node/test/service/tests/build-blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use futures::{future, pin_mut, select, FutureExt};
use polkadot_test_service::*;
use sp_keyring::Sr25519Keyring;

#[substrate_test_utils::test]
#[substrate_test_utils::test(flavor = "multi_thread")]
async fn ensure_test_service_build_blocks() {
let mut builder = sc_cli::LoggerBuilder::new("");
builder.with_colors(false);
Expand Down
4 changes: 2 additions & 2 deletions node/test/service/tests/call-function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use polkadot_test_service::*;
use sp_keyring::Sr25519Keyring::{Alice, Bob, Charlie};

#[substrate_test_utils::test]
#[substrate_test_utils::test(flavor = "multi_thread")]
async fn call_function_actually_work() {
let alice_config =
node_config(|| {}, tokio::runtime::Handle::current(), Alice, Vec::new(), true);
Expand All @@ -30,7 +30,7 @@ async fn call_function_actually_work() {
});
let output = alice.send_extrinsic(function, Bob).await.unwrap();

let res = output.result.expect("return value expected");
let res = output.result;
let json = serde_json::from_str::<serde_json::Value>(res.as_str()).expect("valid JSON");
let object = json.as_object().expect("JSON is an object");
assert!(object.contains_key("jsonrpc"), "key jsonrpc exists");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
const PUPPET_EXE: &str = env!("CARGO_BIN_EXE_adder_collator_puppet_worker");

// If this test is failing, make sure to run all tests with the `real-overseer` feature being enabled.
#[substrate_test_utils::test]

#[substrate_test_utils::test(flavor = "multi_thread")]
async fn collating_using_adder_collator() {
use polkadot_primitives::v2::Id as ParaId;
use sp_keyring::AccountKeyring::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
const PUPPET_EXE: &str = env!("CARGO_BIN_EXE_undying_collator_puppet_worker");

// If this test is failing, make sure to run all tests with the `real-overseer` feature being enabled.
#[substrate_test_utils::test]
#[substrate_test_utils::test(flavor = "multi_thread")]
async fn collating_using_undying_collator() {
use polkadot_primitives::v2::Id as ParaId;
use sp_keyring::AccountKeyring::*;
Expand Down
2 changes: 1 addition & 1 deletion rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
edition = "2021"

[dependencies]
jsonrpc-core = "18.0.0"
jsonrpsee = { version = "0.12.0", features = ["server"] }
polkadot-primitives = { path = "../primitives" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" }
Expand Down
93 changes: 51 additions & 42 deletions rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

use std::sync::Arc;

use jsonrpsee::RpcModule;
use polkadot_primitives::v2::{AccountId, Balance, Block, BlockNumber, Hash, Nonce};
use sc_client_api::AuxStore;
use sc_consensus_babe::Epoch;
use sc_finality_grandpa::FinalityProofProvider;
pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor};
use sc_sync_state_rpc::{SyncStateRpcApi, SyncStateRpcHandler};
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
Expand All @@ -35,7 +35,7 @@ use sp_keystore::SyncCryptoStorePtr;
use txpool_api::TransactionPool;

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

/// Extra dependencies for BABE.
pub struct BabeDeps {
Expand Down Expand Up @@ -115,13 +115,16 @@ where
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sc_client_api::StateBackend<sp_runtime::traits::HashFor<Block>>,
{
use frame_rpc_system::{FullSystem, SystemApi};
use pallet_mmr_rpc::{Mmr, MmrApi};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
use sc_consensus_babe_rpc::BabeRpcHandler;
use sc_finality_grandpa_rpc::{GrandpaApi, GrandpaRpcHandler};

let mut io = jsonrpc_core::IoHandler::default();
use beefy_gadget_rpc::{BeefyApiServer, BeefyRpcHandler};
use frame_rpc_system::{SystemApiServer, SystemRpc};
use pallet_mmr_rpc::{MmrApiServer, MmrRpc};
use pallet_transaction_payment_rpc::{TransactionPaymentApiServer, TransactionPaymentRpc};
use sc_consensus_babe_rpc::{BabeApiServer, BabeRpc};
use sc_finality_grandpa_rpc::{GrandpaApiServer, GrandpaRpc};
use sc_sync_state_rpc::{SyncStateRpc, SyncStateRpcApiServer};
use substrate_state_trie_migration_rpc::StateMigrationApiServer;

let mut io = RpcModule::new(());
let FullDeps { client, pool, select_chain, chain_spec, deny_unsafe, babe, grandpa, beefy } =
deps;
let BabeDeps { keystore, babe_config, shared_epoch_changes } = babe;
Expand All @@ -133,41 +136,47 @@ where
finality_provider,
} = grandpa;

io.extend_with(substrate_state_trie_migration_rpc::StateMigrationApi::to_delegate(
substrate_state_trie_migration_rpc::MigrationRpc::new(client.clone(), backend, deny_unsafe),
));

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(MmrApi::to_delegate(Mmr::new(client.clone())));
io.extend_with(sc_consensus_babe_rpc::BabeApi::to_delegate(BabeRpcHandler::new(
client.clone(),
shared_epoch_changes.clone(),
keystore,
babe_config,
select_chain,
deny_unsafe,
)));
io.extend_with(GrandpaApi::to_delegate(GrandpaRpcHandler::new(
shared_authority_set.clone(),
shared_voter_state,
justification_stream,
subscription_executor,
finality_provider,
)));
io.extend_with(SyncStateRpcApi::to_delegate(SyncStateRpcHandler::new(
chain_spec,
client,
shared_authority_set,
shared_epoch_changes,
)?));
io.merge(
substrate_state_trie_migration_rpc::MigrationRpc::new(client.clone(), backend, deny_unsafe)
.into_rpc(),
)?;
io.merge(SystemRpc::new(client.clone(), pool.clone(), deny_unsafe).into_rpc())?;
io.merge(TransactionPaymentRpc::new(client.clone()).into_rpc())?;
io.merge(MmrRpc::new(client.clone()).into_rpc())?;
io.merge(
BabeRpc::new(
client.clone(),
shared_epoch_changes.clone(),
keystore,
babe_config,
select_chain,
deny_unsafe,
)
.into_rpc(),
)?;
io.merge(
GrandpaRpc::new(
subscription_executor,
shared_authority_set.clone(),
shared_voter_state,
justification_stream,
finality_provider,
)
.into_rpc(),
)?;
io.merge(
SyncStateRpc::new(chain_spec, client, shared_authority_set, shared_epoch_changes)?
.into_rpc(),
)?;

let handler: beefy_gadget_rpc::BeefyRpcHandler<Block> = beefy_gadget_rpc::BeefyRpcHandler::new(
beefy.beefy_commitment_stream,
beefy.beefy_best_block_stream,
beefy.subscription_executor,
io.merge(
BeefyRpcHandler::<Block>::new(
beefy.beefy_commitment_stream,
beefy.beefy_best_block_stream,
beefy.subscription_executor,
)?
.into_rpc(),
)?;
io.extend_with(beefy_gadget_rpc::BeefyApi::to_delegate(handler));

Ok(io)
}
2 changes: 1 addition & 1 deletion runtime/parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ try-runtime = [
"pallet-vesting/try-runtime",
]
runtime-metrics = ["sp-tracing/with-tracing", "polkadot-runtime-metrics/runtime-metrics"]
vstaging = []
vstaging = []
2 changes: 1 addition & 1 deletion utils/staking-miner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
codec = { package = "parity-scale-codec", version = "3.0.0" }
clap = { version = "3.1", features = ["derive", "env"] }
tracing-subscriber = { version = "0.3.10", features = ["env-filter"] }
jsonrpsee = { version = "0.10.1", features = ["ws-client", "macros"] }
jsonrpsee = { version = "0.12.0", features = ["ws-client", "macros"] }
log = "0.4.16"
paste = "1.0.7"
serde = "1.0.137"
Expand Down
15 changes: 0 additions & 15 deletions utils/staking-miner/src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,6 @@ macro_rules! monitor_cmd_for { ($runtime:tt) => { paste::paste! {
maybe_rp = subscription.next() => {
match maybe_rp {
Some(Ok(r)) => r,
// Custom `jsonrpsee` message sent by the server if the subscription was closed on the server side.
Some(Err(RpcError::SubscriptionClosed(reason))) => {
log::warn!(target: LOG_TARGET, "subscription to `subscribeNewHeads/subscribeFinalizedHeads` terminated: {:?}. Retrying..", reason);
subscription = heads_subscription().await?;
continue;
}
Some(Err(e)) => {
log::error!(target: LOG_TARGET, "subscription failed to decode Header {:?}, this is bug please file an issue", e);
return Err(e.into());
Expand Down Expand Up @@ -312,15 +306,6 @@ macro_rules! monitor_cmd_for { ($runtime:tt) => { paste::paste! {
while let Some(rp) = tx_subscription.next().await {
let status_update = match rp {
Ok(r) => r,
// Custom `jsonrpsee` message sent by the server if the subscription was closed on the server side.
Err(RpcError::SubscriptionClosed(reason)) => {
log::warn!(
target: LOG_TARGET,
"tx subscription closed by the server: {:?}; skip block: {}",
reason, at.number
);
return;
},
Err(e) => {
log::error!(target: LOG_TARGET, "subscription failed to decode TransactionStatus {:?}, this is a bug please file an issue", e);
let _ = tx.send(e.into());
Expand Down
6 changes: 3 additions & 3 deletions utils/staking-miner/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,23 @@ pub trait RpcApi {
unsubscribe = "author_unwatchExtrinsic",
item = TransactionStatus<Hash, Hash>
)]
fn watch_extrinsic(&self, bytes: &Bytes) -> RpcResult<()>;
fn watch_extrinsic(&self, bytes: &Bytes);

/// New head subscription.
#[subscription(
name = "chain_subscribeNewHeads" => "newHead",
unsubscribe = "chain_unsubscribeNewHeads",
item = Header
)]
fn subscribe_new_heads(&self) -> RpcResult<()>;
fn subscribe_new_heads(&self);

/// Finalized head subscription.
#[subscription(
name = "chain_subscribeFinalizedHeads" => "chain_finalizedHead",
unsubscribe = "chain_unsubscribeFinalizedHeads",
item = Header
)]
fn subscribe_finalized_heads(&self) -> RpcResult<()>;
fn subscribe_finalized_heads(&self);
}

/// Wraps a shared web-socket JSON-RPC client that can be cloned.
Expand Down