Skip to content

Commit

Permalink
add minigeth example
Browse files Browse the repository at this point in the history
add docker_compose

storage mod & docker-compose
  • Loading branch information
xander42280 committed Apr 4, 2024
1 parent c710665 commit 25f6e6d
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 12 deletions.
62 changes: 62 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# image: zkm-prover:latest => https://github.com/zkMIPS/zkm-prover/blob/main/Dockerfile
# image: gnark-plonky2-verifier:latest => https://github.com/zkMIPS/gnark-plonky2-verifier/blob/main/Dockerfile
version: "3.5"
networks:
default:
name: zkm-prover
services:
zkm-stage:
container_name: zkm-stage
restart: unless-stopped
depends_on:
zkm-prover:
condition: service_started
zkm-snark:
condition: service_started
image: zkm-prover:latest
deploy:
resources:
limits:
memory: 4G
reservations:
memory: 256M
ports:
- 50000:50000
environment:
- RUST_LOG=info
volumes:
- ./service/config/config_docker_compose.toml:/usr/local/bin/config.toml
- /tmp/zkm-prover/data:/zkm/data
command:
- "/bin/sh"
- "-c"
- "/usr/local/bin/service --config /usr/local/bin/config.toml"

zkm-prover:
container_name: zkm-prover
restart: unless-stopped
image: zkm-prover:latest
deploy:
resources:
limits:
memory: 400G
reservations:
memory: 256M
environment:
- RUST_LOG=info
volumes:
- ./service/config/config_docker_compose.toml:/usr/local/bin/config.toml
- /tmp/zkm-prover/data:/zkm/data
command:
- "/bin/sh"
- "-c"
- "/usr/local/bin/service --config /usr/local/bin/config.toml"

zkm-snark:
container_name: zkm-snark
restart: unless-stopped
image: gnark-plonky2-verifier:latest
volumes:
- /tmp/zkm-prover/data:/zkm/data
command: >
/usr/local/bin/start.sh
2 changes: 2 additions & 0 deletions service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ prost = "0.11.0"
tokio = { version = "1.21.0", features = ["macros", "rt-multi-thread", "signal"] }
once_cell = "1.8"
uuid = { version = "1.2", features = ["v4", "fast-rng", "macro-diagnostics"] }
mysql_async = { version = "*", default-features = false, features = ["minimal"]}
serde = "1.0.92"
serde_json = "1.0"
serde_derive = "1.0.92"
log = "0.4.0"
env_logger = "0.10"
Expand Down
1 change: 1 addition & 0 deletions service/config/config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
addr = "0.0.0.0:50000"
database_url = "mysql://root:123456@localhost:3306/stage"
prover_addrs = ["127.0.0.1:50001", "127.0.0.1:50002"]
snark_addrs = ["127.0.0.1:50051"]
base_dir = "/tmp/zkm/test/test_proof"
5 changes: 5 additions & 0 deletions service/config/config_docker_compose.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
addr = "0.0.0.0:50000"
database_url = "mysql://root:123456@localhost:3306/stage"
prover_addrs = ["zkm-prover:50000"]
snark_addrs = ["zkm-snark:50051"]
base_dir = "/zkm/data"
29 changes: 29 additions & 0 deletions service/db.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
CREATE DATABASE IF NOT EXISTS stage;

use stage;

CREATE TABLE IF NOT EXISTS stage_task
(
id varchar(255) primary key,
status int not null default 0,
context text ,
result text ,
check_at timestamp not null default now(),
created_at timestamp not null default now(),
updated_at timestamp not null default now()
);

CREATE TABLE IF NOT EXISTS prove_task
(
id varchar(255) not null primary key,
proof_id varchar(255) not null default '',
type int not null default 0,
status int not null default 0,
time_cost int not null default 0,
node_info varchar(255) not null default '',
request text ,
response text ,
check_at timestamp not null default now(),
created_at timestamp not null default now(),
updated_at timestamp not null default now()
);
11 changes: 1 addition & 10 deletions service/examples/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Examples

## Tools
## Hello world

* Compile the Go code to MIPS

Expand All @@ -10,15 +10,6 @@ Write your own hello.go, and compile with
GOOS=linux GOARCH=mips GOMIPS=softfloat go build hello.go -o /tmp/zkm/test/hello_world
```

Download the block and place it in the corresponding directory [minigeth](https://github.com/zkMIPS/cannon-mips).

```
$ mkdir -p /tmp/cannon
$ export BASEDIR=/tmp/cannon; minigeth/go-ethereum 13284491
$ mkdir -p /tmp/zkm/test/0_13284491
$ cp /tmp/cannon/0_13284491/input /tmp/zkm/test/0_13284491
```

* Compile zkm-prover

```
Expand Down
2 changes: 2 additions & 0 deletions service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub fn instance() -> &'static Mutex<RuntimeConfig> {
#[derive(Debug, Deserialize, Clone)]
pub struct RuntimeConfig {
pub addr: String,
pub database_url: String,
pub prover_addrs: Vec<String>,
pub snark_addrs: Vec<String>,
pub base_dir: String,
Expand All @@ -26,6 +27,7 @@ impl RuntimeConfig {
pub fn new() -> Self {
RuntimeConfig {
addr: "0.0.0.0:50000".to_string(),
database_url: "mysql://user:password@localhost:3306/dbname".to_string(),
prover_addrs: ["0.0.0.0:50000".to_string()].to_vec(),
snark_addrs: ["0.0.0.0:50000".to_string()].to_vec(),
base_dir: "/tmp".to_string(),
Expand Down
1 change: 1 addition & 0 deletions service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod prover_client;
mod prover_node;
mod prover_service;
mod stage_service;
mod storage;

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
Expand Down
19 changes: 17 additions & 2 deletions service/src/stage_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use tokio::sync::mpsc;
use tokio::time;
use tonic::{Request, Response, Status};

use crate::config;
use crate::prover_client;
use crate::{config, storage};
use prover::provers::{self, read_file_bin};

#[allow(clippy::module_inception)]
Expand All @@ -30,6 +30,7 @@ lazy_static! {

pub struct StageServiceSVC {
tls_config: Option<TlsConfig>,
_storage: storage::Storage,
}

impl StageServiceSVC {
Expand All @@ -46,7 +47,12 @@ impl StageServiceSVC {
} else {
None
};
Ok(StageServiceSVC { tls_config })
let database_url = config.database_url.as_str();
let storage = storage::Storage::new(database_url);
Ok(StageServiceSVC {
tls_config,
_storage: storage,
})
}
}

Expand Down Expand Up @@ -147,6 +153,15 @@ impl StageService for StageServiceSVC {
request.get_ref().seg_size,
);

// let _ = self
// .storage
// .insert_stage_task(
// &request.get_ref().proof_id,
// stage_service::ExecutorError::Unspecified as i32,
// &serde_json::to_string(&generate_context).unwrap(),
// )
// .await;

let mut stage = stage::stage::Stage::new(generate_context);
let (tx, mut rx) = mpsc::channel(128);
stage.dispatch();
Expand Down
74 changes: 74 additions & 0 deletions service/src/storage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use mysql_async::prelude::*;

pub struct Storage {
db_pool: mysql_async::Pool,
}

impl Storage {
pub fn new(database_url: &str) -> Self {
let db_pool = mysql_async::Pool::new(database_url);
Storage { db_pool }
}

#[allow(dead_code)]
pub async fn insert_stage_task(
&self,
proof_id: &str,
status: i32,
context: &str,
) -> std::result::Result<bool, String> {
let mut conn = self.db_pool.get_conn().await.map_err(|e| (e.to_string()))?;
let stmt = conn
.prep("INSERT INTO stage_task (id, status, context) values (:id, :status, :context)")
.await
.map_err(|e| (e.to_string()))?;
let params = mysql_async::Params::from(vec![
(
String::from("id"),
mysql_async::Value::Bytes(proof_id.as_bytes().to_vec()),
),
(
String::from("status"),
mysql_async::Value::Int(status as i64),
),
(
String::from("context"),
mysql_async::Value::Bytes(context.as_bytes().to_vec()),
),
]);
let _: std::result::Result<Vec<String>, String> =
conn.exec(stmt, params).await.map_err(|e| (e.to_string()));
Ok(true)
}

#[allow(dead_code)]
pub async fn update_stage_task(
&mut self,
proof_id: &str,
status: i32,
result: &str,
) -> std::result::Result<bool, String> {
let mut conn = self.db_pool.get_conn().await.map_err(|e| (e.to_string()))?;
let stmt = conn
.prep("UPDATE stage_task set status = :status, result = :result where id = :id)")
.await
.map_err(|e| (e.to_string()))?;
let params = mysql_async::Params::from(vec![
(
String::from("id"),
mysql_async::Value::Bytes(proof_id.as_bytes().to_vec()),
),
(
String::from("status"),
mysql_async::Value::Int(status as i64),
),
(
String::from("result"),
mysql_async::Value::Bytes(result.as_bytes().to_vec()),
),
]);
let _: std::result::Result<Vec<String>, String> =
conn.exec(stmt, params).await.map_err(|e| (e.to_string()));
Ok(true)
}
}

0 comments on commit 25f6e6d

Please sign in to comment.