diff --git a/Cargo.lock b/Cargo.lock index fbaf4fc..93fd6b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3815,7 +3815,7 @@ dependencies = [ [[package]] name = "reth-chainspec" version = "1.1.5" -source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-v2#b037c98a5a3462526829179f58cd67f51511f227" +source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-upgrade#eb41a605a7efd77c2292a110745179d7d1a5b1de" dependencies = [ "alloy-chains", "alloy-consensus", @@ -3834,7 +3834,7 @@ dependencies = [ [[package]] name = "reth-codecs" version = "1.1.5" -source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-v2#b037c98a5a3462526829179f58cd67f51511f227" +source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-upgrade#eb41a605a7efd77c2292a110745179d7d1a5b1de" dependencies = [ "alloy-consensus", "alloy-eips", @@ -3851,7 +3851,7 @@ dependencies = [ [[package]] name = "reth-codecs-derive" version = "1.1.5" -source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-v2#b037c98a5a3462526829179f58cd67f51511f227" +source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-upgrade#eb41a605a7efd77c2292a110745179d7d1a5b1de" dependencies = [ "convert_case", "proc-macro2", @@ -3862,7 +3862,7 @@ dependencies = [ [[package]] name = "reth-ethereum-forks" version = "1.1.5" -source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-v2#b037c98a5a3462526829179f58cd67f51511f227" +source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-upgrade#eb41a605a7efd77c2292a110745179d7d1a5b1de" dependencies = [ "alloy-chains", "alloy-eip2124", @@ -3877,7 +3877,7 @@ dependencies = [ [[package]] name = "reth-ethereum-primitives" version = "1.1.5" -source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-v2#b037c98a5a3462526829179f58cd67f51511f227" +source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-upgrade#eb41a605a7efd77c2292a110745179d7d1a5b1de" dependencies = [ "alloy-consensus", "alloy-eips", @@ -3892,7 +3892,7 @@ dependencies = [ [[package]] name = "reth-network-peers" version = "1.1.5" -source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-v2#b037c98a5a3462526829179f58cd67f51511f227" +source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-upgrade#eb41a605a7efd77c2292a110745179d7d1a5b1de" dependencies = [ "alloy-primitives", "alloy-rlp", @@ -3904,7 +3904,7 @@ dependencies = [ [[package]] name = "reth-primitives" version = "1.1.5" -source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-v2#b037c98a5a3462526829179f58cd67f51511f227" +source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-upgrade#eb41a605a7efd77c2292a110745179d7d1a5b1de" dependencies = [ "alloy-consensus", "once_cell", @@ -3917,7 +3917,7 @@ dependencies = [ [[package]] name = "reth-primitives-traits" version = "1.1.5" -source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-v2#b037c98a5a3462526829179f58cd67f51511f227" +source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-upgrade#eb41a605a7efd77c2292a110745179d7d1a5b1de" dependencies = [ "alloy-consensus", "alloy-eips", @@ -3943,7 +3943,7 @@ dependencies = [ [[package]] name = "reth-scroll-chainspec" version = "1.1.5" -source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-v2#b037c98a5a3462526829179f58cd67f51511f227" +source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-upgrade#eb41a605a7efd77c2292a110745179d7d1a5b1de" dependencies = [ "alloy-chains", "alloy-consensus", @@ -3966,7 +3966,7 @@ dependencies = [ [[package]] name = "reth-scroll-forks" version = "1.1.5" -source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-v2#b037c98a5a3462526829179f58cd67f51511f227" +source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-upgrade#eb41a605a7efd77c2292a110745179d7d1a5b1de" dependencies = [ "alloy-chains", "alloy-primitives", @@ -3978,7 +3978,7 @@ dependencies = [ [[package]] name = "reth-scroll-primitives" version = "1.1.5" -source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-v2#b037c98a5a3462526829179f58cd67f51511f227" +source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-upgrade#eb41a605a7efd77c2292a110745179d7d1a5b1de" dependencies = [ "alloy-consensus", "alloy-eips", @@ -3999,7 +3999,7 @@ dependencies = [ [[package]] name = "reth-static-file-types" version = "1.1.5" -source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-v2#b037c98a5a3462526829179f58cd67f51511f227" +source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-upgrade#eb41a605a7efd77c2292a110745179d7d1a5b1de" dependencies = [ "alloy-primitives", "derive_more", @@ -4010,7 +4010,7 @@ dependencies = [ [[package]] name = "reth-trie-common" version = "1.1.5" -source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-v2#b037c98a5a3462526829179f58cd67f51511f227" +source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-upgrade#eb41a605a7efd77c2292a110745179d7d1a5b1de" dependencies = [ "alloy-consensus", "alloy-primitives", @@ -4037,7 +4037,7 @@ dependencies = [ [[package]] name = "revm" version = "19.4.0" -source = "git+https://github.com/scroll-tech/revm?branch=scroll-evm-executor%2Ffeat%2Fv55%2Feuclid-v2#6fe1fae6d92f0f6a3ed234a955aca4bdcf864f97" +source = "git+https://github.com/scroll-tech/revm?branch=scroll-evm-executor%2Ffeat%2Fv55%2Feuclid-upgrade#17dfd866846f0fa19fa04bd6f848fb80cd5d73fc" dependencies = [ "auto_impl", "cfg-if", @@ -4051,7 +4051,7 @@ dependencies = [ [[package]] name = "revm-interpreter" version = "15.1.0" -source = "git+https://github.com/scroll-tech/revm?branch=scroll-evm-executor%2Ffeat%2Fv55%2Feuclid-v2#6fe1fae6d92f0f6a3ed234a955aca4bdcf864f97" +source = "git+https://github.com/scroll-tech/revm?branch=scroll-evm-executor%2Ffeat%2Fv55%2Feuclid-upgrade#17dfd866846f0fa19fa04bd6f848fb80cd5d73fc" dependencies = [ "revm-primitives", "serde", @@ -4060,7 +4060,7 @@ dependencies = [ [[package]] name = "revm-precompile" version = "16.0.0" -source = "git+https://github.com/scroll-tech/revm?branch=scroll-evm-executor%2Ffeat%2Fv55%2Feuclid-v2#6fe1fae6d92f0f6a3ed234a955aca4bdcf864f97" +source = "git+https://github.com/scroll-tech/revm?branch=scroll-evm-executor%2Ffeat%2Fv55%2Feuclid-upgrade#17dfd866846f0fa19fa04bd6f848fb80cd5d73fc" dependencies = [ "aurora-engine-modexp", "c-kzg", @@ -4078,7 +4078,7 @@ dependencies = [ [[package]] name = "revm-primitives" version = "15.1.0" -source = "git+https://github.com/scroll-tech/revm?branch=scroll-evm-executor%2Ffeat%2Fv55%2Feuclid-v2#6fe1fae6d92f0f6a3ed234a955aca4bdcf864f97" +source = "git+https://github.com/scroll-tech/revm?branch=scroll-evm-executor%2Ffeat%2Fv55%2Feuclid-upgrade#17dfd866846f0fa19fa04bd6f848fb80cd5d73fc" dependencies = [ "alloy-eip2930", "alloy-eip7702", @@ -4399,7 +4399,7 @@ checksum = "6ea1a2d0a644769cc99faa24c3ad26b379b786fe7c36fd3c546254801650e6dd" [[package]] name = "sbv-helpers" version = "2.0.0" -source = "git+https://github.com/scroll-tech/stateless-block-verifier?branch=zkvm%2Feuclid-v2#74d7fb0398b1bc94fe20ac29bdc445634c4bfeea" +source = "git+https://github.com/scroll-tech/stateless-block-verifier?branch=zkvm%2Feuclid-upgrade#6759d7b0893e31782e3a24abaad6be655edffdde" dependencies = [ "revm", ] @@ -4407,7 +4407,7 @@ dependencies = [ [[package]] name = "sbv-kv" version = "2.0.0" -source = "git+https://github.com/scroll-tech/stateless-block-verifier?branch=zkvm%2Feuclid-v2#74d7fb0398b1bc94fe20ac29bdc445634c4bfeea" +source = "git+https://github.com/scroll-tech/stateless-block-verifier?branch=zkvm%2Feuclid-upgrade#6759d7b0893e31782e3a24abaad6be655edffdde" dependencies = [ "auto_impl", "hashbrown 0.15.2", @@ -4417,7 +4417,7 @@ dependencies = [ [[package]] name = "sbv-primitives" version = "2.0.0" -source = "git+https://github.com/scroll-tech/stateless-block-verifier?branch=zkvm%2Feuclid-v2#74d7fb0398b1bc94fe20ac29bdc445634c4bfeea" +source = "git+https://github.com/scroll-tech/stateless-block-verifier?branch=zkvm%2Feuclid-upgrade#6759d7b0893e31782e3a24abaad6be655edffdde" dependencies = [ "alloy-consensus", "alloy-eips", @@ -4435,7 +4435,6 @@ dependencies = [ "reth-scroll-forks", "reth-scroll-primitives", "revm", - "rkyv", "sbv-helpers", "sbv-kv", "scroll-alloy-consensus", @@ -4448,7 +4447,7 @@ dependencies = [ [[package]] name = "sbv-utils" version = "2.0.0" -source = "git+https://github.com/scroll-tech/stateless-block-verifier?branch=zkvm%2Feuclid-v2#74d7fb0398b1bc94fe20ac29bdc445634c4bfeea" +source = "git+https://github.com/scroll-tech/stateless-block-verifier?branch=zkvm%2Feuclid-upgrade#6759d7b0893e31782e3a24abaad6be655edffdde" dependencies = [ "alloy-provider", "alloy-transport", @@ -4500,7 +4499,7 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "scroll-alloy-consensus" version = "1.1.5" -source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-v2#b037c98a5a3462526829179f58cd67f51511f227" +source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-upgrade#eb41a605a7efd77c2292a110745179d7d1a5b1de" dependencies = [ "alloy-consensus", "alloy-eips", @@ -4518,7 +4517,7 @@ dependencies = [ [[package]] name = "scroll-alloy-network" version = "1.1.5" -source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-v2#b037c98a5a3462526829179f58cd67f51511f227" +source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-upgrade#eb41a605a7efd77c2292a110745179d7d1a5b1de" dependencies = [ "alloy-consensus", "alloy-network", @@ -4532,7 +4531,7 @@ dependencies = [ [[package]] name = "scroll-alloy-rpc-types" version = "1.1.5" -source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-v2#b037c98a5a3462526829179f58cd67f51511f227" +source = "git+https://github.com/scroll-tech/reth?branch=zkvm%2Feuclid-upgrade#eb41a605a7efd77c2292a110745179d7d1a5b1de" dependencies = [ "alloy-consensus", "alloy-eips", @@ -6236,23 +6235,3 @@ dependencies = [ "cc", "pkg-config", ] - -[[patch.unused]] -name = "revm" -version = "19.4.0" -source = "git+https://github.com/scroll-tech/revm?branch=scroll-evm-executor%2Fv55#6accb0ba959747d717443954a8bd988efa8f98fc" - -[[patch.unused]] -name = "revm-interpreter" -version = "15.1.0" -source = "git+https://github.com/scroll-tech/revm?branch=scroll-evm-executor%2Fv55#6accb0ba959747d717443954a8bd988efa8f98fc" - -[[patch.unused]] -name = "revm-precompile" -version = "16.0.0" -source = "git+https://github.com/scroll-tech/revm?branch=scroll-evm-executor%2Fv55#6accb0ba959747d717443954a8bd988efa8f98fc" - -[[patch.unused]] -name = "revm-primitives" -version = "15.1.0" -source = "git+https://github.com/scroll-tech/revm?branch=scroll-evm-executor%2Fv55#6accb0ba959747d717443954a8bd988efa8f98fc" diff --git a/Cargo.toml b/Cargo.toml index 35581f5..6b812cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,10 +33,10 @@ tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } axum = "0.6.0" dotenv = "0.15" rocksdb = "0.23.0" -sbv-utils = { git = "https://github.com/scroll-tech/stateless-block-verifier", branch = "zkvm/euclid-v2", features = [ +sbv-utils = { git = "https://github.com/scroll-tech/stateless-block-verifier", branch = "zkvm/euclid-upgrade", features = [ "scroll", ], optional = true } -sbv-primitives = { git = "https://github.com/scroll-tech/stateless-block-verifier", branch = "zkvm/euclid-v2", features = [ +sbv-primitives = { git = "https://github.com/scroll-tech/stateless-block-verifier", branch = "zkvm/euclid-upgrade", features = [ "scroll", ], optional = true } url = "2.5.4" @@ -47,8 +47,8 @@ openvm = ["dep:sbv-utils", "dep:sbv-primitives"] [patch.crates-io] # patched add rkyv support & MSRV 1.77 alloy-primitives = { git = "https://github.com/scroll-tech/alloy-core", branch = "v0.8.21" } -revm = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v55" } -revm-interpreter = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v55" } -revm-precompile = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v55" } -revm-primitives = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v55" } +#revm = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v55" } +#revm-interpreter = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v55" } +#revm-precompile = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v55" } +#revm-primitives = { git = "https://github.com/scroll-tech/revm", branch = "scroll-evm-executor/v55" } ruint = { git = "https://github.com/scroll-tech/uint.git", branch = "v1.12.3" } diff --git a/conf/config.json b/conf/config.json index bf9002d..46ed259 100644 --- a/conf/config.json +++ b/conf/config.json @@ -1,38 +1,23 @@ { - "prover_name_prefix": "prover_name", - "keys_dir": "keys", - "coordinator": { - "base_url": "https://coordinator-api.scrollsdk", - "retry_count": 3, - "retry_wait_time_sec": 5, - "connection_timeout_sec": 60 - }, - "l2geth": { - "endpoint": "https://l2-rpc.scrollsdk" - }, - "prover": { - "circuit_type": [1,2,3], - "circuit_version": "v0.13.1", - "cloud": { - "base_url": "", - "api_key": "", - "retry_count": 3, - "retry_wait_time_sec": 5, - "connection_timeout_sec": 60 - }, - "local": { - "low_version_circuit": { - "hard_fork_name": "bernoulli", - "params_path": "params", - "assets_path": "assets" - }, - "high_version_circuit": { - "hard_fork_name": "curie", - "params_path": "params", - "assets_path": "assets" - } - } - }, - "db_path": "db" - } - \ No newline at end of file + "prover_name_prefix": "prover_name", + "keys_dir": "keys", + "coordinator": { + "base_url": "http://localhost:8555", + "retry_count": 10, + "retry_wait_time_sec": 10, + "connection_timeout_sec": 30 + }, + "l2geth": { + "endpoint": "http://localhost:9999" + }, + "prover": { + "circuit_type": 2, + "supported_proof_types": [ + 1, + 2, + 3 + ], + "circuit_version": "v0.13.1" + }, + "db_path": "db" +} diff --git a/src/coordinator_handler/api.rs b/src/coordinator_handler/api.rs index ac39cf9..6c80c73 100644 --- a/src/coordinator_handler/api.rs +++ b/src/coordinator_handler/api.rs @@ -49,9 +49,10 @@ impl Api { { let url = self.build_url(method)?; let request_body = serde_json::to_string(req)?; + let size = request_body.len(); log::info!("[coordinator client], {method}, sent request"); - log::debug!("[coordinator client], {method}, request: {request_body}"); + log::debug!("[coordinator client], {method}, request: {request_body}, token: {token}, request size: {size}"); let response = self .client .post(url) @@ -63,10 +64,6 @@ impl Api { .await?; if response.status() != http::status::StatusCode::OK { - // log::error!( - // "[coordinator client], {method}, status not ok: {}", - // response.status() - // ); anyhow::bail!( "[coordinator client], {method}, status not ok: {}", response.status() diff --git a/src/coordinator_handler/types.rs b/src/coordinator_handler/types.rs index 87de37b..4dafc68 100644 --- a/src/coordinator_handler/types.rs +++ b/src/coordinator_handler/types.rs @@ -126,6 +126,8 @@ pub struct GetTaskResponseData { #[derive(Debug, Clone, Deserialize)] pub struct ChunkTaskDetail { pub block_hashes: Vec, + pub prev_msg_queue_hash: CommonHash, + pub fork_name: String, } #[derive(Serialize, Deserialize)] // TODO: Default? diff --git a/src/db.rs b/src/db.rs index 39c02b3..4919d1c 100644 --- a/src/db.rs +++ b/src/db.rs @@ -12,6 +12,7 @@ impl Db { } pub fn get_task(&self, public_key: String) -> (Option, Option) { + log::debug!("[db], get task, public_key: {public_key}"); ( self.get_coordinator_task_by_public_key(public_key.clone()), self.get_proving_task_id_by_public_key(public_key), @@ -24,6 +25,7 @@ impl Db { coordinator_task: &GetTaskResponseData, proving_task_id: String, ) { + log::debug!("[db], set task, public_key: {public_key}"); self.set_coordinator_task_by_public_key(public_key.clone(), coordinator_task); self.set_proving_task_id_by_public_key(public_key, proving_task_id); } diff --git a/src/prover/builder.rs b/src/prover/builder.rs index 38596ea..92a6acd 100644 --- a/src/prover/builder.rs +++ b/src/prover/builder.rs @@ -62,7 +62,12 @@ where let key_signers: Result, _> = (0..self.cfg.prover.n_workers) .map(|i| { - let key_path = PathBuf::from(&self.cfg.keys_dir).join(i.to_string()); + let keys_dir = PathBuf::from(&self.cfg.keys_dir); + if !keys_dir.exists() { + std::fs::create_dir_all(&keys_dir) + .map_err(|e| anyhow::anyhow!("failed to create keys directory {}: {e}", keys_dir.display()))?; + } + let key_path = keys_dir.join(i.to_string()); KeySigner::new(&key_path) }) .collect(); diff --git a/src/prover/mod.rs b/src/prover/mod.rs index 3c807a7..ac54ca7 100644 --- a/src/prover/mod.rs +++ b/src/prover/mod.rs @@ -9,7 +9,6 @@ use crate::{ db::Db, tracing_handler::L2gethClient, }; -use anyhow::bail; use axum::{routing::get, Router}; use ethers_core::types::H256; use ethers_providers::Middleware; @@ -97,6 +96,8 @@ where .db .get_task(coordinator_client.key_signer.get_public_key()) { + let task_id = coordinator_task.clone().task_id; + log::debug!("got previous task from db, task_id: {task_id}"); if self.proving_service.read().await.is_local() { let proving_task = self.request_proving(&coordinator_task).await?; proving_task_id = proving_task.task_id @@ -116,7 +117,7 @@ where &self, coordinator_client: &CoordinatorClient, ) -> anyhow::Result { - let get_task_request = self.build_get_task_request().await; + let get_task_request = self.build_get_task_request().await?; let coordinator_task = coordinator_client.get_task(&get_task_request).await?; if coordinator_task.errcode != ErrorCode::Success { @@ -275,7 +276,7 @@ where error = ?e, "Failed to submit proof due to a http error" ); - return Ok(()) + return Ok(()); } }; @@ -303,19 +304,21 @@ where Ok(()) } - async fn build_get_task_request(&self) -> GetTaskRequest { + async fn build_get_task_request(&self) -> anyhow::Result { let prover_height = match &self.l2geth_client { None => None, Some(l2geth_client) => match l2geth_client.block_number().await { Ok(block_number) => block_number.as_number().map(|num| num.as_u64()), - Err(_) => None, + Err(e) => { + anyhow::bail!("Failed get block number height. err: {:?}", e); + } }, }; - GetTaskRequest { + Ok(GetTaskRequest { task_types: self.proof_types.clone(), prover_height, - } + }) } async fn build_proving_input( @@ -350,12 +353,18 @@ where } ProofType::Chunk => { let chunk_task_detail: ChunkTaskDetail = serde_json::from_str(&task.task_data)?; - let serialized_traces = self + let serialized_traces = match self .l2geth_client .as_ref() .unwrap() .get_traces_by_hashes(&chunk_task_detail.block_hashes) - .await?; + .await + { + Ok(traces) => traces, + Err(e) => { + anyhow::bail!("Failed to get traces by hashes: {:?}", e); + } + }; // Note: Manually join pre-serialized traces since they are already in JSON format. // Using serde_json::to_string would escape the JSON strings, creating invalid nested JSON. let input = format!("[{}]", serialized_traces.join(",")); @@ -381,17 +390,32 @@ where match task.task_type { ProofType::Chunk => { let chunk_task_detail: ChunkTaskDetail = serde_json::from_str(&task.task_data)?; - let mut witnesses = vec![]; + let mut block_witnesses = vec![]; for block_hash in chunk_task_detail.block_hashes { - witnesses.push(self.build_block_witness(block_hash).await?); + match self.build_block_witness(block_hash).await { + Ok(witness) => block_witnesses.push(witness), + Err(e) => { + anyhow::bail!( + "Failed to build block witness for hash {:?}: {:?}", + block_hash, + e + ); + } + }; } - witnesses.sort_by(|a, b| a.header.number.cmp(&b.header.number)); + block_witnesses.sort_by(|a, b| a.header.number.cmp(&b.header.number)); + + let input_map = serde_json::json!({ + "block_witnesses": block_witnesses, + "prev_msg_queue_hash": chunk_task_detail.prev_msg_queue_hash, + "fork_name": chunk_task_detail.fork_name, + }); Ok(ProveRequest { proof_type: task.task_type, circuit_version: self.circuit_version.clone(), hard_fork_name: task.hard_fork_name.clone(), - input: serde_json::to_string(&witnesses)?, + input: serde_json::to_string(&input_map)?, }) } ProofType::Batch | ProofType::Bundle => Ok(ProveRequest { @@ -400,7 +424,7 @@ where hard_fork_name: task.hard_fork_name.clone(), input: task.task_data.clone(), }), - _ => bail!("unsupported task type: {:?}", task.task_type), + _ => anyhow::bail!("unsupported task type: {:?}", task.task_type), } } @@ -420,10 +444,61 @@ where let block_num = block.number.expect("block hash without number").as_u64(); let provider = - alloy::providers::ProviderBuilder::<_, _, sbv_primitives::Network>::default() + alloy::providers::ProviderBuilder::<_, _, sbv_primitives::types::Network>::default() .on_http(client.provider.provider().url().clone()); let witness = provider.dump_block_witness(block_num.into()).await?; witness.ok_or_else(|| anyhow::anyhow!("Failed to dump block witness")) } } + +#[cfg(test)] +mod tests { + use crate::config::Config; + use crate::prover::{ + proving_service::{ + GetVkRequest, GetVkResponse, ProveRequest, ProveResponse, QueryTaskRequest, + QueryTaskResponse, + }, + ProverBuilder, ProvingService, + }; + use async_trait::async_trait; + use tokio; + + struct MockProver {} + + #[async_trait] + impl ProvingService for MockProver { + fn is_local(&self) -> bool { + true + } + async fn get_vks(&self, _: GetVkRequest) -> GetVkResponse { + GetVkResponse { + ..Default::default() + } + } + async fn prove(&mut self, _: ProveRequest) -> ProveResponse { + ProveResponse { + ..Default::default() + } + } + async fn query_task(&mut self, _: QueryTaskRequest) -> QueryTaskResponse { + QueryTaskResponse { + ..Default::default() + } + } + } + + #[tokio::test] + async fn test_build_get_task_request() { + let cfg = Config::from_file("conf/config.json".to_string()).unwrap(); + let prover_service = MockProver {}; + let prover = ProverBuilder::new(cfg, prover_service) + .build() + .await + .unwrap(); + + let get_task_request = prover.build_get_task_request().await; + assert!(get_task_request.is_err()) + } +} diff --git a/src/prover/proving_service.rs b/src/prover/proving_service.rs index 78a4afb..4d9e26d 100644 --- a/src/prover/proving_service.rs +++ b/src/prover/proving_service.rs @@ -9,17 +9,19 @@ pub trait ProvingService { async fn query_task(&mut self, req: QueryTaskRequest) -> QueryTaskResponse; } +#[derive(Default)] pub struct GetVkRequest { pub proof_types: Vec, pub circuit_version: String, } +#[derive(Default)] pub struct GetVkResponse { pub vks: Vec, pub error: Option, } -#[derive(Clone)] +#[derive(Default, Clone)] pub struct ProveRequest { pub proof_type: ProofType, pub circuit_version: String, @@ -44,6 +46,7 @@ pub struct ProveResponse { pub error: Option, } +#[derive(Default)] pub struct QueryTaskRequest { pub task_id: String, } diff --git a/src/tracing_handler.rs b/src/tracing_handler.rs index 3676b54..dec9eaa 100644 --- a/src/tracing_handler.rs +++ b/src/tracing_handler.rs @@ -32,8 +32,10 @@ impl L2gethClient { pub async fn block_number(&self) -> anyhow::Result { log::info!("l2geth_client calling block_number"); - let trace = self.provider.request("eth_blockNumber", ()).await?; - Ok(trace) + let block_number = self.provider.request("eth_blockNumber", ()).await?; + log::info!("l2geth_client received block_number: {:#?}", block_number); + + Ok(block_number) } pub async fn get_traces_by_hashes(