pow changes

master
Kevin Froman 2019-02-16 23:20:47 -06:00
parent 3fc623b8ee
commit 950883dc5d
3 changed files with 10 additions and 4 deletions

View File

@ -18,10 +18,11 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
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:
'''

View File

@ -44,6 +44,10 @@ class PasswordStrengthError(Exception):
pass
# block exceptions
class DifficultyTooLarge(Exception):
pass
class InvalidMetadata(Exception):
pass

View File

@ -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())