* fixed threadCount not lowering for getBlocks

* fixed onionrblockapi not properly converting bytes to string for block
hash
This commit is contained in:
Kevin Froman 2018-06-21 19:34:42 -05:00
parent ff8128ae33
commit 232bc4932a
3 changed files with 10 additions and 5 deletions

View File

@ -212,7 +212,7 @@ class API:
resp = ''
if self._utils.validateHash(data):
if not os.path.exists('data/blocks/' + data + '.db'):
block = Block(data.encode(), core=self._core)
block = Block(hash=data.encode(), core=self._core)
resp = base64.b64encode(block.getRaw().encode()).decode()
if len(resp) == 0:
abort(404)

View File

@ -121,7 +121,8 @@ class OnionrCommunicatorDaemon:
else:
logger.warn('POW failed for block' + blockHash)
else:
logger.warn('Block hash validation failed for ' + blockHash)
logger.warn('Block hash validation failed for ' + blockHash + ' got ' + self._core._crypto.sha3Hash(content))
self.decrementThreadCount('getBlocks')
return
def pickOnlinePeer(self):

View File

@ -27,14 +27,16 @@ class Block:
def __init__(self, hash = None, core = None, type = None, content = None):
# take from arguments
# sometimes people input a bytes object instead of str in `hash`
try:
hash = hash.decode()
except AttributeError:
pass
self.hash = hash
self.core = core
self.btype = type
self.bcontent = content
# sometimes people input a bytes object instead of str in `hash`
if isinstance(hash, bytes):
hash = hash.decode()
# initialize variables
self.valid = True
@ -57,6 +59,8 @@ class Block:
if not self.getHash() is None:
if not self.update():
logger.debug('Failed to open block %s.' % self.getHash())
else:
logger.debug('Did not update block')
# logic