From 1cbf9f7ccb95d53b9cdc2818782477fa274f9ccb Mon Sep 17 00:00:00 2001 From: Joohansson Date: Sun, 21 Jun 2020 13:35:32 +0200 Subject: [PATCH 1/2] New default threshold for v21 --- src/assets/lib/pow/nano-webgl-pow.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/assets/lib/pow/nano-webgl-pow.js b/src/assets/lib/pow/nano-webgl-pow.js index c38005d0..b8152f83 100644 --- a/src/assets/lib/pow/nano-webgl-pow.js +++ b/src/assets/lib/pow/nano-webgl-pow.js @@ -3,13 +3,16 @@ // Author: numtel // License: MIT -// window.NanoWebglPow(hashHex, callback, progressCallback); +// window.NanoWebglPow(hashHex, callback, progressCallback, threshold); // @param hashHex String Previous Block Hash as Hex String // @param callback Function Called when work value found // Receives single string argument, work value as hex // @param progressCallback Function Optional // Receives single argument: n, number of frames so far // Return true to abort +// @param threshold String Optional difficulty threshold (default=0xFFFFFFF8 since v21) + +const defaultThreshold = '0xFFFFFFF8' (function(){ @@ -29,7 +32,7 @@ function hex_reverse(hex) { return out; } -function calculate(hashHex, callback, progressCallback) { +function calculate(hashHex, callback, progressCallback, threshold = defaultThreshold) { const canvas = document.createElement('canvas'); canvas.width = window.NanoWebglPow.width; @@ -212,7 +215,7 @@ function calculate(hashHex, callback, progressCallback) { // Threshold test, first 4 bytes not significant, // only calculate digest of the second 4 bytes - if((BLAKE2B_IV32_1 ^ v[1] ^ v[17]) > 0xFFFFFFC0u) { + if((BLAKE2B_IV32_1 ^ v[1] ^ v[17]) > ` + threshold + `u) { // Success found, return pixel data so work value can be constructed fragColor = vec4( float(x_index + 1u)/255., // +1 to distinguish from 0 (unsuccessful) pixels @@ -287,7 +290,7 @@ function calculate(hashHex, callback, progressCallback) { gl.uniform4uiv(work0Location, Array.from(work0)); gl.uniform4uiv(work1Location, Array.from(work1)); - + // Check with progressCallback every 100 frames if(n%100===0 && typeof progressCallback === 'function' && progressCallback(n)) return; @@ -328,4 +331,4 @@ window.NanoWebglPow = calculate; window.NanoWebglPow.width = 256 * 2; window.NanoWebglPow.height = 256 * 2; -})(); +})(); \ No newline at end of file From 40b14ca47e81967c881e4774548022ad574228ad Mon Sep 17 00:00:00 2001 From: Joohansson Date: Mon, 29 Jun 2020 06:58:38 +0200 Subject: [PATCH 2/2] const correction --- src/assets/lib/pow/nano-webgl-pow.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/assets/lib/pow/nano-webgl-pow.js b/src/assets/lib/pow/nano-webgl-pow.js index b8152f83..49c0d3e4 100644 --- a/src/assets/lib/pow/nano-webgl-pow.js +++ b/src/assets/lib/pow/nano-webgl-pow.js @@ -12,9 +12,8 @@ // Return true to abort // @param threshold String Optional difficulty threshold (default=0xFFFFFFF8 since v21) -const defaultThreshold = '0xFFFFFFF8' - (function(){ +const defaultThreshold = '0xFFFFFFF8' function array_hex(arr, index, length) { let out='';