From 1524089fe1b1eac78cce03f927eaadcb6dacffa7 Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Thu, 20 Apr 2023 14:42:27 +0400 Subject: [PATCH 1/2] make staking miner compatible with new OnlineConfig --- utils/staking-miner/src/main.rs | 4 ++-- utils/staking-miner/src/rpc.rs | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/utils/staking-miner/src/main.rs b/utils/staking-miner/src/main.rs index 044ba4ed22df..1ba42b21d91c 100644 --- a/utils/staking-miner/src/main.rs +++ b/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/utils/staking-miner/src/rpc.rs b/utils/staking-miner/src/rpc.rs index ae978ee3382d..11088fbf5a74 100644 --- a/utils/staking-miner/src/rpc.rs +++ b/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; @@ -117,10 +119,16 @@ impl Deref for SharedRpcClient { impl SharedRpcClient { /// Consume and extract the inner client. + #[allow(dead_code)] 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. pub(crate) async fn new( uri: &str, @@ -134,7 +142,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`. From 331e48562298f4d6d0e629d25bfff7c6a2015e93 Mon Sep 17 00:00:00 2001 From: Liam Aharon Date: Thu, 20 Apr 2023 15:06:22 +0400 Subject: [PATCH 2/2] remove dead code --- utils/staking-miner/src/rpc.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/utils/staking-miner/src/rpc.rs b/utils/staking-miner/src/rpc.rs index 11088fbf5a74..a95e89191a49 100644 --- a/utils/staking-miner/src/rpc.rs +++ b/utils/staking-miner/src/rpc.rs @@ -118,12 +118,6 @@ impl Deref for SharedRpcClient { } impl SharedRpcClient { - /// Consume and extract the inner client. - #[allow(dead_code)] - pub fn into_inner(self) -> Arc { - self.0 - } - /// Get the URI of the client. pub fn uri(&self) -> &str { &self.1