Skip to content

Commit

Permalink
Bump jsonrpsee to Alpha.3 (paritytech#892)
Browse files Browse the repository at this point in the history
* Bump `jsonrpsee` to `alpha.3`

* Arc-ify `WsClient`
  • Loading branch information
HCastano committed Apr 12, 2021
1 parent d665b53 commit 1610f86
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 33 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions relays/client-ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
6 changes: 3 additions & 3 deletions relays/client-substrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
41 changes: 21 additions & 20 deletions relays/client-substrate/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub struct Client<C: Chain> {
/// Client connection params.
params: ConnectionParams,
/// Substrate RPC client.
client: RpcClient,
client: Arc<RpcClient>,
/// Genesis block hash.
genesis_hash: C::Hash,
/// If several tasks are submitting their transactions simultaneously using `submit_signed_extrinsic`
Expand Down Expand Up @@ -84,7 +84,7 @@ impl<C: Chain> Client<C> {
let client = Self::build_client(params.clone()).await?;

let number: C::BlockNumber = Zero::zero();
let genesis_hash = Substrate::<C>::chain_get_block_hash(&client, number).await?;
let genesis_hash = Substrate::<C>::chain_get_block_hash(&*client, number).await?;

Ok(Self {
params,
Expand All @@ -101,7 +101,7 @@ impl<C: Chain> Client<C> {
}

/// Build client to use in connection.
async fn build_client(params: ConnectionParams) -> Result<RpcClient> {
async fn build_client(params: ConnectionParams) -> Result<Arc<RpcClient>> {
let uri = format!(
"{}://{}:{}",
if params.secure { "wss" } else { "ws" },
Expand All @@ -111,14 +111,15 @@ impl<C: Chain> Client<C> {
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<C: Chain> Client<C> {
/// 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::<C>::system_health(&self.client).await?;
let health = Substrate::<C>::system_health(&*self.client).await?;
let is_synced = !health.is_syncing && (!health.should_have_peers || health.peers > 0);
if is_synced {
Ok(())
Expand All @@ -134,33 +135,33 @@ impl<C: Chain> Client<C> {

/// Return hash of the best finalized block.
pub async fn best_finalized_header_hash(&self) -> Result<C::Hash> {
Ok(Substrate::<C>::chain_get_finalized_head(&self.client).await?)
Ok(Substrate::<C>::chain_get_finalized_head(&*self.client).await?)
}

/// Returns the best Substrate header.
pub async fn best_header(&self) -> Result<C::Header>
where
C::Header: DeserializeOwned,
{
Ok(Substrate::<C>::chain_get_header(&self.client, None).await?)
Ok(Substrate::<C>::chain_get_header(&*self.client, None).await?)
}

/// Get a Substrate block from its hash.
pub async fn get_block(&self, block_hash: Option<C::Hash>) -> Result<C::SignedBlock> {
Ok(Substrate::<C>::chain_get_block(&self.client, block_hash).await?)
Ok(Substrate::<C>::chain_get_block(&*self.client, block_hash).await?)
}

/// Get a Substrate header by its hash.
pub async fn header_by_hash(&self, block_hash: C::Hash) -> Result<C::Header>
where
C::Header: DeserializeOwned,
{
Ok(Substrate::<C>::chain_get_header(&self.client, block_hash).await?)
Ok(Substrate::<C>::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<C::Hash> {
Ok(Substrate::<C>::chain_get_block_hash(&self.client, number).await?)
Ok(Substrate::<C>::chain_get_block_hash(&*self.client, number).await?)
}

/// Get a Substrate header by its number.
Expand All @@ -174,12 +175,12 @@ impl<C: Chain> Client<C> {

/// Return runtime version.
pub async fn runtime_version(&self) -> Result<RuntimeVersion> {
Ok(Substrate::<C>::runtime_version(&self.client).await?)
Ok(Substrate::<C>::runtime_version(&*self.client).await?)
}

/// Read value from runtime storage.
pub async fn storage_value<T: Decode>(&self, storage_key: StorageKey) -> Result<Option<T>> {
Substrate::<C>::get_storage(&self.client, storage_key)
Substrate::<C>::get_storage(&*self.client, storage_key)
.await?
.map(|encoded_value| T::decode(&mut &encoded_value.0[..]).map_err(Error::ResponseParseFailed))
.transpose()
Expand All @@ -191,7 +192,7 @@ impl<C: Chain> Client<C> {
C: ChainWithBalances,
{
let storage_key = C::account_info_storage_key(&account);
let encoded_account_data = Substrate::<C>::get_storage(&self.client, storage_key)
let encoded_account_data = Substrate::<C>::get_storage(&*self.client, storage_key)
.await?
.ok_or(Error::AccountDoesNotExist)?;
let decoded_account_data =
Expand All @@ -204,14 +205,14 @@ impl<C: Chain> Client<C> {
///
/// 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<C::Index> {
Ok(Substrate::<C>::system_account_next_index(&self.client, account).await?)
Ok(Substrate::<C>::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<C::Hash> {
let tx_hash = Substrate::<C>::author_submit_extrinsic(&self.client, transaction).await?;
let tx_hash = Substrate::<C>::author_submit_extrinsic(&*self.client, transaction).await?;
log::trace!(target: "bridge", "Sent transaction to Substrate node: {:?}", tx_hash);
Ok(tx_hash)
}
Expand All @@ -231,7 +232,7 @@ impl<C: Chain> Client<C> {
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::<C>::author_submit_extrinsic(&self.client, extrinsic).await?;
let tx_hash = Substrate::<C>::author_submit_extrinsic(&*self.client, extrinsic).await?;
log::trace!(target: "bridge", "Sent transaction to {} node: {:?}", C::NAME, tx_hash);
Ok(tx_hash)
}
Expand All @@ -241,15 +242,15 @@ impl<C: Chain> Client<C> {
let call = SUB_API_GRANDPA_AUTHORITIES.to_string();
let data = Bytes(Vec::new());

let encoded_response = Substrate::<C>::state_call(&self.client, call, data, Some(block)).await?;
let encoded_response = Substrate::<C>::state_call(&*self.client, call, data, Some(block)).await?;
let authority_list = encoded_response.0;

Ok(authority_list)
}

/// Execute runtime call at given block.
pub async fn state_call(&self, method: String, data: Bytes, at_block: Option<C::Hash>) -> Result<Bytes> {
Substrate::<C>::state_call(&self.client, method, data, at_block)
Substrate::<C>::state_call(&*self.client, method, data, at_block)
.await
.map_err(Into::into)
}
Expand All @@ -264,7 +265,7 @@ impl<C: Chain> Client<C> {
at_block: C::Hash,
) -> Result<StorageProof> {
let encoded_trie_nodes = SubstrateMessages::<C>::prove_messages(
&self.client,
&*self.client,
instance,
lane,
*range.start(),
Expand All @@ -287,7 +288,7 @@ impl<C: Chain> Client<C> {
at_block: C::Hash,
) -> Result<Vec<Vec<u8>>> {
let encoded_trie_nodes =
SubstrateMessages::<C>::prove_messages_delivery(&self.client, instance, lane, Some(at_block))
SubstrateMessages::<C>::prove_messages_delivery(&*self.client, instance, lane, Some(at_block))
.await
.map_err(Error::RpcError)?;
let decoded_trie_nodes: Vec<Vec<u8>> =
Expand Down

0 comments on commit 1610f86

Please sign in to comment.