* fixed threadCount not lowering for getBlocks

* fixed onionrblockapi not properly converting bytes to string for block
hash
master
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 = '' resp = ''
if self._utils.validateHash(data): if self._utils.validateHash(data):
if not os.path.exists('data/blocks/' + data + '.db'): 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() resp = base64.b64encode(block.getRaw().encode()).decode()
if len(resp) == 0: if len(resp) == 0:
abort(404) abort(404)

View File

@ -121,7 +121,8 @@ class OnionrCommunicatorDaemon:
else: else:
logger.warn('POW failed for block' + blockHash) logger.warn('POW failed for block' + blockHash)
else: 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 return
def pickOnlinePeer(self): def pickOnlinePeer(self):

View File

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