diff --git a/onionr/api.py b/onionr/api.py index d413c2d9..bf592c59 100755 --- a/onionr/api.py +++ b/onionr/api.py @@ -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) diff --git a/onionr/communicator2.py b/onionr/communicator2.py index 33b23c2f..73fbc4ae 100755 --- a/onionr/communicator2.py +++ b/onionr/communicator2.py @@ -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): diff --git a/onionr/onionrblockapi.py b/onionr/onionrblockapi.py index 4e46e5a4..90a32b9a 100644 --- a/onionr/onionrblockapi.py +++ b/onionr/onionrblockapi.py @@ -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