Skip to content

Commit

Permalink
feat: balance check with contract
Browse files Browse the repository at this point in the history
  • Loading branch information
rkdud007 committed May 6, 2024
1 parent ba629e0 commit 90f6722
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion crates/common/src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

Expand Down
11 changes: 5 additions & 6 deletions crates/delegator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -68,7 +68,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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! {
Expand Down Expand Up @@ -110,13 +110,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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));
Expand Down
6 changes: 3 additions & 3 deletions crates/peer/src/node_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use starknet::{
providers::Provider,
signers::{LocalWallet, SigningKey, VerifyingKey},
};
use tracing::trace;
use tracing::{info, trace};

/*
Node Account
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion crates/peer/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 90f6722

Please sign in to comment.