From 90f6722efaa86a054c0e4a63d4b77fd477127bdf Mon Sep 17 00:00:00 2001 From: Pia Date: Mon, 6 May 2024 17:26:46 +0900 Subject: [PATCH] feat: balance check with contract --- Cargo.toml | 2 +- crates/common/src/job.rs | 2 +- crates/delegator/src/main.rs | 11 +++++------ crates/peer/src/node_account.rs | 6 +++--- crates/peer/src/registry.rs | 3 ++- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4f997dc..05bea6c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ async-stream = "0.3.5" bincode = "1.3" cairo-proof-parser = { git = "https://github.com/Okm165/cairo-proof-parser", rev = "97a04bbee07330311b38d6f4cecfed3acb237626" } cairo-vm = { git = "https://github.com/lambdaclass/cairo-vm.git" } -crypto-bigint = { version = "0.5.3", features = ["serde"] } +crypto-bigint = { version = "0.5.3", features = ["serde", "alloc"] } futures = "0.3.30" futures-core = "0.3.30" futures-util = "0.3.30" diff --git a/crates/common/src/job.rs b/crates/common/src/job.rs index 288464b..8087532 100644 --- a/crates/common/src/job.rs +++ b/crates/common/src/job.rs @@ -61,7 +61,7 @@ impl JobData { let pie = Self::decompress_cairo_pie(&cairo_pie_compressed); let num_of_steps = pie.execution_resources.n_steps as u64; // TODO - calculate reward based on the number of steps and the tip - let reward = U256::from(num_of_steps * 100 + tip); + let reward = U256::from(num_of_steps / 10000 + tip); Self { reward, num_of_steps, cairo_pie_compressed, registry_address } } diff --git a/crates/delegator/src/main.rs b/crates/delegator/src/main.rs index 9e9717b..6aa91b1 100644 --- a/crates/delegator/src/main.rs +++ b/crates/delegator/src/main.rs @@ -21,7 +21,7 @@ use tokio::{ io::{stdin, AsyncBufReadExt, BufReader}, sync::mpsc, }; -use tracing::{debug, info}; +use tracing::{debug, error, info}; use tracing_subscriber::EnvFilter; #[tokio::main] @@ -68,7 +68,7 @@ async fn main() -> Result<(), Box> { // Read cairo program path from stdin let mut stdin = BufReader::new(stdin()).lines(); // TODO: Accept dynamic tip - let tip = 10; + let tip = 0; loop { tokio::select! { @@ -110,13 +110,12 @@ async fn main() -> Result<(), Box> { let job_data = JobData::new(tip, cairo_pie_compressed,registry_address); let expected_reward = job_data.reward; let deposit_amount = node_account.balance(registry_address).await?; - // TODO: handle error better way if deposit_amount < expected_reward{ - return Err("Staked amount is less than expected reward".into()); + error!("Staked amount is less than expected reward"); + return Ok(()); } let job = Job::try_from_job_data(job_data, node_account.get_signing_key()); - // info!("Job: {:?}", job.job_data.reward); - // info!("Job: {:?}", job.job_data.num_of_steps); + let serialized_job = serde_json::to_string(&job).unwrap(); send_topic_tx.send(serialized_job.into()).await?; info!("Sent a new job: {}", hash!(&job)); diff --git a/crates/peer/src/node_account.rs b/crates/peer/src/node_account.rs index e5581d3..67f740a 100644 --- a/crates/peer/src/node_account.rs +++ b/crates/peer/src/node_account.rs @@ -9,7 +9,7 @@ use starknet::{ providers::Provider, signers::{LocalWallet, SigningKey, VerifyingKey}, }; -use tracing::trace; +use tracing::{info, trace}; /* Node Account @@ -109,8 +109,8 @@ where let low: u128 = call_result[0].try_into().unwrap(); let high: u128 = call_result[1].try_into().unwrap(); - let call_result = U256::from(high << 128 | low); - trace!("Balance result: {:?}", call_result); + let call_result = U256::from(high << 64 | low); + info!("Balance result: {:?}", call_result); Ok(call_result) } diff --git a/crates/peer/src/registry.rs b/crates/peer/src/registry.rs index 48ba817..4100db1 100644 --- a/crates/peer/src/registry.rs +++ b/crates/peer/src/registry.rs @@ -8,7 +8,8 @@ use std::{error::Error, pin::Pin}; use tracing::trace; const EVENT_SCRAPE_INTERVAL: u64 = 2; -const REGISTRY_CONTRACT: &str = "0xcdd51fbc4e008f4ef807eaf26f5043521ef5931bbb1e04032a25bd845d286b"; +const REGISTRY_CONTRACT: &str = + "0x030938966f24f5084d9570ac52aeff76fe30559f4f3fe086a2b0cb4017ce4384"; /* Registry Handler