From 5ad94d93ed2743e54b23f86556d249f6adc61297 Mon Sep 17 00:00:00 2001 From: Hernando Castano Date: Mon, 12 Apr 2021 17:22:24 -0400 Subject: [PATCH] Bump `jsonrpsee` to Alpha.3 (#892) * Bump `jsonrpsee` to `alpha.3` * Arc-ify `WsClient` --- bridges/relays/client-ethereum/Cargo.toml | 6 +-- bridges/relays/client-substrate/Cargo.toml | 6 +-- bridges/relays/client-substrate/src/client.rs | 41 ++++++++++--------- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/bridges/relays/client-ethereum/Cargo.toml b/bridges/relays/client-ethereum/Cargo.toml index 79f6ab0cf6feb..56e346417301b 100644 --- a/bridges/relays/client-ethereum/Cargo.toml +++ b/bridges/relays/client-ethereum/Cargo.toml @@ -10,9 +10,9 @@ bp-eth-poa = { path = "../../primitives/ethereum-poa" } codec = { package = "parity-scale-codec", version = "2.0.0" } headers-relay = { path = "../headers" } hex-literal = "0.3" -jsonrpsee-proc-macros = "0.2.0-alpha.2" -jsonrpsee-types = "0.2.0-alpha.2" -jsonrpsee-ws-client = "0.2.0-alpha.2" +jsonrpsee-proc-macros = "=0.2.0-alpha.3" +jsonrpsee-types = "=0.2.0-alpha.3" +jsonrpsee-ws-client = "=0.2.0-alpha.3" libsecp256k1 = { version = "0.3.4", default-features = false, features = ["hmac"] } log = "0.4.11" relay-utils = { path = "../utils" } diff --git a/bridges/relays/client-substrate/Cargo.toml b/bridges/relays/client-substrate/Cargo.toml index 48feac3834e4e..e70351877c2e0 100644 --- a/bridges/relays/client-substrate/Cargo.toml +++ b/bridges/relays/client-substrate/Cargo.toml @@ -9,9 +9,9 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" async-std = "1.6.5" async-trait = "0.1.40" codec = { package = "parity-scale-codec", version = "2.0.0" } -jsonrpsee-proc-macros = "0.2.0-alpha.2" -jsonrpsee-types = "0.2.0-alpha.2" -jsonrpsee-ws-client = "0.2.0-alpha.2" +jsonrpsee-proc-macros = "=0.2.0-alpha.3" +jsonrpsee-types = "=0.2.0-alpha.3" +jsonrpsee-ws-client = "=0.2.0-alpha.3" log = "0.4.11" num-traits = "0.2" rand = "0.7" diff --git a/bridges/relays/client-substrate/src/client.rs b/bridges/relays/client-substrate/src/client.rs index a149ba69701f6..34763e9979eaf 100644 --- a/bridges/relays/client-substrate/src/client.rs +++ b/bridges/relays/client-substrate/src/client.rs @@ -50,7 +50,7 @@ pub struct Client { /// Client connection params. params: ConnectionParams, /// Substrate RPC client. - client: RpcClient, + client: Arc, /// Genesis block hash. genesis_hash: C::Hash, /// If several tasks are submitting their transactions simultaneously using `submit_signed_extrinsic` @@ -84,7 +84,7 @@ impl Client { let client = Self::build_client(params.clone()).await?; let number: C::BlockNumber = Zero::zero(); - let genesis_hash = Substrate::::chain_get_block_hash(&client, number).await?; + let genesis_hash = Substrate::::chain_get_block_hash(&*client, number).await?; Ok(Self { params, @@ -101,7 +101,7 @@ impl Client { } /// Build client to use in connection. - async fn build_client(params: ConnectionParams) -> Result { + async fn build_client(params: ConnectionParams) -> Result> { let uri = format!( "{}://{}:{}", if params.secure { "wss" } else { "ws" }, @@ -111,14 +111,15 @@ impl Client { let mut config = RpcConfig::with_url(&uri); config.max_notifs_per_subscription = MAX_SUBSCRIPTION_CAPACITY; let client = RpcClient::new(config).await?; - Ok(client) + + Ok(Arc::new(client)) } } impl Client { /// Returns true if client is connected to at least one peer and is in synced state. pub async fn ensure_synced(&self) -> Result<()> { - let health = Substrate::::system_health(&self.client).await?; + let health = Substrate::::system_health(&*self.client).await?; let is_synced = !health.is_syncing && (!health.should_have_peers || health.peers > 0); if is_synced { Ok(()) @@ -134,7 +135,7 @@ impl Client { /// Return hash of the best finalized block. pub async fn best_finalized_header_hash(&self) -> Result { - Ok(Substrate::::chain_get_finalized_head(&self.client).await?) + Ok(Substrate::::chain_get_finalized_head(&*self.client).await?) } /// Returns the best Substrate header. @@ -142,12 +143,12 @@ impl Client { where C::Header: DeserializeOwned, { - Ok(Substrate::::chain_get_header(&self.client, None).await?) + Ok(Substrate::::chain_get_header(&*self.client, None).await?) } /// Get a Substrate block from its hash. pub async fn get_block(&self, block_hash: Option) -> Result { - Ok(Substrate::::chain_get_block(&self.client, block_hash).await?) + Ok(Substrate::::chain_get_block(&*self.client, block_hash).await?) } /// Get a Substrate header by its hash. @@ -155,12 +156,12 @@ impl Client { where C::Header: DeserializeOwned, { - Ok(Substrate::::chain_get_header(&self.client, block_hash).await?) + Ok(Substrate::::chain_get_header(&*self.client, block_hash).await?) } /// Get a Substrate block hash by its number. pub async fn block_hash_by_number(&self, number: C::BlockNumber) -> Result { - Ok(Substrate::::chain_get_block_hash(&self.client, number).await?) + Ok(Substrate::::chain_get_block_hash(&*self.client, number).await?) } /// Get a Substrate header by its number. @@ -174,12 +175,12 @@ impl Client { /// Return runtime version. pub async fn runtime_version(&self) -> Result { - Ok(Substrate::::runtime_version(&self.client).await?) + Ok(Substrate::::runtime_version(&*self.client).await?) } /// Read value from runtime storage. pub async fn storage_value(&self, storage_key: StorageKey) -> Result> { - Substrate::::get_storage(&self.client, storage_key) + Substrate::::get_storage(&*self.client, storage_key) .await? .map(|encoded_value| T::decode(&mut &encoded_value.0[..]).map_err(Error::ResponseParseFailed)) .transpose() @@ -191,7 +192,7 @@ impl Client { C: ChainWithBalances, { let storage_key = C::account_info_storage_key(&account); - let encoded_account_data = Substrate::::get_storage(&self.client, storage_key) + let encoded_account_data = Substrate::::get_storage(&*self.client, storage_key) .await? .ok_or(Error::AccountDoesNotExist)?; let decoded_account_data = @@ -204,14 +205,14 @@ impl Client { /// /// Note: It's the caller's responsibility to make sure `account` is a valid ss58 address. pub async fn next_account_index(&self, account: C::AccountId) -> Result { - Ok(Substrate::::system_account_next_index(&self.client, account).await?) + Ok(Substrate::::system_account_next_index(&*self.client, account).await?) } /// Submit unsigned extrinsic for inclusion in a block. /// /// Note: The given transaction needs to be SCALE encoded beforehand. pub async fn submit_unsigned_extrinsic(&self, transaction: Bytes) -> Result { - let tx_hash = Substrate::::author_submit_extrinsic(&self.client, transaction).await?; + let tx_hash = Substrate::::author_submit_extrinsic(&*self.client, transaction).await?; log::trace!(target: "bridge", "Sent transaction to Substrate node: {:?}", tx_hash); Ok(tx_hash) } @@ -231,7 +232,7 @@ impl Client { let _guard = self.submit_signed_extrinsic_lock.lock().await; let transaction_nonce = self.next_account_index(extrinsic_signer).await?; let extrinsic = prepare_extrinsic(transaction_nonce); - let tx_hash = Substrate::::author_submit_extrinsic(&self.client, extrinsic).await?; + let tx_hash = Substrate::::author_submit_extrinsic(&*self.client, extrinsic).await?; log::trace!(target: "bridge", "Sent transaction to {} node: {:?}", C::NAME, tx_hash); Ok(tx_hash) } @@ -241,7 +242,7 @@ impl Client { let call = SUB_API_GRANDPA_AUTHORITIES.to_string(); let data = Bytes(Vec::new()); - let encoded_response = Substrate::::state_call(&self.client, call, data, Some(block)).await?; + let encoded_response = Substrate::::state_call(&*self.client, call, data, Some(block)).await?; let authority_list = encoded_response.0; Ok(authority_list) @@ -249,7 +250,7 @@ impl Client { /// Execute runtime call at given block. pub async fn state_call(&self, method: String, data: Bytes, at_block: Option) -> Result { - Substrate::::state_call(&self.client, method, data, at_block) + Substrate::::state_call(&*self.client, method, data, at_block) .await .map_err(Into::into) } @@ -264,7 +265,7 @@ impl Client { at_block: C::Hash, ) -> Result { let encoded_trie_nodes = SubstrateMessages::::prove_messages( - &self.client, + &*self.client, instance, lane, *range.start(), @@ -287,7 +288,7 @@ impl Client { at_block: C::Hash, ) -> Result>> { let encoded_trie_nodes = - SubstrateMessages::::prove_messages_delivery(&self.client, instance, lane, Some(at_block)) + SubstrateMessages::::prove_messages_delivery(&*self.client, instance, lane, Some(at_block)) .await .map_err(Error::RpcError)?; let decoded_trie_nodes: Vec> =