Skip to content

Commit

Permalink
proof verification and dht limits increase
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Aug 11, 2024
1 parent 28e5fa6 commit e32574a
Show file tree
Hide file tree
Showing 12 changed files with 430 additions and 45 deletions.
25 changes: 14 additions & 11 deletions crates/delegator/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use axum::{
};
use futures::StreamExt;
use hyper::StatusCode;
use libp2p::{kad, PeerId};
use libp2p::kad;
use serde::{Deserialize, Serialize};
use std::hash::{DefaultHasher, Hash, Hasher};
use std::{io, time::Duration};
Expand Down Expand Up @@ -39,7 +39,7 @@ pub struct DelegateRequest {

#[derive(Debug, Serialize)]
pub struct DelegateResponse {
job_hash: kad::RecordKey,
job_key: String,
}

pub async fn deletage_handler(
Expand All @@ -49,19 +49,19 @@ pub async fn deletage_handler(
let job_data = JobData::new(input.pie);
let job_data_hash = kad::RecordKey::new(&hash!(job_data).to_be_bytes());
state.delegate_tx.send(job_data).await.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
Ok(Json(DelegateResponse { job_hash: job_data_hash }))
Ok(Json(DelegateResponse { job_key: hex::encode(job_data_hash) }))
}

#[derive(Debug, Deserialize)]
pub struct JobEventsRequest {
job_hash: kad::RecordKey,
job_key: String,
}

#[derive(Debug, Serialize)]
#[serde(tag = "type", content = "data")]
pub enum JobEventsResponse {
BidReceived(PeerId),
Delegated(PeerId),
BidReceived(String),
Delegated(String),
Finished(Vec<u8>),
}

Expand All @@ -70,16 +70,19 @@ pub async fn job_events_handler(
Query(input): Query<JobEventsRequest>,
) -> Sse<impl Stream<Item = Result<Event, io::Error>>> {
let stream = stream! {
let job_hash = input.job_hash;
let job_key = kad::RecordKey::new(
&hex::decode(input.job_key)
.map_err(|e| io::Error::new(io::ErrorKind::BrokenPipe, e.to_string()))?
);
loop {
tokio::select! {
Ok((hash, event)) = state.events_rx.recv() => {
if hash == job_hash {
Ok((key, event)) = state.events_rx.recv() => {
if key == job_key {
yield Event::default()
.json_data(
match event {
DelegatorEvent::BidReceived(peer_id) => { JobEventsResponse::BidReceived(peer_id) },
DelegatorEvent::Delegated(peer_id) => { JobEventsResponse::Delegated(peer_id) },
DelegatorEvent::BidReceived(peer_id) => { JobEventsResponse::BidReceived(peer_id.to_base58()) },
DelegatorEvent::Delegated(peer_id) => { JobEventsResponse::Delegated(peer_id.to_base58()) },
DelegatorEvent::Finished(data) => { JobEventsResponse::Finished(data) },
}
)
Expand Down
21 changes: 15 additions & 6 deletions crates/peer/src/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use futures::stream::Stream;
use libp2p::futures::StreamExt;
use libp2p::gossipsub::{self, IdentTopic, TopicHash};
use libp2p::identity::Keypair;
use libp2p::kad::store::MemoryStore;
use libp2p::kad::Mode;
use libp2p::kad::store::{MemoryStore, MemoryStoreConfig};
use libp2p::kad::{Config, Mode};
use libp2p::swarm::{DialError, NetworkBehaviour, SwarmEvent};
use libp2p::{kad, noise, tcp, yamux, Multiaddr, Swarm, SwarmBuilder};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -92,6 +92,8 @@ impl SwarmRunner {
p2p_keypair: Keypair,
p2p_multiaddr: Multiaddr,

Check warning on line 93 in crates/peer/src/swarm.rs

View workflow job for this annotation

GitHub Actions / check-formatting

Diff in /home/runner/work/zetina/zetina/crates/peer/src/swarm.rs

Check warning on line 93 in crates/peer/src/swarm.rs

View workflow job for this annotation

GitHub Actions / check-formatting

Diff in /home/runner/work/zetina/zetina/crates/peer/src/swarm.rs
) -> Result<Self, Box<dyn std::error::Error>> {
let mut config = Config::default();
config.set_max_packet_size(1024*1024*100);
let mut swarm = SwarmBuilder::with_existing_identity(p2p_keypair)
.with_tokio()
.with_tcp(
Expand All @@ -101,13 +103,20 @@ impl SwarmRunner {
)?
.with_quic()
.with_behaviour(|p2p_keypair| PeerBehaviour {
kademlia: kad::Behaviour::new(
kademlia: kad::Behaviour::with_config(
p2p_keypair.public().to_peer_id(),

Check warning on line 107 in crates/peer/src/swarm.rs

View workflow job for this annotation

GitHub Actions / check-formatting

Diff in /home/runner/work/zetina/zetina/crates/peer/src/swarm.rs

Check warning on line 107 in crates/peer/src/swarm.rs

View workflow job for this annotation

GitHub Actions / check-formatting

Diff in /home/runner/work/zetina/zetina/crates/peer/src/swarm.rs
MemoryStore::new(p2p_keypair.public().to_peer_id()),
MemoryStore::with_config(
p2p_keypair.public().to_peer_id(),
MemoryStoreConfig {
max_value_bytes: 1024*1024*100,
..Default::default()
},
),
config

Check warning on line 115 in crates/peer/src/swarm.rs

View workflow job for this annotation

GitHub Actions / check-formatting

Diff in /home/runner/work/zetina/zetina/crates/peer/src/swarm.rs

Check warning on line 115 in crates/peer/src/swarm.rs

View workflow job for this annotation

GitHub Actions / check-formatting

Diff in /home/runner/work/zetina/zetina/crates/peer/src/swarm.rs
),
gossipsub: Self::init_gossip(p2p_keypair).unwrap(),
})?
.with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(60)))
.with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(10)))
.build();

swarm.behaviour_mut().gossipsub.subscribe(&IdentTopic::new(Topic::Networking.as_str()))?;
Expand Down Expand Up @@ -163,7 +172,7 @@ impl SwarmRunner {
let record = kad::Record {
key: kad::RecordKey::new(&key),
value: data,
publisher: Some(*self.swarm.local_peer_id()),
publisher: None,
expires: None,
};
if let Err(e) = self.swarm.behaviour_mut().kademlia.put_record(record, kad::Quorum::One) {
Expand Down
6 changes: 3 additions & 3 deletions crates/prover/src/stone_prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ pub fn params(n_steps: u64) -> Params {
)
.collect(),
last_layer_degree_bound,
n_queries: 1,
proof_of_work_bits: 1,
n_queries: 20,
proof_of_work_bits: 30,
},
log_n_cosets: 1,
log_n_cosets: 2,
},
..Default::default()
}
Expand Down
72 changes: 72 additions & 0 deletions dashboard/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,19 @@
"react": "^18",
"react-dom": "^18",
"react-dropzone": "^14.2.3",
"zod": "^3.23.8"
"zod": "^3.23.8",
"swiftness-dex-blake2s": "^0.0.7",
"swiftness-dex-keccak": "^0.0.7",
"swiftness-recursive-blake2s": "^0.0.7",
"swiftness-recursive-keccak": "^0.0.7",
"swiftness-recursive-with-poseidon-blake2s": "^0.0.7",
"swiftness-recursive-with-poseidon-keccak": "^0.0.7",
"swiftness-small-blake2s": "^0.0.7",
"swiftness-small-keccak": "^0.0.7",
"swiftness-starknet-blake2s": "^0.0.7",
"swiftness-starknet-keccak": "^0.0.7",
"swiftness-starknet-with-keccak-blake2s": "^0.0.7",
"swiftness-starknet-with-keccak-keccak": "^0.0.7"
},
"devDependencies": {
"@types/node": "^20",
Expand Down
21 changes: 13 additions & 8 deletions dashboard/src/app/api.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
import { z } from "zod";

const hexStringSchema = z.string().regex(/^[0-9a-fA-F]+$/, 'Invalid hex string');
const base58Pattern = /^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$/;
const base58Schema = z.string().regex(base58Pattern, 'Invalid Base58 string');
const bytesSchema = z.array(z.number());

// Zod for DelegateRequest
export const DelegateRequest = z.object({
pie: z.array(z.number()),
pie: bytesSchema,
});
export type DelegateRequest = z.infer<typeof DelegateRequest>;

// Zod for DelegateResponse
export const DelegateResponse = z.object({
job_hash: z.coerce.bigint(),
job_key: hexStringSchema
});
export type DelegateResponse = z.infer<typeof DelegateResponse>;

// Zod for JobEventsRequest
export const JobEventsRequest = z.object({
job_hash: z.coerce.bigint(),
job_key: hexStringSchema
});
export type JobEventsRequest = z.infer<typeof JobEventsRequest>;

export const JobEventsResponse = z.object({
type: z.literal("Finished"),
type: z.literal("Finished").or(z.literal("Delegated")).or(z.literal("BidReceived")),
data: z.any(),
});
export type JobEventsResponse = z.infer<typeof JobEventsResponse>;

export const JobHash = z.coerce.bigint();
export type JobHash = z.infer<typeof JobHash>;

export const Proof = z.array(z.number());
export const Proof = bytesSchema;
export type Proof = z.infer<typeof Proof>;

export const PeerId = base58Schema;
export type PeerId = z.infer<typeof PeerId>;
10 changes: 10 additions & 0 deletions dashboard/src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,13 @@ body {
filter: blur(5px);
z-index: -1; /* Ensure the image is behind any content in .background */
}

/* Hide scrollbar for WebKit browsers (Chrome, Safari) */
.scroll-container::-webkit-scrollbar {
display: none; /* Hide scrollbar */
}

/* Hide scrollbar for Firefox */
.scroll-container {
scrollbar-width: none; /* Hide scrollbar */
}
Loading

0 comments on commit e32574a

Please sign in to comment.