Skip to content

Commit

Permalink
remove retry / create client lazyly
Browse files Browse the repository at this point in the history
  • Loading branch information
pgherveou committed Oct 23, 2023
1 parent 5e73665 commit 0480e10
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 23 deletions.
2 changes: 1 addition & 1 deletion crates/examples/examples/simple_network_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let network = orchestrator.spawn(config).await?;
println!("🚀🚀🚀🚀 network deployed");

let client = network.get_node("alice")?.client();
let client = network.get_node("alice")?.client().await?;
let mut blocks = client.blocks().subscribe_finalized().await?.take(3);

while let Some(block) = blocks.next().await {
Expand Down
14 changes: 4 additions & 10 deletions crates/orchestrator/src/network/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ pub struct NetworkNode {
pub(crate) spec: NodeSpec,
pub(crate) name: String,
pub(crate) ws_uri: String,
rpc: RpcClient,
client: OnlineClient<PolkadotConfig>,
pub(crate) prometheus_uri: String,
metrics_cache: Arc<RwLock<MetricMap>>,
}
Expand All @@ -27,17 +25,13 @@ impl NetworkNode {
pub(crate) fn new<T: Into<String>>(
name: T,
ws_uri: T,
rpc: RpcClient,
client: OnlineClient<PolkadotConfig>,
prometheus_uri: T,
spec: NodeSpec,
inner: DynNode,
) -> Self {
Self {
name: name.into(),
ws_uri: ws_uri.into(),
rpc,
client,
prometheus_uri: prometheus_uri.into(),
inner,
spec,
Expand All @@ -52,12 +46,12 @@ impl NetworkNode {
Ok(())
}

pub fn rpc(&self) -> RpcClient {
self.rpc.clone()
pub async fn rpc(&self) -> Result<RpcClient, subxt::Error> {
RpcClient::from_url(&self.ws_uri).await
}

pub fn client(&self) -> OnlineClient<PolkadotConfig> {
self.client.clone()
pub async fn client(&self) -> Result<OnlineClient<PolkadotConfig>, subxt::Error> {
OnlineClient::from_url(&self.ws_uri).await
}

/// Resume the node, this is implemented by resuming the
Expand Down
12 changes: 0 additions & 12 deletions crates/orchestrator/src/spawner.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use std::path::PathBuf;

use anyhow::Context;
use futures::Future;
use provider::{
constants::LOCALHOST,
types::{SpawnNodeOptions, TransferedFile},
DynNamespace,
};
use subxt::{backend::rpc::RpcClient, OnlineClient};
use support::fs::FileSystem;

use crate::{
Expand Down Expand Up @@ -163,19 +161,9 @@ where
println!("📓 logs cmd: tail -f {}/{}.log", base_dir, node.name);
println!("\n");

let client = retry(5, || async { OnlineClient::from_url(&ws_uri).await })
.await
.context(format!("Failed to connect to node rpc at {ws_uri}"))?;

let rpc = RpcClient::from_url(&ws_uri)
.await
.context(format!("Failed to connect to rpc client at {ws_uri}"))?;

Ok(NetworkNode::new(
node.name.clone(),
ws_uri,
rpc,
client,
prometheus_uri,
node.clone(),
running_node,
Expand Down

0 comments on commit 0480e10

Please sign in to comment.