1//! Asynchronous verification of cryptographic primitives.
23use tokio::sync::oneshot::error::RecvError;
45use crate::BoxError;
67pub mod ed25519;
8pub mod groth16;
9pub mod halo2;
10pub mod redjubjub;
11pub mod redpallas;
1213/// The maximum batch size for any of the batch verifiers.
14const MAX_BATCH_SIZE: usize = 64;
1516/// The maximum latency bound for any of the batch verifiers.
17const MAX_BATCH_LATENCY: std::time::Duration = std::time::Duration::from_millis(100);
1819/// Fires off a task into the Rayon threadpool, awaits the result through a oneshot channel,
20/// then converts the error to a [`BoxError`].
21pub async fn spawn_fifo_and_convert<
22 E: 'static + std::error::Error + Into<BoxError> + Sync + Send,
23 F: 'static + FnOnce() -> Result<(), E> + Send,
24>(
25 f: F,
26) -> Result<(), BoxError> {
27 spawn_fifo(f)
28 .await
29.map_err(|_| {
30"threadpool unexpectedly dropped response channel sender. Is Zebra shutting down?"
31})?
32.map_err(BoxError::from)
33}
3435/// Fires off a task into the Rayon threadpool and awaits the result through a oneshot channel.
36pub async fn spawn_fifo<
37 E: 'static + std::error::Error + Sync + Send,
38 F: 'static + FnOnce() -> Result<(), E> + Send,
39>(
40 f: F,
41) -> Result<Result<(), E>, RecvError> {
42// Rayon doesn't have a spawn function that returns a value,
43 // so we use a oneshot channel instead.
44let (rsp_tx, rsp_rx) = tokio::sync::oneshot::channel();
4546 rayon::spawn_fifo(move || {
47let _ = rsp_tx.send(f());
48 });
4950 rsp_rx.await
51}