work on proof of work
This commit is contained in:
parent
7d9936e55c
commit
1f8eb925c6
@ -669,22 +669,27 @@ class OnionrCommunicate:
|
|||||||
'''
|
'''
|
||||||
retData = False
|
retData = False
|
||||||
try:
|
try:
|
||||||
metadata['pow']
|
metadata['powToken']
|
||||||
token = metadata['pow']
|
metadata['powHash']
|
||||||
|
token = metadata['powToken']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return False
|
return False
|
||||||
dataLen = len(blockContent)
|
dataLen = len(blockContent)
|
||||||
expectedHash = self._crypto.blake2bHash(blockContent)
|
expectedHash = self._crypto.blake2bHash(metadata['powToken'] + blockContent)
|
||||||
difficulty = 0
|
difficulty = 0
|
||||||
if token == expectedHash:
|
if metadata['powHash'] == expectedHash:
|
||||||
difficulty = math.floor(dataLen/1000000)
|
difficulty = math.floor(dataLen/1000000)
|
||||||
|
|
||||||
mainHash = '0000000000000000000000000000000000000000000000000000000000000000'#nacl.hash.blake2b(nacl.utils.random()).decode()
|
mainHash = '0000000000000000000000000000000000000000000000000000000000000000'#nacl.hash.blake2b(nacl.utils.random()).decode()
|
||||||
puzzle = mainHash[0:difficulty]
|
puzzle = mainHash[0:difficulty]
|
||||||
|
|
||||||
if token[0:difficulty] == puzzle:
|
if metadata['powHash'][0:difficulty] == puzzle:
|
||||||
logger.info('Validated block pow')
|
logger.info('Validated block pow')
|
||||||
retData = True
|
retData = True
|
||||||
|
else:
|
||||||
|
logger.warn("Invalid token")
|
||||||
|
else:
|
||||||
|
logger.warn("Invalid token2")
|
||||||
|
|
||||||
return retData
|
return retData
|
||||||
|
|
||||||
|
@ -635,9 +635,17 @@ class Core:
|
|||||||
# wait for proof to complete
|
# wait for proof to complete
|
||||||
while True:
|
while True:
|
||||||
powToken = powProof.getResult()
|
powToken = powProof.getResult()
|
||||||
if powToken != False:
|
if powToken == False:
|
||||||
break
|
|
||||||
time.sleep(0.3)
|
time.sleep(0.3)
|
||||||
|
continue
|
||||||
|
powHash = powToken[0]
|
||||||
|
powToken = base64.b64encode(powToken[1])
|
||||||
|
try:
|
||||||
|
powToken = powToken.decode()
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
break
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data.decode()
|
data.decode()
|
||||||
@ -645,7 +653,7 @@ class Core:
|
|||||||
data = data.encode()
|
data = data.encode()
|
||||||
|
|
||||||
retData = ''
|
retData = ''
|
||||||
metadata = {'type': header, 'pow': powToken}
|
metadata = {'type': header, 'powHash': powHash, 'powToken': powToken}
|
||||||
sig = {}
|
sig = {}
|
||||||
|
|
||||||
metadata = json.dumps(metadata)
|
metadata = json.dumps(metadata)
|
||||||
|
@ -44,6 +44,7 @@ class POW:
|
|||||||
blockCheckCount += 1
|
blockCheckCount += 1
|
||||||
hbCount += 1
|
hbCount += 1
|
||||||
'''
|
'''
|
||||||
|
rand = nacl.utils.random()
|
||||||
token = nacl.hash.blake2b(nacl.utils.random() + self.data).decode()
|
token = nacl.hash.blake2b(nacl.utils.random() + self.data).decode()
|
||||||
#print(token)
|
#print(token)
|
||||||
if self.puzzle == token[0:self.difficulty]:
|
if self.puzzle == token[0:self.difficulty]:
|
||||||
@ -57,7 +58,7 @@ class POW:
|
|||||||
if self.reporting:
|
if self.reporting:
|
||||||
logger.info('Found token ' + token, timestamp=True)
|
logger.info('Found token ' + token, timestamp=True)
|
||||||
logger.info('took ' + str(endTime - startTime) + ' seconds', timestamp=True)
|
logger.info('took ' + str(endTime - startTime) + ' seconds', timestamp=True)
|
||||||
self.result = token
|
self.result = (token, rand)
|
||||||
|
|
||||||
def __init__(self, data, bitcoinNode=''):
|
def __init__(self, data, bitcoinNode=''):
|
||||||
self.foundHash = False
|
self.foundHash = False
|
||||||
|
Loading…
Reference in New Issue
Block a user