From f01d8088b7832de92127dbb40c1e5b42094d5aa8 Mon Sep 17 00:00:00 2001 From: Beaudan Date: Mon, 3 Jun 2019 10:06:36 +1000 Subject: [PATCH] Remove development PoW --- js/modules/loki_message_api.js | 4 ++-- libloki/proof-of-work.js | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/js/modules/loki_message_api.js b/js/modules/loki_message_api.js index f7431b251..b35a8ba36 100644 --- a/js/modules/loki_message_api.js +++ b/js/modules/loki_message_api.js @@ -31,10 +31,10 @@ const filterIncomingMessages = async messages => { }; const calcNonce = (messageEventData, pubKey, data64, timestamp, ttl) => { + const difficulty = window.storage.get('PoWDifficulty', null); // Nonce is returned as a base64 string to include in header window.Whisper.events.trigger('calculatingPoW', messageEventData); - const development = window.getEnvironment() !== 'production'; - return callWorker('calcPoW', timestamp, ttl, pubKey, data64, development); + return callWorker('calcPoW', timestamp, ttl, pubKey, data64, difficulty); }; const trySendP2p = async (pubKey, data64, isPing, messageEventData) => { diff --git a/libloki/proof-of-work.js b/libloki/proof-of-work.js index cdd95dba4..b1359d4e5 100644 --- a/libloki/proof-of-work.js +++ b/libloki/proof-of-work.js @@ -1,8 +1,7 @@ /* global dcodeIO, crypto, JSBI */ const NONCE_LEN = 8; // Modify this value for difficulty scaling -const DEV_DIFFICULTY = 10; -const PROD_DIFFICULTY = 100; +const FALLBACK_DIFFICULTY = 10; const pow = { // Increment Uint8Array nonce by '_increment' with carrying @@ -62,7 +61,6 @@ const pow = { ttl, pubKey, data, - development = false, _difficulty = null, increment = 1, startNonce = 0 @@ -74,8 +72,7 @@ const pow = { ).toArrayBuffer() ); - const difficulty = - _difficulty || (development ? DEV_DIFFICULTY : PROD_DIFFICULTY); + const difficulty = _difficulty || FALLBACK_DIFFICULTY; const target = pow.calcTarget(ttl, payload.length, difficulty); let nonce = new Uint8Array(NONCE_LEN); @@ -103,7 +100,7 @@ const pow = { return pow.bufferToBase64(nonce); }, - calcTarget(ttl, payloadLen, difficulty = PROD_DIFFICULTY) { + calcTarget(ttl, payloadLen, difficulty = FALLBACK_DIFFICULTY) { // payloadLength + NONCE_LEN const totalLen = JSBI.add(JSBI.BigInt(payloadLen), JSBI.BigInt(NONCE_LEN)); // ttl converted to seconds