improved pow
This commit is contained in:
parent
f4ec71bbd0
commit
6bf8a56979
@ -34,6 +34,7 @@ class POW:
|
|||||||
blockCheckCount = 0
|
blockCheckCount = 0
|
||||||
block = '' #self.bitcoinNode.getBlockHash(self.bitcoinNode.getLastBlockHeight())
|
block = '' #self.bitcoinNode.getBlockHash(self.bitcoinNode.getLastBlockHeight())
|
||||||
while self.hashing:
|
while self.hashing:
|
||||||
|
'''
|
||||||
if blockCheckCount == blockCheck:
|
if blockCheckCount == blockCheck:
|
||||||
if self.reporting:
|
if self.reporting:
|
||||||
logger.debug('Refreshing Bitcoin block')
|
logger.debug('Refreshing Bitcoin block')
|
||||||
@ -41,31 +42,35 @@ class POW:
|
|||||||
blockCheckCount = 0
|
blockCheckCount = 0
|
||||||
blockCheckCount += 1
|
blockCheckCount += 1
|
||||||
hbCount += 1
|
hbCount += 1
|
||||||
token = nacl.hash.blake2b(nacl.utils.random() + block.encode()).decode()
|
'''
|
||||||
if self.mainHash[0:self.difficulty] == token[0:self.difficulty]:
|
token = nacl.hash.blake2b(nacl.utils.random()).decode()
|
||||||
|
#print(token)
|
||||||
|
if self.puzzle == token[0:self.difficulty]:
|
||||||
self.hashing = False
|
self.hashing = False
|
||||||
iFound = True
|
iFound = True
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
logger.debug('POW thread exiting, another thread found result')
|
||||||
if iFound:
|
if iFound:
|
||||||
endTime = math.floor(time.time())
|
endTime = math.floor(time.time())
|
||||||
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), timestamp=True)
|
logger.info('took ' + str(endTime - startTime) + ' seconds', timestamp=True)
|
||||||
self.result = token
|
self.result = token
|
||||||
|
|
||||||
def __init__(self, difficulty, bitcoinNode):
|
def __init__(self, difficulty, bitcoinNode=''):
|
||||||
self.foundHash = False
|
self.foundHash = False
|
||||||
self.difficulty = difficulty
|
self.difficulty = difficulty
|
||||||
|
|
||||||
logger.debug('Computing difficulty of ' + str(self.difficulty))
|
logger.debug('Computing difficulty of ' + str(self.difficulty))
|
||||||
|
|
||||||
self.mainHash = nacl.hash.blake2b(nacl.utils.random()).decode()
|
self.mainHash = '0000000000000000000000000000000000000000000000000000000000000000'#nacl.hash.blake2b(nacl.utils.random()).decode()
|
||||||
self.puzzle = self.mainHash[0:self.difficulty]
|
self.puzzle = self.mainHash[0:self.difficulty]
|
||||||
self.bitcoinNode = bitcoinNode
|
self.bitcoinNode = bitcoinNode
|
||||||
logger.debug('trying to find ' + str(self.mainHash))
|
#logger.debug('trying to find ' + str(self.mainHash))
|
||||||
tOne = threading.Thread(name='one', target=self.pow, args=(True,))
|
tOne = threading.Thread(name='one', target=self.pow, args=(True,))
|
||||||
tTwo = threading.Thread(name='two', target=self.pow)
|
tTwo = threading.Thread(name='two', target=self.pow, args=(True,))
|
||||||
tThree = threading.Thread(name='three', target=self.pow)
|
tThree = threading.Thread(name='three', target=self.pow, args=(True,))
|
||||||
tOne.start()
|
tOne.start()
|
||||||
tTwo.start()
|
tTwo.start()
|
||||||
tThree.start()
|
tThree.start()
|
||||||
|
Loading…
Reference in New Issue
Block a user