fix(worker): constrain nonce value to be a whole integer (#1045)
* fix(worker): constrain nonce value to be a whole integer Closes #1043 Sometimes the worker could get into a strange state where it has a decimal nonce, but the server assumes that the nonce can only be a whole number. This patch constrains the nonce to be a whole number on the worker end by detecting if the nonce is a decimal number and then truncating away the decimal portion. Signed-off-by: Xe Iaso <me@xeiaso.net> * chore: spelling Signed-off-by: Xe Iaso <me@xeiaso.net> * fix(algorithms/fast): truncate decimal place on number of threads Signed-off-by: Xe Iaso <me@xeiaso.net> --------- Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
parent
fb8ce508ee
commit
c661bc37d1
5 changed files with 28 additions and 1 deletions
|
|
@ -4,7 +4,7 @@ export default function process(
|
|||
difficulty = 5,
|
||||
signal = null,
|
||||
progressCallback = null,
|
||||
threads = Math.max(navigator.hardwareConcurrency / 2, 1),
|
||||
threads = Math.trunc(Math.max(navigator.hardwareConcurrency / 2, 1)),
|
||||
) {
|
||||
console.debug("fast algo");
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,18 @@ addEventListener('message', async ({ data: eventData }) => {
|
|||
nonce += threads;
|
||||
iterations++;
|
||||
|
||||
/* Truncate the decimal portion of the nonce. This is a bit of an evil bit
|
||||
* hack, but it works reliably enough. The core of why this works is:
|
||||
*
|
||||
* > 13.4 % 1 !== 0
|
||||
* true
|
||||
* > 13 % 1 !== 0
|
||||
* false
|
||||
*/
|
||||
if (nonce % 1 !== 0) {
|
||||
nonce = Math.trunc(nonce);
|
||||
}
|
||||
|
||||
// Send a progress update from the main thread every 1024 iterations.
|
||||
if (isMainThread && (iterations & 1023) === 0) {
|
||||
postMessage(nonce);
|
||||
|
|
|
|||
|
|
@ -49,6 +49,18 @@ addEventListener("message", async ({ data: eventData }) => {
|
|||
nonce += threads;
|
||||
iterations++;
|
||||
|
||||
/* Truncate the decimal portion of the nonce. This is a bit of an evil bit
|
||||
* hack, but it works reliably enough. The core of why this works is:
|
||||
*
|
||||
* > 13.4 % 1 !== 0
|
||||
* true
|
||||
* > 13 % 1 !== 0
|
||||
* false
|
||||
*/
|
||||
if (nonce % 1 !== 0) {
|
||||
nonce = Math.trunc(nonce);
|
||||
}
|
||||
|
||||
// Send a progress update from the main thread every 1024 iterations.
|
||||
if (isMainThread && (iterations & 1023) === 0) {
|
||||
postMessage(nonce);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue