pub trait ParallelPowGenerator: Send + Sync {
// Required methods
fn generate_best_effort<'life0, 'life1, 'async_trait>(
&'life0 self,
label: &'life1 str,
iteration_limit: usize,
pow_min: Pow,
data_hash: Hash,
) -> Pin<Box<dyn Future<Output = Result<(Salt, Pow, Hash)>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn generate<'life0, 'life1, 'async_trait>(
&'life0 self,
label: &'life1 str,
pow_min: Pow,
data_hash: Hash,
) -> Pin<Box<dyn Future<Output = Result<(Salt, Pow, Hash)>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn active_jobs(&self) -> Vec<PowJobStatus>;
}Expand description
A pluggable engine for searching for proof-of-work solutions in parallel.
Proof-of-work is required on every RPC packet, on peer announcements, and on report /
feedback submissions, so finding PoW is on the hot path for every outbound action a client
or server takes. ParallelPowGenerator abstracts over the concrete way we parallelize that
search so the calling code stays platform-agnostic:
NativeParallelPowGeneratorusesrayon+tokio::task::spawn_blockingto pin the search across all CPU cores on native targets.StubParallelPowGeneratoris a single-threaded fallback that works on every target, including WASM. Browser clients use this (with a relaxedpow_min) because Web Workers do not exposerayon/ threads directly.
Implementations must also maintain the active_jobs() observability view — the UI surfaces
in-progress PoW searches to end users so they understand why an action is slow.
Required Methods§
Sourcefn generate_best_effort<'life0, 'life1, 'async_trait>(
&'life0 self,
label: &'life1 str,
iteration_limit: usize,
pow_min: Pow,
data_hash: Hash,
) -> Pin<Box<dyn Future<Output = Result<(Salt, Pow, Hash)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn generate_best_effort<'life0, 'life1, 'async_trait>(
&'life0 self,
label: &'life1 str,
iteration_limit: usize,
pow_min: Pow,
data_hash: Hash,
) -> Pin<Box<dyn Future<Output = Result<(Salt, Pow, Hash)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Run up to iteration_limit hash attempts and return the best (Salt, Pow, Hash) found.
Exits early if pow >= pow_min is achieved.
label is a human-readable job name for observability (e.g. "rpc", "feedback").
data_hash must be pre-computed via pow_compute_data_hash before calling.
Sourcefn generate<'life0, 'life1, 'async_trait>(
&'life0 self,
label: &'life1 str,
pow_min: Pow,
data_hash: Hash,
) -> Pin<Box<dyn Future<Output = Result<(Salt, Pow, Hash)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn generate<'life0, 'life1, 'async_trait>(
&'life0 self,
label: &'life1 str,
pow_min: Pow,
data_hash: Hash,
) -> Pin<Box<dyn Future<Output = Result<(Salt, Pow, Hash)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Loop generate_best_effort in batches until pow >= pow_min is achieved.
Sourcefn active_jobs(&self) -> Vec<PowJobStatus>
fn active_jobs(&self) -> Vec<PowJobStatus>
Snapshot of all concurrently in-flight generate calls.