fix: no duplicate work when exceeding hardcoded int (#36)

* fix: no duplicate work when exceeding that 1xxx number

* run go generate and update CHANGELOG

Signed-off-by: Xe Iaso <me@xeiaso.net>

---------

Signed-off-by: Xe Iaso <me@xeiaso.net>
Co-authored-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
Donatas 2025-03-20 22:20:53 +02:00 committed by GitHub
parent 3e9a93f629
commit eeaed6a317
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 11 additions and 8 deletions

View file

@ -25,7 +25,8 @@ export function process(data, difficulty = 5, threads = navigator.hardwareConcur
worker.postMessage({
data,
difficulty,
nonce: 1000000 * i,
nonce: i,
threads,
});
workers.push(worker);
@ -52,10 +53,11 @@ function processTask() {
let data = event.data.data;
let difficulty = event.data.difficulty;
let hash;
let nonce = event.data.nonce || 0;
let nonce = event.data.nonce;
let threads = event.data.threads;
while (true) {
const currentHash = await sha256(data + nonce++);
const currentHash = await sha256(data + nonce);
const thisHash = new Uint8Array(currentHash);
let valid = true;
@ -76,9 +78,9 @@ function processTask() {
console.log(hash);
break;
}
}
nonce -= 1; // last nonce was post-incremented
nonce += threads;
}
postMessage({
hash,