From f958c9c8e83e24dcade90e2c11eca50ea814d7f0 Mon Sep 17 00:00:00 2001 From: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com> Date: Fri, 27 Sep 2024 16:18:32 +1000 Subject: [PATCH] feat: add `GetVkResponse` (#16) --- examples/cloud.rs | 10 +++++----- examples/local.rs | 6 +++--- src/config.rs | 2 +- src/prover/builder.rs | 7 +++++-- src/prover/proving_service.rs | 11 ++++++++--- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/examples/cloud.rs b/examples/cloud.rs index df59545..0cc34ed 100644 --- a/examples/cloud.rs +++ b/examples/cloud.rs @@ -1,11 +1,11 @@ use clap::Parser; -use std::sync::Arc; use scroll_proving_sdk::{ config::{CloudProverConfig, Config}, prover::{ proving_service::{ - GetVkRequest, ProveRequest, ProveResponse, QueryTaskRequest, QueryTaskResponse, + GetVkRequest, GetVkResponse, ProveRequest, ProveResponse, QueryTaskRequest, + QueryTaskResponse, }, ProverBuilder, ProvingService, }, @@ -21,7 +21,7 @@ struct Args { } struct CloudProver { - endpoint: String, + base_url: String, api_key: String, } @@ -29,7 +29,7 @@ impl ProvingService for CloudProver { fn is_local(&self) -> bool { false } - fn get_vk(&self, req: GetVkRequest) -> String { + fn get_vk(&self, req: GetVkRequest) -> GetVkResponse { todo!() } fn prove(&self, req: ProveRequest) -> ProveResponse { @@ -43,7 +43,7 @@ impl ProvingService for CloudProver { impl CloudProver { pub fn new(cfg: CloudProverConfig) -> Self { Self { - endpoint: cfg.endpoint, + base_url: cfg.base_url, api_key: cfg.api_key, } } diff --git a/examples/local.rs b/examples/local.rs index b913150..4f25b3b 100644 --- a/examples/local.rs +++ b/examples/local.rs @@ -1,11 +1,11 @@ use clap::Parser; -use std::sync::Arc; use scroll_proving_sdk::{ config::{Config, LocalProverConfig}, prover::{ proving_service::{ - GetVkRequest, ProveRequest, ProveResponse, QueryTaskRequest, QueryTaskResponse, + GetVkRequest, GetVkResponse, ProveRequest, ProveResponse, QueryTaskRequest, + QueryTaskResponse, }, ProverBuilder, ProvingService, }, @@ -26,7 +26,7 @@ impl ProvingService for LocalProver { fn is_local(&self) -> bool { true } - fn get_vk(&self, req: GetVkRequest) -> String { + fn get_vk(&self, req: GetVkRequest) -> GetVkResponse { todo!() } fn prove(&self, req: ProveRequest) -> ProveResponse { diff --git a/src/config.rs b/src/config.rs index e25320e..29291d2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -36,7 +36,7 @@ pub struct ProverConfig { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct CloudProverConfig { - pub endpoint: String, + pub base_url: String, pub api_key: String, } diff --git a/src/prover/builder.rs b/src/prover/builder.rs index f4036e1..a10f51d 100644 --- a/src/prover/builder.rs +++ b/src/prover/builder.rs @@ -47,11 +47,14 @@ impl ProverBuilder { circuit_type: self.cfg.prover.circuit_type, circuit_version: self.cfg.prover.circuit_version.clone(), }; - let vk = self + let get_vk_response = self .proving_service .as_ref() .unwrap() .get_vk(get_vk_request); + if let Some(error) = get_vk_response.error { + anyhow::bail!("failed to get vk: {}", error); + } let key_signers: Result, _> = (0..self.cfg.prover.n_workers) .map(|i| { @@ -66,7 +69,7 @@ impl ProverBuilder { CoordinatorClient::new( self.cfg.coordinator.clone(), self.cfg.prover.circuit_type, - vec![vk.clone()], + vec![get_vk_response.vk.clone()], self.cfg.prover.circuit_version.clone(), format!("{}{}", self.cfg.prover_name_prefix, i), key_signers[i].clone(), diff --git a/src/prover/proving_service.rs b/src/prover/proving_service.rs index eb04f8f..19f2e76 100644 --- a/src/prover/proving_service.rs +++ b/src/prover/proving_service.rs @@ -2,9 +2,9 @@ use super::CircuitType; pub trait ProvingService { fn is_local(&self) -> bool; - fn get_vk(&self, req: GetVkRequest) -> String; // TODO: Result - fn prove(&self, req: ProveRequest) -> ProveResponse; // TODO: Result - fn query_task(&self, req: QueryTaskRequest) -> QueryTaskResponse; // TODO: Result + fn get_vk(&self, req: GetVkRequest) -> GetVkResponse; + fn prove(&self, req: ProveRequest) -> ProveResponse; + fn query_task(&self, req: QueryTaskRequest) -> QueryTaskResponse; } pub struct GetVkRequest { @@ -12,6 +12,11 @@ pub struct GetVkRequest { pub circuit_version: String, } +pub struct GetVkResponse { + pub vk: String, + pub error: Option, +} + pub struct ProveRequest { pub circuit_type: CircuitType, pub circuit_version: String,