work on proof of work

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

View File

@ -217,4 +217,8 @@ class OnionrCrypto:
return hasher.hexdigest() return hasher.hexdigest()
def blake2bHash(self, data): def blake2bHash(self, data):
try:
data = data.encode()
except AttributeError:
pass
return nacl.hash.blake2b(data) 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 nacl.encoding, nacl.hash, nacl.utils, time, math, threading, binascii, logger, sys
import btc import btc, core
class POW: class POW:
def pow(self, reporting = False): def pow(self, reporting = False):
@ -34,6 +34,7 @@ class POW:
blockCheckCount = 0 blockCheckCount = 0
block = '' #self.bitcoinNode.getBlockHash(self.bitcoinNode.getLastBlockHeight()) block = '' #self.bitcoinNode.getBlockHash(self.bitcoinNode.getLastBlockHeight())
#logger.debug('thread started') #logger.debug('thread started')
myCore = core.Core()
while self.hashing: while self.hashing:
''' '''
if blockCheckCount == blockCheck: if blockCheckCount == blockCheck:
@ -45,7 +46,7 @@ class POW:
hbCount += 1 hbCount += 1
''' '''
rand = nacl.utils.random() rand = nacl.utils.random()
token = nacl.hash.blake2b(nacl.utils.random() + self.data).decode() token = nacl.hash.blake2b(rand + self.data).decode()
#print(token) #print(token)
if self.puzzle == token[0:self.difficulty]: if self.puzzle == token[0:self.difficulty]:
self.hashing = False self.hashing = False