Skip to content

Commit

Permalink
feat: serialize mock job
Browse files Browse the repository at this point in the history
  • Loading branch information
rkdud007 committed Apr 19, 2024
1 parent 3b3e93f commit 8a2f765
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 6 deletions.
17 changes: 15 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ members = [
"crates/delegator",
"crates/executor",
"crates/peer",
"crates/prover", "crates/runner",
"crates/prover",
"crates/runner",
]
exclude = []

Expand All @@ -21,14 +22,26 @@ license-file = "LICENSE"
[workspace.dependencies]
async-process = "2.2.0"
async-stream = "0.3.5"
bincode = "1.3"
cairo-felt = "0.9.1"
cairo-proof-parser = { git = "https://github.com/Okm165/cairo-proof-parser", rev = "97a04bbee07330311b38d6f4cecfed3acb237626" }
futures = "0.3.30"
futures-core = "0.3.30"
futures-util = "0.3.30"
hex = "0.4.3"
itertools = "0.12.1"
libp2p = { version = "0.53.2", features = ["secp256k1", "tokio","gossipsub","kad","mdns","noise","macros","tcp","yamux","quic"]}
libp2p = { version = "0.53.2", features = [
"secp256k1",
"tokio",
"gossipsub",
"kad",
"mdns",
"noise",
"macros",
"tcp",
"yamux",
"quic",
] }
libsecp256k1 = "0.7.1"
num-bigint = "0.4.4"
serde = "1.0.197"
Expand Down
3 changes: 2 additions & 1 deletion crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ license-file.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bincode.workspace = true
cairo-felt.workspace = true
hex.workspace = true
libp2p.workspace = true
Expand All @@ -16,4 +17,4 @@ num-bigint.workspace = true
serde_json.workspace = true
serde.workspace = true
tempfile.workspace = true
thiserror.workspace = true
thiserror.workspace = true
10 changes: 10 additions & 0 deletions crates/common/src/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,13 @@ impl Display for Job {
write!(f, "{}", hex::encode(hash!(self).to_be_bytes()))
}
}

impl Job {
pub fn serialize_job(&self) -> Vec<u8> {
bincode::serialize(self).unwrap()

Check failure on line 39 in crates/common/src/job.rs

View workflow job for this annotation

GitHub Actions / formatting-and-testing

the trait bound `Job: Serialize` is not satisfied

Check failure on line 39 in crates/common/src/job.rs

View workflow job for this annotation

GitHub Actions / formatting-and-testing

the trait bound `Job: Serialize` is not satisfied
}

pub fn deserialize_job(serialized_job: &[u8]) -> Self {
bincode::deserialize(serialized_job).unwrap()

Check failure on line 43 in crates/common/src/job.rs

View workflow job for this annotation

GitHub Actions / formatting-and-testing

the trait bound `Job: Deserialize<'_>` is not satisfied

Check failure on line 43 in crates/common/src/job.rs

View workflow job for this annotation

GitHub Actions / formatting-and-testing

the trait bound `Job: Deserialize<'_>` is not satisfied
}
}
15 changes: 13 additions & 2 deletions crates/delegator/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use futures_util::StreamExt;
use sharp_p2p_common::job::Job;
use sharp_p2p_common::network::Network;
use sharp_p2p_common::topic::{gossipsub_ident_topic, Topic};
use sharp_p2p_peer::registry::RegistryHandler;
Expand Down Expand Up @@ -36,8 +37,18 @@ async fn main() -> Result<(), Box<dyn Error>> {

loop {
tokio::select! {
Ok(Some(line)) = stdin.next_line() => {
send_topic_tx.send(line.as_bytes().to_vec()).await?;
Ok(Some(_)) = stdin.next_line() => {
// TODO: Turn this into a real job generation
let job = Job {
reward: 100,
num_of_steps: 10,
private_input: vec![1, 2, 3],
public_input: vec![4, 5, 6],
cpu_air_prover_config: vec![7, 8, 9],
cpu_air_params: vec![10, 11, 12],
};
let serialized_job = (job).serialize_job();
send_topic_tx.send(serialized_job).await?;
},
Some(event) = message_stream.next() => {
info!("{:?}", event);
Expand Down
24 changes: 23 additions & 1 deletion crates/executor/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use futures_util::StreamExt;
use libp2p::gossipsub::Event;
use sharp_p2p_common::job::Job;
use sharp_p2p_common::network::Network;
use sharp_p2p_common::topic::{gossipsub_ident_topic, Topic};
use sharp_p2p_peer::registry::RegistryHandler;
Expand Down Expand Up @@ -40,7 +42,27 @@ async fn main() -> Result<(), Box<dyn Error>> {
send_topic_tx.send(line.as_bytes().to_vec()).await?;
},
Some(event) = message_stream.next() => {
info!("{:?}", event);
match event {
Event::Message { message, .. } => {
// Received a new-job message from the network
if message.topic == gossipsub_ident_topic(Network::Sepolia, Topic::NewJob).into() {
let deserialized_job = Job::deserialize_job(&message.data);
info!("Received a new job: {:?}", deserialized_job);
}
// Received a picked-job message from the network
if message.topic == gossipsub_ident_topic(Network::Sepolia, Topic::PickedJob).into() {

info!("Received a picked job: {:?}", message);
}
},
Event::Subscribed { peer_id, topic } => {
info!("{} subscribed to the topic {}", peer_id.to_string(), topic.to_string());
},
Event::Unsubscribed { peer_id, topic }=> {
info!("{} unsubscribed to the topic {}", peer_id.to_string(), topic.to_string());
},
_ => {}
}
},
Some(Ok(event_vec)) = event_stream.next() => {
info!("{:?}", event_vec);
Expand Down

0 comments on commit 8a2f765

Please sign in to comment.