work on proof of work

This commit is contained in:
Kevin Froman 2018-05-05 18:32:10 -05:00
parent 1f8eb925c6
commit 9c3416e707
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
3 changed files with 20 additions and 4 deletions

View File

@ -60,7 +60,7 @@ class OnionrCommunicate:
#logger.fatal('Failed to start Bitcoin Node, exiting...')
#exit(1)
blockProcessTimer = 0
blockProcessTimer = 19
blockProcessAmount = 20
highFailureTimer = 0
highFailureRate = 10
@ -561,6 +561,10 @@ class OnionrCommunicate:
blockMeta2 = {'type': ''}
pass
blockContent = blockContent[blockContent.rfind(b'}') + 1:]
try:
blockContent = blockContent.decode()
except AttributeError:
pass
if not self.verifyPow(blockContent, blockMeta2):
logger.warn(i + " has invalid or insufficient proof of work token, deleting")
@ -675,8 +679,13 @@ class OnionrCommunicate:
except KeyError:
return False
dataLen = len(blockContent)
expectedHash = self._crypto.blake2bHash(metadata['powToken'] + blockContent)
print(blockContent)
expectedHash = self._crypto.blake2bHash(base64.b64decode(metadata['powToken']) + blockContent.encode())
difficulty = 0
try:
expectedHash = expectedHash.decode()
except AttributeError:
pass
if metadata['powHash'] == expectedHash:
difficulty = math.floor(dataLen/1000000)
@ -689,6 +698,8 @@ class OnionrCommunicate:
else:
logger.warn("Invalid token")
else:
logger.warn('expected hash ' + expectedHash)
logger.warn('got hash ' + metadata['powHash'])
logger.warn("Invalid token2")
return retData

View File

@ -217,4 +217,8 @@ class OnionrCrypto:
return hasher.hexdigest()
def blake2bHash(self, data):
try:
data = data.encode()
except AttributeError:
pass
return nacl.hash.blake2b(data)

View File

@ -19,7 +19,7 @@
'''
import nacl.encoding, nacl.hash, nacl.utils, time, math, threading, binascii, logger, sys
import btc
import btc, core
class POW:
def pow(self, reporting = False):
@ -34,6 +34,7 @@ class POW:
blockCheckCount = 0
block = '' #self.bitcoinNode.getBlockHash(self.bitcoinNode.getLastBlockHeight())
#logger.debug('thread started')
myCore = core.Core()
while self.hashing:
'''
if blockCheckCount == blockCheck:
@ -45,7 +46,7 @@ class POW:
hbCount += 1
'''
rand = nacl.utils.random()
token = nacl.hash.blake2b(nacl.utils.random() + self.data).decode()
token = nacl.hash.blake2b(rand + self.data).decode()
#print(token)
if self.puzzle == token[0:self.difficulty]:
self.hashing = False