progress in removing core
This commit is contained in:
parent
26c3b519c7
commit
a74f2c5051
18 changed files with 83 additions and 38 deletions
|
@ -1,5 +1,6 @@
|
|||
from . import safecompare, replayvalidation, randomshuffle
|
||||
from . import safecompare, replayvalidation, randomshuffle, verifypow
|
||||
|
||||
replay_validator = replayvalidation.replay_timestamp_validation
|
||||
random_shuffle = randomshuffle.random_shuffle
|
||||
safe_compare = safecompare.safe_compare
|
||||
safe_compare = safecompare.safe_compare
|
||||
verify_POW = verifypow.verify_POW
|
36
onionr/onionrcrypto/cryptoutils/verifypow.py
Normal file
36
onionr/onionrcrypto/cryptoutils/verifypow.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
from .. import hashers
|
||||
import config, onionrproofs, logger
|
||||
def verify_POW(blockContent):
|
||||
'''
|
||||
Verifies the proof of work associated with a block
|
||||
'''
|
||||
retData = False
|
||||
|
||||
dataLen = len(blockContent)
|
||||
|
||||
try:
|
||||
blockContent = blockContent.encode()
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
blockHash = hashers.sha3_hash(blockContent)
|
||||
try:
|
||||
blockHash = blockHash.decode() # bytes on some versions for some reason
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
difficulty = onionrproofs.getDifficultyForNewBlock(blockContent, ourBlock=False)
|
||||
|
||||
if difficulty < int(config.get('general.minimum_block_pow')):
|
||||
difficulty = int(config.get('general.minimum_block_pow'))
|
||||
mainHash = '0000000000000000000000000000000000000000000000000000000000000000'#nacl.hash.blake2b(nacl.utils.random()).decode()
|
||||
puzzle = mainHash[:difficulty]
|
||||
|
||||
if blockHash[:difficulty] == puzzle:
|
||||
# logger.debug('Validated block pow')
|
||||
retData = True
|
||||
else:
|
||||
logger.debug("Invalid token, bad proof")
|
||||
|
||||
return retData
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue