smolgrrr / Wired

The Wired- unstoppable free speech
https://getwired.app
24 stars 6 forks source link

PoW note gen is really slow at high difficulties #2

Closed smolgrrr closed 1 year ago

smolgrrr commented 1 year ago

Maybe this can fix?

const worker1 = new Worker("./worker");
const worker2 = new Worker("./worker");
const worker3 = new Worker("./worker");
const worker4 = new Worker("./worker");

worker1.onmessage = handleResult;
worker2.onmessage = handleResult;
worker3.onmessage = handleResult;
worker4.onmessage = handleResult;

worker1.postMessage({ startNonce: 0, endNonce: 250, ...otherData });
worker2.postMessage({ startNonce: 251, endNonce: 500, ...otherData });
worker3.postMessage({ startNonce: 501, endNonce: 750, ...otherData });
worker4.postMessage({ startNonce: 751, endNonce: 1000, ...otherData });

function handleResult(event) {
  const { result } = event.data;
  if (resultFound(result)) {
    // If a valid nonce is found, terminate all workers
    worker1.terminate();
    worker2.terminate();
    worker3.terminate();
    worker4.terminate();

    // Continue with the result
  }
}
smolgrrr commented 1 year ago

aaaaaaaaaaaaaa

smolgrrr commented 1 year ago

fixed