Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Companion for #13923 (#7111)
Browse files Browse the repository at this point in the history
* make staking miner compatible with new OnlineConfig

* remove dead code
  • Loading branch information
liamaharon authored Apr 21, 2023
1 parent d2a41b3 commit fc95bc6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions utils/staking-miner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -314,7 +314,7 @@ where
pallets.extend(additional);
Builder::<B>::new()
.mode(Mode::Online(OnlineConfig {
transport: client.into_inner().into(),
transport: Transport::Uri(client.uri().to_owned()),
at,
pallets,
hashed_prefixes: vec![<frame_system::BlockHash<T>>::prefix_hash()],
Expand Down
12 changes: 7 additions & 5 deletions utils/staking-miner/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WsClient>);
pub(crate) struct SharedRpcClient(Arc<WsClient>, Uri);

impl Deref for SharedRpcClient {
type Target = WsClient;
Expand All @@ -116,9 +118,9 @@ impl Deref for SharedRpcClient {
}

impl SharedRpcClient {
/// Consume and extract the inner client.
pub fn into_inner(self) -> Arc<WsClient> {
self.0
/// Get the URI of the client.
pub fn uri(&self) -> &str {
&self.1
}

/// Create a new shared JSON-RPC web-socket client.
Expand All @@ -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`.
Expand Down

0 comments on commit fc95bc6

Please sign in to comment.