Improves brain connection reliability

Updates the brain connection logic to randomly select from a list of available URLs for staging and testnet environments.
This commit is contained in:
Noor 2025-06-16 10:57:02 +03:00 committed by ghe0
parent 217ab03164
commit d6a8f14124
Signed by: ghe0
GPG Key ID: 451028EE56A0FBB4
3 changed files with 23 additions and 8 deletions

@ -4,12 +4,19 @@ use anyhow::Result;
use ed25519_dalek::SigningKey;
use lazy_static::lazy_static;
use log::{info, warn};
use rand::Rng;
use sha2::{Digest, Sha256};
use std::{fs::File, io::Read, io::Write};
use std::{
fs::File,
io::{Read, Write},
sync::LazyLock,
};
pub(crate) const DETEE_ROOT_CA: &str = "/etc/detee/root_ca.pem";
pub(crate) const BRAIN_STAGING: (&str, &str) = ("https://184.107.169.199:49092", "staging-brain");
pub(crate) const BRAIN_TESTING: (&str, &str) = ("https://164.92.249.180:31337", "testnet-brain");
pub(crate) const BRAIN_STAGING_URLS: [&str; 3] =
["https://184.107.169.199:49092", "https://149.22.95.1:47855", "https://149.36.48.99:48843"];
pub(crate) const BRAIN_TESTING_URLS: [&str; 3] =
["https://184.107.169.199:45223", "https://149.22.95.1:44522", "https://149.36.48.99:48638"];
pub(crate) const VM_BOOT_DIR: &str = "/var/lib/detee/boot/";
pub(crate) const USED_RESOURCES: &str = "/etc/detee/daemon/used_resources.yaml";
pub(crate) const VM_CONFIG_DIR: &str = "/etc/detee/daemon/vms/";
@ -24,6 +31,14 @@ pub(crate) const OVMF_HASH: &str =
pub(crate) const OVMF_URL: &str =
"https://drive.google.com/uc?export=download&id=1V-vLkaiLaGmFSjrN84Z6nELQOxKNAoSJ";
pub static BRAIN_STAGING: LazyLock<(&str, &str)> = LazyLock::new(|| {
(BRAIN_STAGING_URLS[rand::thread_rng().gen_range(0..BRAIN_STAGING_URLS.len())], "staging-brain")
});
pub static BRAIN_TESTING: LazyLock<(&str, &str)> = LazyLock::new(|| {
(BRAIN_TESTING_URLS[rand::thread_rng().gen_range(0..BRAIN_TESTING_URLS.len())], "testnet-brain")
});
lazy_static! {
pub static ref PUBLIC_KEY: String = get_public_key();
pub static ref IP_INFO: IPInfo = get_ip_info().unwrap();

@ -18,14 +18,16 @@ pub mod snp_proto {
async fn client(network: &str) -> Result<BrainVmDaemonClient<Channel>> {
let (brain_url, brain_san) = match network {
"staging" => BRAIN_STAGING,
"testnet" => BRAIN_TESTING,
"staging" => *BRAIN_STAGING,
"testnet" => *BRAIN_TESTING,
_ => {
return Err(anyhow::anyhow!(
"The only networks currently supported are staging and testnet."
))
}
};
info!("brain_url: {brain_url}, brain_san: {brain_san}");
let pem = std::fs::read_to_string(DETEE_ROOT_CA)?;
let ca = Certificate::from_pem(pem);

@ -253,9 +253,7 @@ async fn main() {
info!("Registering with the brain and getting back deleted VMs.");
match grpc::register_node(&vm_handler.config).await {
Ok(deleted_vms) => {
vm_handler.clear_deleted_contracts(deleted_vms)
}
Ok(deleted_vms) => vm_handler.clear_deleted_contracts(deleted_vms),
Err(e) => log::error!("Could not get contracts from brain: {e:?}"),
};