Use Subscription Manager from jsonrpc-pubsub (#6208)

* Bump jsonrpc pubsub, core, http, and ws

Right now these are the packages which _need_ to be updated
so I can just the latest `jsonrpc-pubsub` code. Once a release
it cut upstream the rest of the dependencies should be updated
as well.

* Use jsonrpc-pubsub's SubscriptionManager

This places sc-rpc-api::Subscriptions

* Bump jsonrpc-core outside of sc-rpc-*

* Update client/rpc tests

Right now one of the `author` tests is failing, I
need to think a bit about how best to fix it.

* Remove Subscriptions manager

There's no need for this implementation since we're
using the one from `jsonrpc-pubsub` now

* Fix author RPC test

This test used to check for a numerial subscription ID,
whereas now it uses a string based ID which is the default
provided by `jsonrpc-pubsub`'s subscription manager.

* Remove unused NumericIdProvider

* Add missing bracket

Removed one too many with that last one, lol

* Bump `jsonrpc` to v14.2

There's an exception though. `jsonrpc-derive` cannot be bumped
past v14.0.5 just yet since it has a dependency on `quote` pinned
to v1.0.1. This means that at the moment it won't build on Substrate
since it's using v1.0.3.

* Track `jsonrpc-derive` master branch

* Bump `quote` version to v1.0.6

* Bump `jsonrpc-derive` to v14.2.1

This includes support for `quote` v1.0.6
This commit is contained in:
Hernando Castano
2020-06-04 04:50:22 -04:00
committed by GitHub
parent e3795af0e3
commit ea1eb4e57f
31 changed files with 196 additions and 285 deletions
+4 -4
View File
@@ -18,8 +18,8 @@
use std::sync::Arc;
use rpc::futures::future::result;
use jsonrpc_pubsub::manager::SubscriptionManager;
use sc_rpc_api::Subscriptions;
use sc_client_api::{BlockchainEvents, BlockBackend};
use sp_runtime::{generic::{BlockId, SignedBlock}, traits::{Block as BlockT}};
@@ -32,14 +32,14 @@ pub struct FullChain<Block: BlockT, Client> {
/// Substrate client.
client: Arc<Client>,
/// Current subscriptions.
subscriptions: Subscriptions,
subscriptions: SubscriptionManager,
/// phantom member to pin the block type
_phantom: PhantomData<Block>,
}
impl<Block: BlockT, Client> FullChain<Block, Client> {
/// Create new Chain API RPC handler.
pub fn new(client: Arc<Client>, subscriptions: Subscriptions) -> Self {
pub fn new(client: Arc<Client>, subscriptions: SubscriptionManager) -> Self {
Self {
client,
subscriptions,
@@ -56,7 +56,7 @@ impl<Block, Client> ChainBackend<Client, Block> for FullChain<Block, Client> whe
&self.client
}
fn subscriptions(&self) -> &Subscriptions {
fn subscriptions(&self) -> &SubscriptionManager {
&self.subscriptions
}
@@ -19,8 +19,8 @@
use std::sync::Arc;
use futures::{future::ready, FutureExt, TryFutureExt};
use rpc::futures::future::{result, Future, Either};
use jsonrpc_pubsub::manager::SubscriptionManager;
use sc_rpc_api::Subscriptions;
use sc_client_api::light::{Fetcher, RemoteBodyRequest, RemoteBlockchain};
use sp_runtime::{
generic::{BlockId, SignedBlock},
@@ -37,7 +37,7 @@ pub struct LightChain<Block: BlockT, Client, F> {
/// Substrate client.
client: Arc<Client>,
/// Current subscriptions.
subscriptions: Subscriptions,
subscriptions: SubscriptionManager,
/// Remote blockchain reference
remote_blockchain: Arc<dyn RemoteBlockchain<Block>>,
/// Remote fetcher reference.
@@ -48,7 +48,7 @@ impl<Block: BlockT, Client, F: Fetcher<Block>> LightChain<Block, Client, F> {
/// Create new Chain API RPC handler.
pub fn new(
client: Arc<Client>,
subscriptions: Subscriptions,
subscriptions: SubscriptionManager,
remote_blockchain: Arc<dyn RemoteBlockchain<Block>>,
fetcher: Arc<F>,
) -> Self {
@@ -70,7 +70,7 @@ impl<Block, Client, F> ChainBackend<Client, Block> for LightChain<Block, Client,
&self.client
}
fn subscriptions(&self) -> &Subscriptions {
fn subscriptions(&self) -> &SubscriptionManager {
&self.subscriptions
}
+5 -6
View File
@@ -32,9 +32,8 @@ use rpc::{
futures::{stream, Future, Sink, Stream},
};
use sc_rpc_api::Subscriptions;
use sc_client_api::{BlockchainEvents, light::{Fetcher, RemoteBlockchain}};
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId};
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId, manager::SubscriptionManager};
use sp_rpc::{number::NumberOrHex, list::ListOrValue};
use sp_runtime::{
generic::{BlockId, SignedBlock},
@@ -57,7 +56,7 @@ trait ChainBackend<Client, Block: BlockT>: Send + Sync + 'static
fn client(&self) -> &Arc<Client>;
/// Get subscriptions reference.
fn subscriptions(&self) -> &Subscriptions;
fn subscriptions(&self) -> &SubscriptionManager;
/// Tries to unwrap passed block hash, or uses best block hash otherwise.
fn unwrap_or_best(&self, hash: Option<Block::Hash>) -> Block::Hash {
@@ -177,7 +176,7 @@ trait ChainBackend<Client, Block: BlockT>: Send + Sync + 'static
/// Create new state API that works on full node.
pub fn new_full<Block: BlockT, Client>(
client: Arc<Client>,
subscriptions: Subscriptions,
subscriptions: SubscriptionManager,
) -> Chain<Block, Client>
where
Block: BlockT + 'static,
@@ -191,7 +190,7 @@ pub fn new_full<Block: BlockT, Client>(
/// Create new state API that works on light node.
pub fn new_light<Block: BlockT, Client, F: Fetcher<Block>>(
client: Arc<Client>,
subscriptions: Subscriptions,
subscriptions: SubscriptionManager,
remote_blockchain: Arc<dyn RemoteBlockchain<Block>>,
fetcher: Arc<F>,
) -> Chain<Block, Client>
@@ -279,7 +278,7 @@ impl<Block, Client> ChainApi<NumberFor<Block>, Block::Hash, Block::Header, Signe
/// Subscribe to new headers.
fn subscribe_headers<Block, Client, F, G, S, ERR>(
client: &Arc<Client>,
subscriptions: &Subscriptions,
subscriptions: &SubscriptionManager,
subscriber: Subscriber<Block::Header>,
best_block_hash: G,
stream: F,
+19 -10
View File
@@ -31,7 +31,7 @@ use crate::testing::TaskExecutor;
#[test]
fn should_return_header() {
let client = Arc::new(substrate_test_runtime_client::new());
let api = new_full(client.clone(), Subscriptions::new(Arc::new(TaskExecutor)));
let api = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor)));
assert_matches!(
api.header(Some(client.genesis_hash()).into()).wait(),
@@ -63,7 +63,7 @@ fn should_return_header() {
#[test]
fn should_return_a_block() {
let mut client = Arc::new(substrate_test_runtime_client::new());
let api = new_full(client.clone(), Subscriptions::new(Arc::new(TaskExecutor)));
let api = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor)));
let block = client.new_block(Default::default()).unwrap().build().unwrap().block;
let block_hash = block.hash();
@@ -114,7 +114,7 @@ fn should_return_a_block() {
#[test]
fn should_return_block_hash() {
let mut client = Arc::new(substrate_test_runtime_client::new());
let api = new_full(client.clone(), Subscriptions::new(Arc::new(TaskExecutor)));
let api = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor)));
assert_matches!(
api.block_hash(None.into()),
@@ -158,7 +158,7 @@ fn should_return_block_hash() {
#[test]
fn should_return_finalized_hash() {
let mut client = Arc::new(substrate_test_runtime_client::new());
let api = new_full(client.clone(), Subscriptions::new(Arc::new(TaskExecutor)));
let api = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor)));
assert_matches!(
api.finalized_head(),
@@ -188,12 +188,15 @@ fn should_notify_about_latest_block() {
{
let mut client = Arc::new(substrate_test_runtime_client::new());
let api = new_full(client.clone(), Subscriptions::new(Arc::new(TaskExecutor)));
let api = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor)));
api.subscribe_all_heads(Default::default(), subscriber);
// assert id assigned
assert_eq!(executor::block_on(id.compat()), Ok(Ok(SubscriptionId::Number(1))));
assert!(matches!(
executor::block_on(id.compat()),
Ok(Ok(SubscriptionId::String(_)))
));
let block = client.new_block(Default::default()).unwrap().build().unwrap().block;
client.import(BlockOrigin::Own, block).unwrap();
@@ -215,12 +218,15 @@ fn should_notify_about_best_block() {
{
let mut client = Arc::new(substrate_test_runtime_client::new());
let api = new_full(client.clone(), Subscriptions::new(Arc::new(TaskExecutor)));
let api = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor)));
api.subscribe_new_heads(Default::default(), subscriber);
// assert id assigned
assert_eq!(executor::block_on(id.compat()), Ok(Ok(SubscriptionId::Number(1))));
assert!(matches!(
executor::block_on(id.compat()),
Ok(Ok(SubscriptionId::String(_)))
));
let block = client.new_block(Default::default()).unwrap().build().unwrap().block;
client.import(BlockOrigin::Own, block).unwrap();
@@ -242,12 +248,15 @@ fn should_notify_about_finalized_block() {
{
let mut client = Arc::new(substrate_test_runtime_client::new());
let api = new_full(client.clone(), Subscriptions::new(Arc::new(TaskExecutor)));
let api = new_full(client.clone(), SubscriptionManager::new(Arc::new(TaskExecutor)));
api.subscribe_finalized_heads(Default::default(), subscriber);
// assert id assigned
assert_eq!(executor::block_on(id.compat()), Ok(Ok(SubscriptionId::Number(1))));
assert!(matches!(
executor::block_on(id.compat()),
Ok(Ok(SubscriptionId::String(_)))
));
let block = client.new_block(Default::default()).unwrap().build().unwrap().block;
client.import(BlockOrigin::Own, block).unwrap();