From 950883dc5d6417b576b2582ce45fe35b0492565e Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sat, 16 Feb 2019 23:20:47 -0600 Subject: [PATCH] pow changes --- onionr/onionrdaemontools.py | 3 ++- onionr/onionrexceptions.py | 4 ++++ onionr/onionrproofs.py | 7 ++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/onionr/onionrdaemontools.py b/onionr/onionrdaemontools.py index 33e84b34..dace5b06 100755 --- a/onionr/onionrdaemontools.py +++ b/onionr/onionrdaemontools.py @@ -18,10 +18,11 @@ along with this program. If not, see . ''' -import onionrexceptions, onionrpeers, onionrproofs, logger, onionrusers +import onionrexceptions, onionrpeers, onionrproofs, logger import base64, sqlite3, os from dependencies import secrets from utils import netutils +from onionrusers import onionrusers class DaemonTools: ''' diff --git a/onionr/onionrexceptions.py b/onionr/onionrexceptions.py index 6763a172..b3710dbe 100755 --- a/onionr/onionrexceptions.py +++ b/onionr/onionrexceptions.py @@ -44,6 +44,10 @@ class PasswordStrengthError(Exception): pass # block exceptions + +class DifficultyTooLarge(Exception): + pass + class InvalidMetadata(Exception): pass diff --git a/onionr/onionrproofs.py b/onionr/onionrproofs.py index 12e5615f..9fd9b648 100755 --- a/onionr/onionrproofs.py +++ b/onionr/onionrproofs.py @@ -69,6 +69,7 @@ def getDifficultyForNewBlock(data, ourBlock=True): minDifficulty = config.get('general.minimum_block_pow', 4) retData = max(minDifficulty, math.floor(dataSize / 100000)) + getDifficultyModifier() + return retData def getHashDifficulty(h): @@ -245,11 +246,10 @@ class POW: answer = '' heartbeat = 200000 hbCount = 0 - + nonce = int(binascii.hexlify(nacl.utils.random(2)), 16) while self.hashing: - rand = nacl.utils.random() #token = nacl.hash.blake2b(rand + self.data).decode() - self.metadata['powRandomToken'] = base64.b64encode(rand).decode() + self.metadata['powRandomToken'] = nonce payload = json.dumps(self.metadata).encode() + b'\n' + self.data token = myCore._crypto.sha3Hash(payload) try: @@ -262,6 +262,7 @@ class POW: iFound = True self.result = payload break + nonce += 1 if iFound: endTime = math.floor(time.time())