Skip to main content

generate_loop

Function generate_loop 

Source
pub async fn generate_loop(
    generator: &(dyn ParallelPowGenerator + '_),
    tracker: &Arc<Mutex<JobTracker>>,
    label: &str,
    pow_min: Pow,
    data_hash: Hash,
) -> Result<(Salt, Pow, Hash)>
Expand description

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

Future optimization: the current batch-and-wait approach dispatches to all N workers, then waits for all N to respond before dispatching the next batch. This means fast workers sit idle while the slowest worker finishes. A better design would feed workers individually as they complete (work-stealing / pool-style), maintaining a shared “best result so far” per job and checking pow_min after each worker result. This would also allow concurrent generate() calls to have their batches truly interleaved at the individual-worker level rather than at the batch level.