rename operator_pubkey to operator_wallet and add max_memory_mb_per_app field; submit node pricing on registering node

This commit is contained in:
Noor 2025-03-11 10:42:05 +00:00
parent d790e2cb98
commit d7ae481085
Signed by: noormohammedb
GPG Key ID: E424C39E19EFD7DF
3 changed files with 21 additions and 33 deletions

@ -5,8 +5,9 @@ use serde::{Deserialize, Serialize};
pub struct HostConfig { pub struct HostConfig {
pub brain_url: String, pub brain_url: String,
pub host_ip_address: String, pub host_ip_address: String,
pub operator_pubkey: String, pub operator_wallet: String,
pub max_cores_per_app: u32, pub max_cores_per_app: u32,
pub max_memory_mb_per_app: u32,
pub max_vcpu_reservation: u32, pub max_vcpu_reservation: u32,
pub max_mem_reservation_mb: u32, pub max_mem_reservation_mb: u32,
pub max_disk_reservation_mb: u32, pub max_disk_reservation_mb: u32,
@ -24,37 +25,6 @@ fn default_reserved_no_of_port() -> u32 {
16 16
} }
/*
impl Default for HostConfig {
fn default() -> Self {
// TODO: load from config file
let brain_url =
std::env::var("BRAIN_URL").unwrap_or_else(|_| "http://127.0.0.1:31337".to_string());
let owner_wallet = "0x".to_string();
let host_ip_address = "127.0.0.1".to_string();
let max_cores_per_app = 4;
let max_vcpu_reservation = 8;
let max_mem_reservation_mb = 8192;
let max_ports_per_app = 9;
let price = 0;
Self {
brain_url,
host_ip_address,
owner_wallet,
max_cores_per_app,
max_ports_per_app,
max_vcpu_reservation,
max_mem_reservation_mb,
price,
delete_archive: true,
}
}
}
*/
impl HostConfig { impl HostConfig {
pub fn load_from_disk(path: &str) -> Result<Self> { pub fn load_from_disk(path: &str) -> Result<Self> {
let content = std::fs::read_to_string(path)?; let content = std::fs::read_to_string(path)?;

@ -92,11 +92,28 @@ impl App {
host_config: &HostConfig, host_config: &HostConfig,
host_resource: &mut HostResources, host_resource: &mut HostResources,
) -> Result<Self> { ) -> Result<Self> {
if new_app_req.price_per_unit < host_config.price {
return Err(anyhow!("price is too low"));
}
if host_resource.existing_apps.contains(&new_app_req.uuid) {
let content =
std::fs::read_to_string(format!("{}{}.yaml", *APP_CONFIG_DIR, &new_app_req.uuid))?;
let app: App = serde_yml::from_str(&content)?;
return Err(anyhow!("app already exists\n{:?}", app));
}
let app_uuid = new_app_req.uuid.clone(); let app_uuid = new_app_req.uuid.clone();
if host_config.max_cores_per_app < new_app_req.resource.vcpu { if host_config.max_cores_per_app < new_app_req.resource.vcpu {
return Err(anyhow!("too many vcpus for app")); return Err(anyhow!("too many vcpus for app"));
} }
if host_config.max_memory_mb_per_app < new_app_req.resource.memory_mb {
return Err(anyhow!("too much memory for app"));
}
// TODO: revert state if any error
if host_config.max_vcpu_reservation if host_config.max_vcpu_reservation
< host_resource < host_resource
.reserved_vcpus .reserved_vcpus

@ -30,11 +30,12 @@ pub async fn register_node(config: &crate::HostConfig) -> Result<Vec<AppContract
let req = RegisterAppNodeReq { let req = RegisterAppNodeReq {
node_pubkey: PUBLIC_KEY.to_string(), node_pubkey: PUBLIC_KEY.to_string(),
operator_pubkey: config.operator_pubkey.clone(), operator_wallet: config.operator_wallet.clone(),
main_ip: IP_INFO.ip.clone(), main_ip: IP_INFO.ip.clone(),
city: IP_INFO.city.clone(), city: IP_INFO.city.clone(),
region: IP_INFO.region.clone(), region: IP_INFO.region.clone(),
country: IP_INFO.country.clone(), country: IP_INFO.country.clone(),
price: config.price,
}; };
let pubkey = PUBLIC_KEY.clone(); let pubkey = PUBLIC_KEY.clone();