Updated the nonce trials variables to be constants for production and development

pull/78/head
Beaudan 7 years ago
parent a0584a68c9
commit f6ab6495ae

@ -12,7 +12,9 @@ module.exports = {
const NONCE_LEN = 8; const NONCE_LEN = 8;
// Modify this value for difficulty scaling // Modify this value for difficulty scaling
let NONCE_TRIALS = 10; const DEV_NONCE_TRIALS = 10;
const PROD_NONCE_TRIALS = 1000;
let development = true;
// Increment Uint8Array nonce by 1 with carrying // Increment Uint8Array nonce by 1 with carrying
function incrementNonce(nonce) { function incrementNonce(nonce) {
@ -106,8 +108,9 @@ function calcTarget(ttl, payloadLen) {
); );
// totalLen + innerFrac // totalLen + innerFrac
const lenPlusInnerFrac = totalLen.add(innerFrac); const lenPlusInnerFrac = totalLen.add(innerFrac);
// NONCE_TRIALS * lenPlusInnerFrac // nonceTrials * lenPlusInnerFrac
const denominator = new BigInteger(NONCE_TRIALS.toString()).multiply( const nonceTrials = development ? DEV_NONCE_TRIALS : PROD_NONCE_TRIALS;
const denominator = new BigInteger(nonceTrials.toString()).multiply(
lenPlusInnerFrac lenPlusInnerFrac
); );
// 2^64 - 1 // 2^64 - 1
@ -119,8 +122,7 @@ function calcTarget(ttl, payloadLen) {
// Start calculation in child process when main process sends message data // Start calculation in child process when main process sends message data
process.on('message', msg => { process.on('message', msg => {
if (!msg.development) ({ development } = msg);
NONCE_TRIALS = 1000;
process.send({ process.send({
nonce: calcPoW( nonce: calcPoW(
msg.timestamp, msg.timestamp,

Loading…
Cancel
Save