Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New default threshold for v21 local webGL pow #123

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/assets/lib/pow/nano-webgl-pow.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
// Author: numtel <ben@latenightsketches.com>
// 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)

(function(){
const defaultThreshold = '0xFFFFFFF8'

function array_hex(arr, index, length) {
let out='';
Expand All @@ -29,7 +31,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;
Expand Down Expand Up @@ -212,7 +214,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
Expand Down Expand Up @@ -287,7 +289,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;
Expand Down Expand Up @@ -328,4 +330,4 @@ window.NanoWebglPow = calculate;
window.NanoWebglPow.width = 256 * 2;
window.NanoWebglPow.height = 256 * 2;

})();
})();