reduce the price of memory

This commit is contained in:
ghe0 2025-01-27 17:49:23 +02:00
parent 9fa62a1978
commit 928c68f550
Signed by: ghe0
GPG Key ID: 451028EE56A0FBB4
2 changed files with 33 additions and 32 deletions

@ -98,7 +98,7 @@ impl Contract {
// I tried, but this can be done better. // I tried, but this can be done better.
// Storage cost should also be based on tier // Storage cost should also be based on tier
(self.vcpus as u64 * 10) (self.vcpus as u64 * 10)
+ ((self.memory_mb + 256) as u64 * 4 / 100) + ((self.memory_mb + 256) as u64 / 200)
+ (self.disk_size_gb as u64 / 10) + (self.disk_size_gb as u64 / 10)
+ (!self.public_ipv4.is_empty() as u64 * 10) + (!self.public_ipv4.is_empty() as u64 * 10)
} }
@ -191,9 +191,10 @@ impl BrainData {
}); });
} }
pub fn contracts_cron(&self) { pub async fn contracts_cron(&self) {
let mut deleted_contracts = Vec::new(); let mut deleted_contracts: Vec<(String, String)> = Vec::new();
log::debug!("Running contracts cron..."); log::debug!("Running contracts cron...");
{
let mut contracts = self.contracts.write().unwrap(); let mut contracts = self.contracts.write().unwrap();
contracts.retain_mut(|c| { contracts.retain_mut(|c| {
let owner_key = self let owner_key = self
@ -204,7 +205,8 @@ impl BrainData {
let minutes_to_collect = (Utc::now() - c.collected_at).num_minutes() as u64; let minutes_to_collect = (Utc::now() - c.collected_at).num_minutes() as u64;
c.collected_at = Utc::now(); c.collected_at = Utc::now();
log::debug!("{minutes_to_collect}"); log::debug!("{minutes_to_collect}");
let mut nanotokens_to_collect = c.price_per_minute().saturating_mul(minutes_to_collect); let mut nanotokens_to_collect =
c.price_per_minute().saturating_mul(minutes_to_collect);
if nanotokens_to_collect > c.locked_nano { if nanotokens_to_collect > c.locked_nano {
nanotokens_to_collect = c.locked_nano; nanotokens_to_collect = c.locked_nano;
} }
@ -219,6 +221,7 @@ impl BrainData {
} }
c.locked_nano > 0 c.locked_nano > 0
}); });
}
// inform daemons of the deletion of the contracts // inform daemons of the deletion of the contracts
for (uuid, node_pubkey) in deleted_contracts.iter() { for (uuid, node_pubkey) in deleted_contracts.iter() {
if let Some(daemon_tx) = self.daemon_tx.get(&node_pubkey.clone()) { if let Some(daemon_tx) = self.daemon_tx.get(&node_pubkey.clone()) {
@ -228,9 +231,7 @@ impl BrainData {
})), })),
}; };
let daemon_tx = daemon_tx.clone(); let daemon_tx = daemon_tx.clone();
tokio::runtime::Runtime::new().unwrap().spawn(async move {
let _ = daemon_tx.send(msg).await; let _ = daemon_tx.send(msg).await;
});
} }
} }
} }

@ -19,7 +19,7 @@ async fn main() {
tokio::spawn(async move { tokio::spawn(async move {
loop { loop {
tokio::time::sleep(tokio::time::Duration::from_secs(60)).await; tokio::time::sleep(tokio::time::Duration::from_secs(60)).await;
data_clone.contracts_cron(); data_clone.contracts_cron().await;
} }
}); });
let addr = "0.0.0.0:31337".parse().unwrap(); let addr = "0.0.0.0:31337".parse().unwrap();