Compare commits
	
		
			2 Commits
		
	
	
		
			ddc5d24857
			...
			25eeab6098
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 25eeab6098 | |||
| 420653bcb6 | 
							
								
								
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							| @ -1182,7 +1182,7 @@ dependencies = [ | |||||||
| [[package]] | [[package]] | ||||||
| name = "detee-shared" | name = "detee-shared" | ||||||
| version = "0.1.0" | version = "0.1.0" | ||||||
| source = "git+ssh://git@gitea.detee.cloud/testnet/proto.git?branch=surreal_brain#fb38352e1b47837b14f32d8df5ae7f6b17202aae" | source = "git+ssh://git@gitea.detee.cloud/testnet/proto.git?branch=surreal_brain_app#0b195b4589e4ec689af7ddca27dc051716ecee78" | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  "bincode", |  "bincode", | ||||||
|  "prost", |  "prost", | ||||||
|  | |||||||
| @ -34,7 +34,7 @@ tokio-retry = "0.3.0" | |||||||
| detee-sgx = { git = "ssh://git@gitea.detee.cloud/testnet/detee-sgx.git", branch = "hratls", features=["hratls", "qvl"] } | detee-sgx = { git = "ssh://git@gitea.detee.cloud/testnet/detee-sgx.git", branch = "hratls", features=["hratls", "qvl"] } | ||||||
| shadow-rs = { version = "1.1.1", features = ["metadata"] } | shadow-rs = { version = "1.1.1", features = ["metadata"] } | ||||||
| 
 | 
 | ||||||
| detee-shared = { git = "ssh://git@gitea.detee.cloud/testnet/proto.git", branch = "surreal_brain" } | detee-shared = { git = "ssh://git@gitea.detee.cloud/testnet/proto.git", branch = "surreal_brain_app" } | ||||||
| # detee-shared = { path = "../detee-shared" } | # detee-shared = { path = "../detee-shared" } | ||||||
| 
 | 
 | ||||||
| [build-dependencies] | [build-dependencies] | ||||||
|  | |||||||
| @ -127,9 +127,9 @@ fn clap_cmd() -> Command { | |||||||
|                     .arg( |                     .arg( | ||||||
|                         Arg::new("disk") |                         Arg::new("disk") | ||||||
|                         .long("disk") |                         .long("disk") | ||||||
|                         .default_value("1000") |                         .default_value("2") | ||||||
|                         .value_parser(clap::value_parser!(u32).range(300..8000)) |                         .value_parser(clap::value_parser!(u32).range(1..100)) | ||||||
|                         .help("disk size in MB") |                         .help("disk size in GB") | ||||||
|                     ) |                     ) | ||||||
|                     .arg( |                     .arg( | ||||||
|                         Arg::new("port") |                         Arg::new("port") | ||||||
|  | |||||||
| @ -1,3 +1,4 @@ | |||||||
|  | use crate::constants::{STAGING_BRAIN_URLS, TESTNET_BRAIN_URLS}; | ||||||
| use crate::{general, utils::block_on}; | use crate::{general, utils::block_on}; | ||||||
| use ed25519_dalek::SigningKey; | use ed25519_dalek::SigningKey; | ||||||
| use log::{debug, info, warn}; | use log::{debug, info, warn}; | ||||||
| @ -5,6 +6,7 @@ use openssl::bn::BigNum; | |||||||
| use openssl::hash::{Hasher, MessageDigest}; | use openssl::hash::{Hasher, MessageDigest}; | ||||||
| use openssl::pkey::{PKey, Private}; | use openssl::pkey::{PKey, Private}; | ||||||
| use openssl::rsa::Rsa; | use openssl::rsa::Rsa; | ||||||
|  | use rand::Rng; | ||||||
| use serde::{Deserialize, Serialize}; | use serde::{Deserialize, Serialize}; | ||||||
| use std::{fs::File, io::Write, path::Path}; | use std::{fs::File, io::Write, path::Path}; | ||||||
| 
 | 
 | ||||||
| @ -309,15 +311,19 @@ impl Config { | |||||||
| 
 | 
 | ||||||
|     pub fn get_brain_info() -> (String, String) { |     pub fn get_brain_info() -> (String, String) { | ||||||
|         match Self::init_config().network.as_str() { |         match Self::init_config().network.as_str() { | ||||||
|  |             "localhost" => ("https://localhost:31337".to_string(), "staging-brain".to_string()), | ||||||
|             "staging" => { |             "staging" => { | ||||||
|                 let url1 = "https://149.22.95.1:47855".to_string(); // staging brain 2
 |                 let url = STAGING_BRAIN_URLS | ||||||
|                 let url2 = "https://149.36.48.99:48843".to_string(); // staging brain 3
 |                     [rand::thread_rng().gen_range(0..STAGING_BRAIN_URLS.len())] | ||||||
| 
 |                 .to_string(); | ||||||
|                 let url = if rand::random::<bool>() { url1 } else { url2 }; |  | ||||||
|                 (url, "staging-brain".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()) | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,2 +1,13 @@ | |||||||
| pub const HRATLS_APP_PORT: u32 = 34500; | pub const HRATLS_APP_PORT: u32 = 34500; | ||||||
| pub const MAX_REDIRECTS: u16 = 3; | 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
 | ||||||
|  | ]; | ||||||
|  | |||||||
| @ -80,9 +80,9 @@ fn handle_deploy( | |||||||
|         // TODO: maybe add launch config on deploy command with --launch-config flag
 |         // TODO: maybe add launch config on deploy command with --launch-config flag
 | ||||||
|         (AppDeployConfig::from_path(file_path).unwrap(), None) |         (AppDeployConfig::from_path(file_path).unwrap(), None) | ||||||
|     } else { |     } else { | ||||||
|         let vcpu = *deploy_match.get_one::<u32>("vcpus").unwrap(); |         let vcpus = *deploy_match.get_one::<u32>("vcpus").unwrap(); | ||||||
|         let memory_mb = *deploy_match.get_one::<u32>("memory").unwrap(); |         let memory_mb = *deploy_match.get_one::<u32>("memory").unwrap(); | ||||||
|         let disk_mb = *deploy_match.get_one::<u32>("disk").unwrap(); |         let disk_size_gb = *deploy_match.get_one::<u32>("disk").unwrap(); | ||||||
|         let port = |         let port = | ||||||
|             deploy_match.get_many::<u32>("port").unwrap_or_default().cloned().collect::<Vec<_>>(); |             deploy_match.get_many::<u32>("port").unwrap_or_default().cloned().collect::<Vec<_>>(); | ||||||
|         let package_name = deploy_match.get_one::<String>("package").unwrap().clone(); |         let package_name = deploy_match.get_one::<String>("package").unwrap().clone(); | ||||||
| @ -98,7 +98,7 @@ fn handle_deploy( | |||||||
| 
 | 
 | ||||||
|         let private_package = false; |         let private_package = false; | ||||||
| 
 | 
 | ||||||
|         let resource = Resource { vcpu, memory_mb, disk_mb, port }; |         let resource = Resource { vcpus, memory_mb, disk_size_gb, port }; | ||||||
|         let node_pubkey = match block_on(get_app_node(resource.clone(), location.into())) { |         let node_pubkey = match block_on(get_app_node(resource.clone(), location.into())) { | ||||||
|             Ok(node) => node.node_pubkey, |             Ok(node) => node.node_pubkey, | ||||||
|             Err(e) => { |             Err(e) => { | ||||||
|  | |||||||
| @ -48,7 +48,7 @@ impl crate::HumanOutput for AppContract { | |||||||
|             .mapped_ports |             .mapped_ports | ||||||
|             .clone() |             .clone() | ||||||
|             .iter() |             .iter() | ||||||
|             .map(|p| format!("({},{})", p.host_port, p.app_port)) |             .map(|p| format!("({},{})", p.host_port, p.guest_port)) | ||||||
|             .collect::<Vec<_>>() |             .collect::<Vec<_>>() | ||||||
|             .join(", "); |             .join(", "); | ||||||
|         println!( |         println!( | ||||||
| @ -57,8 +57,8 @@ impl crate::HumanOutput for AppContract { | |||||||
|         ); |         ); | ||||||
|         println!("The app has mapped ports by the node are: {mapped_ports}"); |         println!("The app has mapped ports by the node are: {mapped_ports}"); | ||||||
|         println!( |         println!( | ||||||
|             "The App has {} vCPUS, {}MB of memory and a disk of {} MB.", |             "The App has {} vCPUS, {}MB of memory and a disk of {} GB.", | ||||||
|             app_resource.vcpu, app_resource.memory_mb, app_resource.disk_mb |             app_resource.vcpus, app_resource.memory_mb, app_resource.disk_size_gb | ||||||
|         ); |         ); | ||||||
|         println!("You have locked {} nanoLP in the contract, that get collected at a rate of {} nanoLP per minute.", |         println!("You have locked {} nanoLP in the contract, that get collected at a rate of {} nanoLP per minute.", | ||||||
|             self.locked_nano, self.nano_per_minute); |             self.locked_nano, self.nano_per_minute); | ||||||
| @ -75,9 +75,9 @@ pub async fn new_app(app_deploy_config: AppDeployConfig) -> Result<NewAppRes> { | |||||||
|     let mut req: NewAppReq = app_deploy_config.clone().into(); |     let mut req: NewAppReq = app_deploy_config.clone().into(); | ||||||
| 
 | 
 | ||||||
|     let locked_nano = calculate_nanolp_for_app( |     let locked_nano = calculate_nanolp_for_app( | ||||||
|         resource.vcpu, |         resource.vcpus, | ||||||
|         resource.memory_mb, |         resource.memory_mb, | ||||||
|         resource.disk_mb, |         resource.disk_size_gb, | ||||||
|         app_deploy_config.hours, |         app_deploy_config.hours, | ||||||
|         req.price_per_unit, |         req.price_per_unit, | ||||||
|     ); |     ); | ||||||
| @ -87,7 +87,8 @@ pub async fn new_app(app_deploy_config: AppDeployConfig) -> Result<NewAppRes> { | |||||||
|     req.admin_pubkey = Config::get_detee_wallet()?; |     req.admin_pubkey = Config::get_detee_wallet()?; | ||||||
|     req.hratls_pubkey = Config::get_hratls_pubkey_hex()?; |     req.hratls_pubkey = Config::get_hratls_pubkey_hex()?; | ||||||
| 
 | 
 | ||||||
|     let res = client().await?.deploy_app(sign_request(req)?).await?; |     let res = client().await?.new_app(sign_request(req)?).await?; | ||||||
|  | 
 | ||||||
|     Ok(res.into_inner()) |     Ok(res.into_inner()) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -41,11 +41,11 @@ pub struct AppContract { | |||||||
|     pub uuid: String, |     pub uuid: String, | ||||||
|     pub name: String, |     pub name: String, | ||||||
|     #[tabled(rename = "Cores")] |     #[tabled(rename = "Cores")] | ||||||
|     pub vcpu: u32, |     pub vcpus: u32, | ||||||
|     #[tabled(rename = "Mem (MB)")] |     #[tabled(rename = "Mem (MB)")] | ||||||
|     pub memory_mb: u32, |     pub memory_mb: u32, | ||||||
|     #[tabled(rename = "Disk (MB)")] |     #[tabled(rename = "Disk (GB)")] | ||||||
|     pub disk_mb: u32, |     pub disk_size_gb: u32, | ||||||
|     #[tabled(rename = "LP/h")] |     #[tabled(rename = "LP/h")] | ||||||
|     pub cost_h: String, |     pub cost_h: String, | ||||||
|     #[tabled(rename = "time left", display_with = "display_mins")] |     #[tabled(rename = "time left", display_with = "display_mins")] | ||||||
| @ -137,22 +137,22 @@ impl From<AppContractPB> for AppContract { | |||||||
|             } |             } | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|         let AppResource { vcpu, memory_mb, disk_mb, .. } = |         let AppResource { vcpus, memory_mb, disk_size_gb, .. } = | ||||||
|             brain_app_contract.resource.unwrap_or_default(); |             brain_app_contract.resource.unwrap_or_default(); | ||||||
| 
 | 
 | ||||||
|         let exposed_host_ports = brain_app_contract |         let exposed_host_ports = brain_app_contract | ||||||
|             .mapped_ports |             .mapped_ports | ||||||
|             .iter() |             .iter() | ||||||
|             .map(|port| (port.host_port, port.app_port)) |             .map(|port| (port.host_port, port.guest_port)) | ||||||
|             .collect::<Vec<_>>(); |             .collect::<Vec<_>>(); | ||||||
| 
 | 
 | ||||||
|         Self { |         Self { | ||||||
|             location, |             location, | ||||||
|             uuid: brain_app_contract.uuid, |             uuid: brain_app_contract.uuid, | ||||||
|             name: brain_app_contract.app_name, |             name: brain_app_contract.app_name, | ||||||
|             vcpu, |             vcpus, | ||||||
|             memory_mb, |             memory_mb, | ||||||
|             disk_mb, |             disk_size_gb, | ||||||
|             cost_h: format!( |             cost_h: format!( | ||||||
|                 "{:.4}", |                 "{:.4}", | ||||||
|                 (brain_app_contract.nano_per_minute * 60) as f64 / 1_000_000_000.0 |                 (brain_app_contract.nano_per_minute * 60) as f64 / 1_000_000_000.0 | ||||||
| @ -181,7 +181,6 @@ pub async fn get_one_contract(uuid: &str) -> Result<AppContractPB, Error> { | |||||||
| 
 | 
 | ||||||
| #[derive(Debug, Serialize, Deserialize)] | #[derive(Debug, Serialize, Deserialize)] | ||||||
| pub struct AppDeployResponse { | pub struct AppDeployResponse { | ||||||
|     pub status: String, |  | ||||||
|     pub uuid: String, |     pub uuid: String, | ||||||
|     pub name: String, |     pub name: String, | ||||||
|     pub node_ip: String, |     pub node_ip: String, | ||||||
| @ -198,14 +197,13 @@ impl crate::HumanOutput for AppDeployResponse { | |||||||
| impl From<(NewAppRes, String)> for AppDeployResponse { | impl From<(NewAppRes, String)> for AppDeployResponse { | ||||||
|     fn from((value, name): (NewAppRes, String)) -> Self { |     fn from((value, name): (NewAppRes, String)) -> Self { | ||||||
|         Self { |         Self { | ||||||
|             status: value.status, |  | ||||||
|             uuid: value.uuid, |             uuid: value.uuid, | ||||||
|             name, |             name, | ||||||
|             node_ip: value.ip_address, |             node_ip: value.ip_address, | ||||||
|             hratls_port: value |             hratls_port: value | ||||||
|                 .mapped_ports |                 .mapped_ports | ||||||
|                 .iter() |                 .iter() | ||||||
|                 .find(|port| port.app_port == HRATLS_APP_PORT) |                 .find(|port| port.guest_port == HRATLS_APP_PORT) | ||||||
|                 .map(|port| port.host_port) |                 .map(|port| port.host_port) | ||||||
|                 .unwrap_or(HRATLS_APP_PORT), |                 .unwrap_or(HRATLS_APP_PORT), | ||||||
|             error: value.error, |             error: value.error, | ||||||
| @ -230,14 +228,15 @@ pub async fn get_app_node( | |||||||
|     location: snp::deploy::Location, |     location: snp::deploy::Location, | ||||||
| ) -> Result<AppNodeListResp, grpc_brain::Error> { | ) -> Result<AppNodeListResp, grpc_brain::Error> { | ||||||
|     let app_node_filter = AppNodeFilters { |     let app_node_filter = AppNodeFilters { | ||||||
|         vcpus: resource.vcpu, |         vcpus: resource.vcpus, | ||||||
|         memory_mb: resource.memory_mb, |         memory_mb: resource.memory_mb, | ||||||
|         storage_mb: resource.disk_mb, |         storage_gb: resource.disk_size_gb, | ||||||
|         country: location.country.clone().unwrap_or_default(), |         country: location.country.clone().unwrap_or_default(), | ||||||
|         region: location.region.clone().unwrap_or_default(), |         region: location.region.clone().unwrap_or_default(), | ||||||
|         city: location.city.clone().unwrap_or_default(), |         city: location.city.clone().unwrap_or_default(), | ||||||
|         ip: location.node_ip.clone().unwrap_or_default(), |         ip: location.node_ip.clone().unwrap_or_default(), | ||||||
|         node_pubkey: String::new(), |         node_pubkey: String::new(), | ||||||
|  |         free_ports: (resource.port.len() + 1) as u32, | ||||||
|     }; |     }; | ||||||
|     get_one_app_node(app_node_filter).await |     get_one_app_node(app_node_filter).await | ||||||
| } | } | ||||||
|  | |||||||
| @ -48,7 +48,7 @@ pub async fn hratls_url_and_mr_enclave_from_app_id( | |||||||
|     let dtpm_port = app_contract |     let dtpm_port = app_contract | ||||||
|         .mapped_ports |         .mapped_ports | ||||||
|         .iter() |         .iter() | ||||||
|         .find(|port| port.app_port == HRATLS_APP_PORT) |         .find(|port| port.guest_port == HRATLS_APP_PORT) | ||||||
|         .ok_or(crate::sgx::grpc_dtpm::Error::Dtpm("Could not find DTMP port".to_string()))? |         .ok_or(crate::sgx::grpc_dtpm::Error::Dtpm("Could not find DTMP port".to_string()))? | ||||||
|         .host_port; |         .host_port; | ||||||
| 
 | 
 | ||||||
| @ -71,13 +71,13 @@ pub async fn fetch_config(package_name: &str) -> Result<DtpmConfig, Error> { | |||||||
| pub fn calculate_nanolp_for_app( | pub fn calculate_nanolp_for_app( | ||||||
|     vcpus: u32, |     vcpus: u32, | ||||||
|     memory_mb: u32, |     memory_mb: u32, | ||||||
|     disk_size_mb: u32, |     disk_size_gb: u32, | ||||||
|     hours: u64, |     hours: u64, | ||||||
|     node_price: u64, |     node_price: u64, | ||||||
| ) -> u64 { | ) -> u64 { | ||||||
|     // this calculation needs to match the calculation of the network
 |     // this calculation needs to match the calculation of the network
 | ||||||
|     let total_units = |     let total_units = | ||||||
|         (vcpus as f64 * 5f64) + (memory_mb as f64 / 200f64) + (disk_size_mb as f64 / 10000f64); |         (vcpus as f64 * 5f64) + (memory_mb as f64 / 200f64) + (disk_size_gb as f64 / 10f64); | ||||||
|     let locked_nano = (hours as f64 * 60f64 * total_units * node_price as f64) as u64; |     let locked_nano = (hours as f64 * 60f64 * total_units * node_price as f64) as u64; | ||||||
|     eprintln!( |     eprintln!( | ||||||
|             "Node price: {}/unit/minute. Total Units for hardware requested: {:.4}. Locking {} LP (offering the App for {} hours).", |             "Node price: {}/unit/minute. Total Units for hardware requested: {:.4}. Locking {} LP (offering the App for {} hours).", | ||||||
|  | |||||||
| @ -91,6 +91,7 @@ impl crate::HumanOutput for VmNodeListResp { | |||||||
| 
 | 
 | ||||||
| async fn client() -> Result<BrainVmCliClient<Channel>, Error> { | async fn client() -> Result<BrainVmCliClient<Channel>, Error> { | ||||||
|     let default_brain_url = Config::get_brain_info().0; |     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?)) |     Ok(BrainVmCliClient::new(Config::connect_brain_channel(default_brain_url).await?)) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user