Skip to content

Commit

Permalink
feat: proving use spawn_blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
yiweichi committed Jan 17, 2025
1 parent bf52b88 commit 820dbc8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
2 changes: 1 addition & 1 deletion prover/Cargo.lock

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

2 changes: 1 addition & 1 deletion prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "v1.
snark-verifier-sdk = { git = "https://github.com/scroll-tech/snark-verifier", branch = "develop", default-features = false, features = ["loader_halo2", "loader_evm", "halo2-pse"] }
prover_darwin = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.12.2", package = "prover", default-features = false, features = ["parallel_syn", "scroll"] }
prover_darwin_v2 = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.13.1", package = "prover", default-features = false, features = ["parallel_syn", "scroll"] }
scroll-proving-sdk = { git = "https://github.com/scroll-tech/scroll-proving-sdk.git", rev = "e29b98d"}
scroll-proving-sdk = { git = "https://github.com/scroll-tech/scroll-proving-sdk.git", rev = "4ae7687"}
base64 = "0.13.1"
reqwest = { version = "0.12.4", features = ["gzip"] }
reqwest-middleware = "0.3"
Expand Down
34 changes: 10 additions & 24 deletions prover/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pub struct LocalProver {
circuits_handler_provider: RwLock<CircuitsHandlerProvider>,
next_task_id: Arc<Mutex<u64>>,
current_task: Arc<Mutex<Option<JoinHandle<Result<String>>>>>,
// result: Arc<Mutex<Result<String>>>,
}

#[async_trait]
Expand Down Expand Up @@ -75,11 +74,7 @@ impl ProvingService for LocalProver {
}

async fn query_task(&self, req: QueryTaskRequest) -> QueryTaskResponse {
let handle = {
let mut current_task = self.current_task.lock().unwrap();
current_task.take()
};

let handle = self.current_task.lock().unwrap().take();
if let Some(handle) = handle {
if handle.is_finished() {
match handle.await {
Expand All @@ -94,34 +89,26 @@ impl ProvingService for LocalProver {
req.task_id,
TaskStatus::Failed,
None,
Some(e.to_string()),
Some(format!("proving task failed: {}", e)),
),
},
Err(_) => build_query_task_response(
Err(e) => build_query_task_response(
req.task_id,
TaskStatus::Failed,
None,
Some("Task panicked".to_string()),
Some(format!("proving task panicked: {}", e)),
),
}
} else {
{
let mut current_task = self.current_task.lock().unwrap();
*current_task = Some(handle);
}
build_query_task_response(
req.task_id,
TaskStatus::Proving,
None,
None,
)
*self.current_task.lock().unwrap() = Some(handle);
build_query_task_response(req.task_id, TaskStatus::Proving, None, None)
}
} else {
build_query_task_response(
req.task_id,
TaskStatus::Failed,
None,
Some("No task running".to_string()),
Some("no proving task is running".to_string()),
)
}
}
Expand Down Expand Up @@ -159,10 +146,9 @@ impl LocalProver {

let req_clone = req.clone();
let handle = Handle::current();
let task_handle = tokio::task::spawn_blocking(move || {
handle.block_on(handler.get_proof_data(req_clone))
});

let task_handle =
tokio::task::spawn_blocking(move || handle.block_on(handler.get_proof_data(req_clone)));

*self.current_task.lock().unwrap() = Some(task_handle);

Ok(ProveResponse {
Expand Down

0 comments on commit 820dbc8

Please sign in to comment.