From ac09a84115982fe3de094343c9ce4b80e66d2ab8 Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Fri, 21 Apr 2023 18:47:12 +1000 Subject: [PATCH] Companion for #13923 (#7111) * make staking miner compatible with new OnlineConfig * remove dead code --- polkadot/utils/staking-miner/src/main.rs | 4 ++-- polkadot/utils/staking-miner/src/rpc.rs | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/polkadot/utils/staking-miner/src/main.rs b/polkadot/utils/staking-miner/src/main.rs index 044ba4ed22..1ba42b21d9 100644 --- a/polkadot/utils/staking-miner/src/main.rs +++ b/polkadot/utils/staking-miner/src/main.rs @@ -50,7 +50,7 @@ use frame_election_provider_support::NposSolver; use frame_support::traits::Get; use futures_util::StreamExt; use jsonrpsee::ws_client::{WsClient, WsClientBuilder}; -use remote_externalities::{Builder, Mode, OnlineConfig}; +use remote_externalities::{Builder, Mode, OnlineConfig, Transport}; use rpc::{RpcApiClient, SharedRpcClient}; use runtime_versions::RuntimeVersions; use signal_hook::consts::signal::*; @@ -314,7 +314,7 @@ where pallets.extend(additional); Builder::::new() .mode(Mode::Online(OnlineConfig { - transport: client.into_inner().into(), + transport: Transport::Uri(client.uri().to_owned()), at, pallets, hashed_prefixes: vec![>::prefix_hash()], diff --git a/polkadot/utils/staking-miner/src/rpc.rs b/polkadot/utils/staking-miner/src/rpc.rs index ae978ee338..a95e89191a 100644 --- a/polkadot/utils/staking-miner/src/rpc.rs +++ b/polkadot/utils/staking-miner/src/rpc.rs @@ -103,9 +103,11 @@ pub trait RpcApi { fn subscribe_finalized_heads(&self); } +type Uri = String; + /// Wraps a shared web-socket JSON-RPC client that can be cloned. #[derive(Clone, Debug)] -pub(crate) struct SharedRpcClient(Arc); +pub(crate) struct SharedRpcClient(Arc, Uri); impl Deref for SharedRpcClient { type Target = WsClient; @@ -116,9 +118,9 @@ impl Deref for SharedRpcClient { } impl SharedRpcClient { - /// Consume and extract the inner client. - pub fn into_inner(self) -> Arc { - self.0 + /// Get the URI of the client. + pub fn uri(&self) -> &str { + &self.1 } /// Create a new shared JSON-RPC web-socket client. @@ -134,7 +136,7 @@ impl SharedRpcClient { .max_concurrent_requests(u32::MAX as usize) .build(uri) .await?; - Ok(Self(Arc::new(client))) + Ok(Self(Arc::new(client), uri.to_owned())) } /// Get a storage item and decode it as `T`.