From 420653bcb65ac06dd36381a9d3d1bf961e8cb0cc Mon Sep 17 00:00:00 2001 From: Noor Date: Mon, 16 Jun 2025 13:53:00 +0530 Subject: [PATCH] Improves brain URL selection for different networks list of 3 brain urls for staging and testnet refactor brain URL selection for staging and testnet environments. --- src/config.rs | 18 ++++++++++++------ src/constants.rs | 11 +++++++++++ src/snp/grpc.rs | 1 + 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/config.rs b/src/config.rs index 0495f5f..eedd637 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,3 +1,4 @@ +use crate::constants::{STAGING_BRAIN_URLS, TESTNET_BRAIN_URLS}; use crate::{general, utils::block_on}; use ed25519_dalek::SigningKey; use log::{debug, info, warn}; @@ -5,6 +6,7 @@ use openssl::bn::BigNum; use openssl::hash::{Hasher, MessageDigest}; use openssl::pkey::{PKey, Private}; use openssl::rsa::Rsa; +use rand::Rng; use serde::{Deserialize, Serialize}; use std::{fs::File, io::Write, path::Path}; @@ -309,15 +311,19 @@ impl Config { pub fn get_brain_info() -> (String, String) { match Self::init_config().network.as_str() { + "localhost" => ("https://localhost:31337".to_string(), "staging-brain".to_string()), "staging" => { - let url1 = "https://149.22.95.1:47855".to_string(); // staging brain 2 - let url2 = "https://149.36.48.99:48843".to_string(); // staging brain 3 - - let url = if rand::random::() { url1 } else { url2 }; + let url = STAGING_BRAIN_URLS + [rand::thread_rng().gen_range(0..STAGING_BRAIN_URLS.len())] + .to_string(); (url, "staging-brain".to_string()) } - "localhost" => ("https://localhost:31337".to_string(), "staging-brain".to_string()), - _ => ("https://173.234.17.2:39477".to_string(), "testnet-brain".to_string()), + _ => { + let url = TESTNET_BRAIN_URLS + [rand::thread_rng().gen_range(0..TESTNET_BRAIN_URLS.len())] + .to_string(); + (url, "testnet-brain".to_string()) + } } } diff --git a/src/constants.rs b/src/constants.rs index dd466f0..ff3da5d 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -1,2 +1,13 @@ pub const HRATLS_APP_PORT: u32 = 34500; pub const MAX_REDIRECTS: u16 = 3; +pub const STAGING_BRAIN_URLS: [&str; 3] = [ + "https://184.107.169.199:49092", // staging brain 1 + "https://149.22.95.1:47855", // staging brain 2 + "https://149.36.48.99:48843", // staging brain 3 +]; + +pub const TESTNET_BRAIN_URLS: [&str; 3] = [ + "https://184.107.169.199:45223", // testnet brain 1 + "https://149.22.95.1:44522", // testnet brain 2 + "https://149.36.48.99:48638", // testnet brain 3 +]; diff --git a/src/snp/grpc.rs b/src/snp/grpc.rs index 10fd953..34b1cba 100644 --- a/src/snp/grpc.rs +++ b/src/snp/grpc.rs @@ -91,6 +91,7 @@ impl crate::HumanOutput for VmNodeListResp { async fn client() -> Result, Error> { let default_brain_url = Config::get_brain_info().0; + info!("brain_url: {default_brain_url}"); Ok(BrainVmCliClient::new(Config::connect_brain_channel(default_brain_url).await?)) }