refactor: move block_on helper to crate ere-zkvm-interface behind tokio feature gate

This commit is contained in:
han0110
2026-02-16 11:42:10 +00:00
parent e76f9871e7
commit 1aa23405da
10 changed files with 48 additions and 59 deletions

3
Cargo.lock generated
View File

@@ -4303,7 +4303,6 @@ dependencies = [
"sp1-sdk",
"tempfile",
"thiserror 2.0.12",
"tokio",
"tracing",
]
@@ -4355,7 +4354,6 @@ dependencies = [
"strum 0.27.2",
"tempfile",
"thiserror 2.0.12",
"tokio",
"tonic 0.14.3",
"tracing",
"uuid 1.17.0",
@@ -4377,6 +4375,7 @@ dependencies = [
"serde_yaml",
"strum 0.27.2",
"thiserror 2.0.12",
"tokio",
"toml 0.8.23",
]

View File

@@ -10,11 +10,11 @@ anyhow.workspace = true
serde = { workspace = true, features = ["derive"] }
tempfile.workspace = true
thiserror.workspace = true
tokio = { workspace = true, features = ["rt-multi-thread"] }
tokio.workspace = true
tracing.workspace = true
# Local dependencies
ere-zkvm-interface = { workspace = true, features = ["clap"] }
ere-zkvm-interface = { workspace = true, features = ["clap", "tokio"] }
ere-common.workspace = true
ere-server.workspace = true

View File

@@ -16,18 +16,14 @@ use ere_server::{
api::twirp::reqwest::Client,
client::{self, Url, zkVMClient},
};
use ere_zkvm_interface::{
CommonError,
zkvm::{
Input, ProgramExecutionReport, ProgramProvingReport, Proof, ProofKind, ProverResource,
PublicValues, zkVM,
},
use ere_zkvm_interface::zkvm::{
CommonError, Input, ProgramExecutionReport, ProgramProvingReport, Proof, ProofKind,
ProverResource, PublicValues, block_on, zkVM,
};
use std::{
future::Future,
iter,
pin::Pin,
sync::OnceLock,
time::{Duration, Instant},
};
use tempfile::TempDir;
@@ -464,18 +460,6 @@ async fn wait_until_healthy(endpoint: &Url, http_client: Client) -> Result<(), E
}
}
fn block_on<T>(future: impl Future<Output = T>) -> T {
match tokio::runtime::Handle::try_current() {
Ok(handle) => tokio::task::block_in_place(|| handle.block_on(future)),
Err(_) => {
static FALLBACK_RT: OnceLock<tokio::runtime::Runtime> = OnceLock::new();
FALLBACK_RT
.get_or_init(|| tokio::runtime::Runtime::new().expect("Failed to create runtime"))
.block_on(future)
}
}
}
#[cfg(test)]
mod test {
use crate::{

View File

@@ -16,6 +16,7 @@ thiserror.workspace = true
# Optional dependencies
clap = { workspace = true, features = ["derive"], optional = true }
tokio = { workspace = true, features = ["rt-multi-thread"], optional = true }
[dev-dependencies]
bincode = { workspace = true, features = ["alloc", "serde"] }
@@ -29,3 +30,4 @@ workspace = true
[features]
default = []
clap = ["dep:clap"]
tokio = ["dep:tokio"]

View File

@@ -8,11 +8,17 @@ mod proof;
mod report;
mod resource;
#[cfg(feature = "tokio")]
mod tokio;
pub use error::CommonError;
pub use proof::{Proof, ProofKind};
pub use report::{ProgramExecutionReport, ProgramProvingReport};
pub use resource::{ProverResource, ProverResourceKind, RemoteProverConfig};
#[cfg(feature = "tokio")]
pub use tokio::block_on;
/// Input for the prover to execute/prove a guest program.
#[derive(Clone, Debug, Default)]
pub struct Input {

View File

@@ -0,0 +1,14 @@
use std::sync::OnceLock;
/// Run a future to completion, reusing the current tokio runtime or creating one.
pub fn block_on<T>(future: impl Future<Output = T>) -> T {
match tokio::runtime::Handle::try_current() {
Ok(handle) => tokio::task::block_in_place(|| handle.block_on(future)),
Err(_) => {
static FALLBACK_RT: OnceLock<tokio::runtime::Runtime> = OnceLock::new();
FALLBACK_RT
.get_or_init(|| tokio::runtime::Runtime::new().expect("Failed to create runtime"))
.block_on(future)
}
}
}

View File

@@ -11,7 +11,6 @@ bincode = { workspace = true, features = ["alloc", "serde"] }
serde.workspace = true
tempfile.workspace = true
thiserror.workspace = true
tokio = { workspace = true, features = ["rt-multi-thread"], optional = true }
tracing.workspace = true
# SP1 dependencies
@@ -34,7 +33,14 @@ ere-build-utils.workspace = true
[features]
default = ["compiler", "zkvm"]
compiler = ["dep:ere-compile-utils"]
zkvm = ["dep:tokio", "dep:sp1-cuda", "dep:sp1-hypercube", "dep:sp1-p3-field", "dep:sp1-recursion-executor", "dep:sp1-sdk"]
zkvm = [
"dep:sp1-cuda",
"dep:sp1-hypercube",
"dep:sp1-p3-field",
"dep:sp1-recursion-executor",
"dep:sp1-sdk",
"ere-zkvm-interface/tokio",
]
[lints]
workspace = true

View File

@@ -2,10 +2,10 @@ use crate::{program::SP1Program, zkvm::sdk::SP1Sdk};
use anyhow::bail;
use ere_zkvm_interface::zkvm::{
CommonError, Input, ProgramExecutionReport, ProgramProvingReport, Proof, ProofKind,
ProverResource, PublicValues, zkVM, zkVMProgramDigest,
ProverResource, PublicValues, block_on, zkVM, zkVMProgramDigest,
};
use sp1_sdk::{SP1ProofMode, SP1ProofWithPublicValues, SP1Stdin, SP1VerifyingKey};
use std::{future::Future, sync::OnceLock, time::Instant};
use std::time::Instant;
use tracing::info;
mod error;
@@ -129,18 +129,6 @@ fn input_to_stdin(input: &Input) -> Result<SP1Stdin, Error> {
Ok(stdin)
}
fn block_on<T>(future: impl Future<Output = T>) -> T {
match tokio::runtime::Handle::try_current() {
Ok(handle) => tokio::task::block_in_place(|| handle.block_on(future)),
Err(_) => {
static FALLBACK_RT: OnceLock<tokio::runtime::Runtime> = OnceLock::new();
FALLBACK_RT
.get_or_init(|| tokio::runtime::Runtime::new().expect("Failed to create runtime"))
.block_on(future)
}
}
}
#[cfg(test)]
mod tests {
use crate::{compiler::RustRv32imaCustomized, program::SP1Program, zkvm::EreSP1};

View File

@@ -16,8 +16,7 @@ serde.workspace = true
strum = { workspace = true, features = ["derive"] }
tempfile.workspace = true
thiserror.workspace = true
tokio = { workspace = true, features = ["rt-multi-thread"] }
tonic.workspace = true
tonic = { workspace = true, optional = true }
tracing.workspace = true
uuid = { workspace = true, features = ["v4"] }
wait-timeout.workspace = true
@@ -27,8 +26,8 @@ ere-compile-utils = { workspace = true, optional = true }
ere-zkvm-interface.workspace = true
# Zisk dependencies
zisk-distributed-grpc-api.workspace = true
zisk-proofman-verifier.workspace = true
zisk-distributed-grpc-api = { workspace = true, optional = true }
zisk-proofman-verifier = { workspace = true, optional = true }
[dev-dependencies]
ere-test-utils = { workspace = true, features = ["host"] }
@@ -39,7 +38,12 @@ ere-build-utils.workspace = true
[features]
default = ["compiler", "zkvm"]
compiler = ["dep:ere-compile-utils"]
zkvm = []
zkvm = [
"dep:tonic",
"dep:zisk-distributed-grpc-api",
"dep:zisk-proofman-verifier",
"ere-zkvm-interface/tokio",
]
[lints]
workspace = true

View File

@@ -1,9 +1,8 @@
//! Remote ZisK cluster proving.
use crate::zkvm::Error;
use ere_zkvm_interface::zkvm::RemoteProverConfig;
use ere_zkvm_interface::zkvm::{RemoteProverConfig, block_on};
use futures_util::StreamExt;
use std::sync::OnceLock;
use std::time::Duration;
use tonic::transport::Channel;
use tracing::debug;
@@ -154,19 +153,6 @@ async fn connect(endpoint: &str) -> Result<ZiskDistributedApiClient<Channel>, Er
Ok(ZiskDistributedApiClient::new(channel))
}
/// Run a future to completion, reusing the current tokio runtime or creating one.
fn block_on<T>(future: impl Future<Output = T>) -> T {
match tokio::runtime::Handle::try_current() {
Ok(handle) => tokio::task::block_in_place(|| handle.block_on(future)),
Err(_) => {
static FALLBACK_RT: OnceLock<tokio::runtime::Runtime> = OnceLock::new();
FALLBACK_RT
.get_or_init(|| tokio::runtime::Runtime::new().expect("Failed to create runtime"))
.block_on(future)
}
}
}
/// Returns `Error::ClusterError`.
fn cluster_error(s: impl ToString) -> Error {
Error::ClusterError(s.to_string())