fix #750
[electrum-nvc.git] / lib / verifier.py
index 196ef1c..c97c5e7 100644 (file)
@@ -32,7 +32,6 @@ class TxVerifier(threading.Thread):
         self.daemon = True
         self.storage = storage
         self.network = network
-        self.blockchain = network.blockchain
         self.transactions    = {}                                 # requested verifications (with height sent by the requestor)
         self.verified_tx     = storage.get('verified_tx3',{})      # height, timestamp of verified transactions
         self.merkle_roots    = storage.get('merkle_roots',{})      # hashed by me
@@ -46,7 +45,7 @@ class TxVerifier(threading.Thread):
         with self.lock:
             if tx in self.verified_tx:
                 height, timestamp, pos = self.verified_tx[tx]
-                conf = (self.blockchain.local_height - height + 1)
+                conf = (self.network.get_local_height() - height + 1)
                 if conf <= 0: timestamp = None
 
             elif tx in self.transactions:
@@ -103,6 +102,9 @@ class TxVerifier(threading.Thread):
             # request missing tx
             for tx_hash, tx_height in self.transactions.items():
                 if tx_hash not in self.verified_tx:
+                    # do not request merkle branch before headers are available
+                    if tx_height > self.network.blockchain.height():
+                        continue
                     if self.merkle_roots.get(tx_hash) is None and tx_hash not in requested_merkle:
                         if self.network.send([ ('blockchain.transaction.get_merkle',[tx_hash, tx_height]) ], lambda i,r: self.queue.put(r)):
                             print_error('requesting merkle', tx_hash)
@@ -134,7 +136,7 @@ class TxVerifier(threading.Thread):
         tx_height = result.get('block_height')
         pos = result.get('pos')
         self.merkle_roots[tx_hash] = self.hash_merkle_root(result['merkle'], tx_hash, pos)
-        header = self.blockchain.read_header(tx_height)
+        header = self.network.get_header(tx_height)
         if not header: return
         assert header.get('merkle_root') == self.merkle_roots[tx_hash]
         # we passed all the tests