X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=backends%2Fbitcoind%2Fblockchain_processor.py;h=9a14dedbe0d9198f8135d4d1523189f54b2d0406;hb=115fb7a138829f3bbe28026d0f41dce0a99b46a3;hp=5d83be4a79e2c187a249e7a9cd80922e1410d7ea;hpb=a71f02d33aceec0b70bb365c7d89663a55c47f0a;p=electrum-server.git diff --git a/backends/bitcoind/blockchain_processor.py b/backends/bitcoind/blockchain_processor.py index 5d83be4..9a14ded 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) @@ -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 @@ -852,8 +862,11 @@ class BlockchainProcessor(Processor): new_mempool_hist[addr] = h # invalidate cache for mempool addresses whose mempool history has changed - for addr in new_mempool_hist.keys(): - if addr in self.mempool_hist.keys(): + new_mempool_hist_keys = new_mempool_hist.keys() + self_mempool_hist_keys = self.mempool_hist.keys() + + for addr in new_mempool_hist_keys: + if addr in self_mempool_hist_keys: if self.mempool_hist[addr] != new_mempool_hist[addr]: self.invalidate_cache(addr) else: @@ -861,8 +874,8 @@ class BlockchainProcessor(Processor): # invalidate cache for addresses that are removed from mempool ? # this should not be necessary if they go into a block, but they might not - for addr in self.mempool_hist.keys(): - if addr not in new_mempool_hist.keys(): + for addr in self_mempool_hist_keys: + if addr not in new_mempool_hist_keys: self.invalidate_cache(addr)