X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=backends%2Fbitcoind%2Fblockchain_processor.py;h=2af9534eaf627ac5f62d372b5e8aa7c549b5522e;hb=01cb32dffec6737903d69e31c401b36788723597;hp=e93439ee38e369d3732723b0477e0b5f76263fb8;hpb=dd25a1f7c56c3964fb3f760e99b5b69b96ab7c75;p=electrum-server.git diff --git a/backends/bitcoind/blockchain_processor.py b/backends/bitcoind/blockchain_processor.py index e93439e..2af9534 100644 --- a/backends/bitcoind/blockchain_processor.py +++ b/backends/bitcoind/blockchain_processor.py @@ -68,6 +68,7 @@ class BlockchainProcessor(Processor): print_log('initializing database') self.height = 0 self.last_hash = '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f' + db_version = self.db_version # check version if self.db_version != db_version: @@ -266,14 +267,14 @@ class BlockchainProcessor(Processor): # sort history, because redeeming transactions are next to the corresponding txout hist.sort(key=lambda tup: tup[2]) - # uniqueness - hist = set(map(lambda x: (x[0], x[2]), hist)) - # add memory pool with self.mempool_lock: for txid in self.mempool_hist.get(addr, []): hist.append((txid, 0, 0)) + # uniqueness + hist = set(map(lambda x: (x[0], x[2]), hist)) + # convert to dict hist = map(lambda x: {'tx_hash': x[0], 'height': x[1]}, hist) @@ -339,7 +340,7 @@ class BlockchainProcessor(Processor): for i in range(l-1, -1, -1): item = serialized_hist[80*i:80*(i+1)] item_height = int(rev_hex(item[36:39].encode('hex')), 16) - if item_height < tx_height: + if item_height <= tx_height: serialized_hist = serialized_hist[0:80*(i+1)] + s + serialized_hist[80*(i+1):] break else: @@ -426,6 +427,7 @@ class BlockchainProcessor(Processor): serialized_hist = serialized_hist[0:80*i] + new_item + serialized_hist[80*(i+1):] break else: + self.shared.stop() hist = self.deserialize(serialized_hist) raise BaseException("prevout not found", addr, hist, txi.encode('hex')) @@ -493,10 +495,14 @@ class BlockchainProcessor(Processor): for txi in block_inputs: try: addr = self.db.Get(txi) - except: - # print "addr not in db", txi.encode('hex') + except KeyError: # the input could come from the same block continue + except: + traceback.print_exc(file=sys.stdout) + self.shared.stop() + raise + self.batch_txio[txi] = addr addr_to_read.append(addr) @@ -525,8 +531,12 @@ class BlockchainProcessor(Processor): for addr in addr_to_read: try: self.batch_list[addr] = self.db.Get(addr) - except: + except KeyError: self.batch_list[addr] = '' + except: + traceback.print_exc(file=sys.stdout) + self.shared.stop() + raise # process @@ -819,7 +829,12 @@ class BlockchainProcessor(Processor): try: addr = self.db.Get(txi) except: - continue + tx_prev = self.get_mempool_transaction(x.get('prevout_hash')) + try: + addr = tx_prev['outputs'][x.get('prevout_n')]['address'] + if not addr: continue + except: + continue l = self.mempool_addresses.get(tx_hash, []) if addr not in l: l.append(addr)