Skip to content

Commit

Permalink
rm registry tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Jun 29, 2024
1 parent 4dc7ea1 commit 99482d1
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 64 deletions.
1 change: 0 additions & 1 deletion cairo/bootloader/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class JobData(Task):
reward: int
num_of_steps: int
cairo_pie_compressed: FieldElementsData
registry_address: int

def load_task(self) -> "CairoPieTask":
return CairoPieTask(
Expand Down
35 changes: 2 additions & 33 deletions crates/common/src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,12 @@ pub struct JobData {
pub num_of_steps: u64,
#[serde(with = "chunk_felt_array")]
pub cairo_pie_compressed: Vec<u8>,
pub registry_address: FieldElement,
}

impl JobData {
pub fn new(reward: u64, cairo_pie_compressed: Vec<u8>, registry_address: FieldElement) -> Self {
pub fn new(reward: u64, cairo_pie_compressed: Vec<u8>) -> Self {
let pie = Self::decompress_cairo_pie(&cairo_pie_compressed);
Self {
reward,
num_of_steps: pie.execution_resources.n_steps as u64,
cairo_pie_compressed,
registry_address,
}
Self { reward, num_of_steps: pie.execution_resources.n_steps as u64, cairo_pie_compressed }
}

fn decompress_cairo_pie(cairo_pie_compressed: &[u8]) -> CairoPie {
Expand Down Expand Up @@ -96,7 +90,6 @@ impl Hash for JobData {
self.reward.hash(state);
self.num_of_steps.hash(state);
self.cairo_pie_compressed.hash(state);
self.registry_address.hash(state);
}
}

Expand All @@ -112,30 +105,6 @@ impl Display for Job {
}
}

// #[cfg(test)]
// mod tests {
// use super::*;
// use proptest::prelude::*;

// proptest! {
// #![proptest_config(ProptestConfig::with_cases(100))]
// #[test]
// fn job_verify_signature(job in any::<Job>()) {
// assert!(job.verify_signature());
// }
// }

// proptest! {
// #![proptest_config(ProptestConfig::with_cases(100))]
// #[test]
// fn job_serialization(job in any::<Job>()) {
// let serialized_job = serde_json::to_string(&job).unwrap();
// let deserialized_job: Job = serde_json::from_str(&serialized_job).unwrap();
// assert_eq!(job, deserialized_job)
// }
// }
// }

mod chunk_felt_array {
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use starknet_crypto::FieldElement;
Expand Down
2 changes: 0 additions & 2 deletions crates/common/src/node_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ where
/// The account for the StarkNet network.
/// This account is used to interact with the Registry contract.
account: SingleOwnerAccount<P, LocalWallet>,
///
///
signing_key: SigningKey,
}

Expand Down
11 changes: 3 additions & 8 deletions crates/compiler/src/cairo_compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use futures::Future;
use rand::{thread_rng, Rng};
use serde_json::json;
use starknet::signers::SigningKey;
use starknet_crypto::FieldElement;
use std::io::Write;
use std::path::PathBuf;
use std::{io::Read, pin::Pin};
Expand All @@ -19,12 +18,11 @@ pub mod tests;

pub struct CairoCompiler<'identity> {
signing_key: &'identity SigningKey,
registry_contract: FieldElement,
}

impl<'identity> CairoCompiler<'identity> {
pub fn new(signing_key: &'identity SigningKey, registry_contract: FieldElement) -> Self {
Self { signing_key, registry_contract }
pub fn new(signing_key: &'identity SigningKey) -> Self {
Self { signing_key }
}
}

Expand Down Expand Up @@ -118,10 +116,7 @@ impl<'identity> CompilerController for CairoCompiler<'identity> {
let mut cairo_pie_compressed = Vec::new();
cairo_pie.read_to_end(&mut cairo_pie_compressed)?;

Ok(Job::try_from_job_data(
JobData::new(0, cairo_pie_compressed, self.registry_contract),
self.signing_key,
))
Ok(Job::try_from_job_data(JobData::new(0, cairo_pie_compressed), self.signing_key))
});

Ok(Process::new(future, terminate_tx))
Expand Down
4 changes: 2 additions & 2 deletions crates/compiler/src/cairo_compiler/tests/multiple_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async fn run_multiple_jobs() {
let fixture2 = fixture();

let identity = SigningKey::from_random();
let compiler = CairoCompiler::new(&identity, FieldElement::ZERO);
let compiler = CairoCompiler::new(&identity);
let mut futures = FuturesUnordered::new();

let job1 = compiler.run(fixture1.program_path, fixture1.program_input_path).unwrap();
Expand All @@ -31,7 +31,7 @@ async fn abort_multiple_jobs() {
let fixture2 = fixture();

let identity = SigningKey::from_random();
let compiler = CairoCompiler::new(&identity, FieldElement::ZERO);
let compiler = CairoCompiler::new(&identity);
let mut futures = FuturesUnordered::new();

let job1 = runner.run(fixture1.program_path, fixture1.program_input_path).unwrap();
Expand Down
5 changes: 2 additions & 3 deletions crates/compiler/src/cairo_compiler/tests/single_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ use crate::{
traits::CompilerController,
};
use starknet::signers::SigningKey;
use starknet_crypto::FieldElement;

#[tokio::test]
async fn run_single_job() {
let fixture = fixture();
let identity = SigningKey::from_random();
let compiler = CairoCompiler::new(&identity, FieldElement::ZERO);
let compiler = CairoCompiler::new(&identity);
compiler.run(fixture.program_path, fixture.program_input_path).unwrap().await.unwrap();
}

#[tokio::test]
async fn abort_single_jobs() {
let fixture = fixture();
let identity = SigningKey::from_random();
let compiler = CairoCompiler::new(&identity, FieldElement::ZERO);
let compiler = CairoCompiler::new(&identity);
let job = compiler.run(fixture.program_path, fixture.program_input_path).unwrap();
job.abort().await.unwrap();
job.await.unwrap_err();
Expand Down
13 changes: 3 additions & 10 deletions crates/delegator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tokio::{
io::{stdin, AsyncBufReadExt, BufReader},
sync::mpsc,
};
use tracing::{debug, info};
use tracing::info;
use tracing_subscriber::EnvFilter;
use zetina_common::{
graceful_shutdown::shutdown_signal,
Expand All @@ -24,7 +24,7 @@ use zetina_compiler::{
errors::CompilerControllerError,
traits::CompilerController,
};
use zetina_peer::{registry::RegistryHandler, swarm::SwarmRunner};
use zetina_peer::swarm::SwarmRunner;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand All @@ -38,9 +38,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
hex::decode("cdd51fbc4e008f4ef807eaf26f5043521ef5931bbb1e04032a25bd845d286b")?;
let url = "https://starknet-sepolia.public.blastapi.io";

let mut registry_handler =
RegistryHandler::new(JsonRpcClient::new(HttpTransport::new(Url::parse(url)?)));
let registry_address = registry_handler.get_registry_address();
let node_account = NodeAccount::new(
private_key,
account_address,
Expand All @@ -59,9 +56,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let (send_topic_tx, send_topic_rx) = mpsc::channel::<Vec<u8>>(1000);
let mut message_stream = swarm_runner.run(new_job_topic, send_topic_rx);
let mut event_stream = registry_handler.subscribe_events(vec!["0x0".to_string()]);

let compiler = CairoCompiler::new(node_account.get_signing_key(), registry_address);
let compiler = CairoCompiler::new(node_account.get_signing_key());

let mut compiler_scheduler =
FuturesUnordered::<Process<'_, Result<Job, CompilerControllerError>>>::new();
Expand Down Expand Up @@ -102,9 +98,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
_ => {}
}
},
Some(Ok(event_vec)) = event_stream.next() => {
debug!("{:?}", event_vec);
},
Some(Ok(job)) = compiler_scheduler.next() => {
let serialized_job = serde_json::to_string(&job).unwrap();
send_topic_tx.send(serialized_job.into()).await?;
Expand Down
3 changes: 1 addition & 2 deletions crates/runner/src/cairo_runner/tests/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use rand::{thread_rng, Rng};
use zetina_common::job::{Job, JobData};

use starknet::signers::SigningKey;
use starknet_crypto::FieldElement;
use std::{env, fs, path::PathBuf};

pub struct TestFixture {
Expand All @@ -20,7 +19,7 @@ pub fn fixture() -> TestFixture {

TestFixture {
job: Job::try_from_job_data(
JobData::new(rng.gen(), fs::read(cairo_pie_path).unwrap(), FieldElement::ZERO),
JobData::new(rng.gen(), fs::read(cairo_pie_path).unwrap()),
&SigningKey::from_random(),
),
program_path,
Expand Down
5 changes: 2 additions & 3 deletions crates/tests/src/tests/compiler_runner_flow.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use futures::stream::FuturesUnordered;
use futures::{FutureExt, StreamExt};
use starknet::signers::SigningKey;
use starknet_crypto::FieldElement;
use zetina_compiler::cairo_compiler::tests::models::fixture as compiler_fixture;
use zetina_compiler::cairo_compiler::CairoCompiler;
use zetina_compiler::traits::CompilerController;
Expand All @@ -15,7 +14,7 @@ async fn run_single_job() {
let runner_fixture = runner_fixture();

let compiler_identity = SigningKey::from_random();
let compiler = CairoCompiler::new(&compiler_identity, FieldElement::ZERO);
let compiler = CairoCompiler::new(&compiler_identity);
let runner_identity = SigningKey::from_random().verifying_key();
let runner = CairoRunner::new(runner_fixture.program_path, &runner_identity);

Expand All @@ -38,7 +37,7 @@ async fn run_multiple_job() {
let runner_fixture1 = runner_fixture();

let compiler_identity = SigningKey::from_random();
let compiler = CairoCompiler::new(&compiler_identity, FieldElement::ZERO);
let compiler = CairoCompiler::new(&compiler_identity);
let runner_identity = SigningKey::from_random().verifying_key();
let runner = CairoRunner::new(runner_fixture1.program_path, &runner_identity);

Expand Down

0 comments on commit 99482d1

Please sign in to comment.