Skip to main content

Module parallel_pow_generator

Module parallel_pow_generator 

Source
Expand description

§Parallel proof-of-work search engine

Proof-of-work is mandatory on every outgoing RPC, every peer announcement, and every piece of report/feedback — so finding a PoW solution quickly is on the hot path for virtually every client and server action. This module isolates that work behind a single trait, ParallelPowGenerator, so the calling code doesn’t care whether it’s running on a 32-core server or a single-threaded WASM Web Worker.

§Implementations

  • NativeParallelPowGenerator — rayon + tokio::task::spawn_blocking, saturates every CPU core on native targets.
  • StubParallelPowGenerator — single-threaded fallback that works on every target including WASM. Browser clients run this (with a relaxed pow_min) because Web Workers don’t expose thread pools.

§Observability

JobTracker + PowJobStatus expose the set of in-flight PoW jobs and the best-so-far pow for each. The web client surfaces this in the UI so that when a post feels slow to send the user can see it’s because PoW is still grinding.

§Shared loop

generate_loop is the one-true batching loop used by both implementations: repeatedly call ParallelPowGenerator::generate_best_effort in 64K-attempt batches, update the tracker, and bail as soon as a batch returns pow >= pow_min. Every batch also yields to the runtime so on single-threaded targets other tasks still get a chance to run.

Structs§

JobTracker
NativeParallelPowGenerator
PowJobStatus
StubParallelPowGenerator

Traits§

ParallelPowGenerator
A pluggable engine for searching for proof-of-work solutions in parallel.

Functions§

generate_loop
Shared loop logic for generate: repeatedly calls generate_best_effort in BATCH_SIZE batches until pow >= pow_min, tracking progress via JobTracker.