Delegate code in onionrproofs

This commit is contained in:
0Gitnick 2019-08-13 19:12:45 -05:00
parent 34c00069f5
commit 26b1cc5d87
2 changed files with 7 additions and 15 deletions

View File

@ -65,7 +65,7 @@ def announce_node(daemon):
data['random'] = existingRand data['random'] = existingRand
else: else:
daemon.announceProgress[peer] = True daemon.announceProgress[peer] = True
proof = onionrproofs.DataPOW(combinedNodes, forceDifficulty=onionrvalues.ANNOUNCE_POW) proof = onionrproofs.DataPOW(combinedNodes, minDifficulty=onionrvalues.ANNOUNCE_POW)
del daemon.announceProgress[peer] del daemon.announceProgress[peer]
try: try:
data['random'] = base64.b64encode(proof.waitForResult()[1]) data['random'] = base64.b64encode(proof.waitForResult()[1])

View File

@ -71,21 +71,13 @@ def hashMeetsDifficulty(hexHash):
return hashDifficulty >= expected return hashDifficulty >= expected
class DataPOW: class DataPOW:
def __init__(self, data, forceDifficulty=0, threadCount = 1): def __init__(self, data, minDifficulty = 0, threadCount = 1):
self.foundHash = False
self.difficulty = 0
self.data = data self.data = data
self.threadCount = threadCount self.threadCount = threadCount
self.difficulty = max(minDifficulty, getDifficultyForNewBlock(data))
self.rounds = 0 self.rounds = 0
self.hashing = False self.hashing = False
self.foundHash = False
if forceDifficulty == 0:
dataLen = sys.getsizeof(data)
self.difficulty = math.floor(dataLen / 1000000)
if self.difficulty <= 2:
self.difficulty = 4
else:
self.difficulty = forceDifficulty
try: try:
self.data = self.data.encode() self.data = self.data.encode()
@ -164,7 +156,7 @@ class DataPOW:
return result return result
class POW: class POW:
def __init__(self, metadata, data, threadCount = 1, forceDifficulty=0): def __init__(self, metadata, data, threadCount = 1, minDifficulty=0):
self.foundHash = False self.foundHash = False
self.difficulty = 0 self.difficulty = 0
self.data = data self.data = data
@ -179,8 +171,8 @@ class POW:
except AttributeError: except AttributeError:
pass pass
if forceDifficulty > 0: if minDifficulty > 0:
self.difficulty = forceDifficulty self.difficulty = minDifficulty
else: else:
# Calculate difficulty. Dumb for now, may use good algorithm in the future. # Calculate difficulty. Dumb for now, may use good algorithm in the future.
self.difficulty = getDifficultyForNewBlock(bytes(json_metadata + b'\n' + self.data)) self.difficulty = getDifficultyForNewBlock(bytes(json_metadata + b'\n' + self.data))