don't add new histories to the log during reorgs
[electrum-server.git] / backends / bitcoind / blockchain_processor.py
index e6dcd57..6f4390f 100644 (file)
@@ -16,6 +16,7 @@ class BlockchainProcessor(Processor):
         Processor.__init__(self)
 
         self.shared = shared
+        self.config = config
         self.up_to_date = False
         self.watched_addresses = []
         self.history_cache = {}
@@ -181,6 +182,11 @@ class BlockchainProcessor(Processor):
         if sync or len(self.headers_data) > 40*100:
             self.flush_headers()
 
+        with self.cache_lock:
+            chunk_index = header.get('block_height')/2016
+            if self.chunk_cache.get(chunk_index):
+                self.chunk_cache.pop(chunk_index)
+
     def pop_header(self):
         # we need to do this only if we have not flushed
         if self.headers_data:
@@ -197,10 +203,12 @@ class BlockchainProcessor(Processor):
 
     def get_chunk(self, i):
         # store them on disk; store the current chunk in memory
-        chunk = self.chunk_cache.get(i)
-        if not chunk:
-            chunk = self.read_chunk(i)
-            self.chunk_cache[i] = chunk
+        with self.cache_lock:
+            chunk = self.chunk_cache.get(i)
+            if not chunk:
+                chunk = self.read_chunk(i)
+                self.chunk_cache[i] = chunk
+
         return chunk
 
 
@@ -452,7 +460,7 @@ class BlockchainProcessor(Processor):
 
                     # re-add them to the history
                     self.add_to_history( prevout_addr, x.get('prevout_hash'), x.get('prevout_n'), prevout_height)
-                    print_log( "new hist for", hash_160_to_bc_address(prevout_addr), self.deserialize(self.batch_list[prevout_addr]) )
+                    # print_log( "new hist for", hash_160_to_bc_address(prevout_addr), self.deserialize(self.batch_list[prevout_addr]) )
 
         # write
         max_len = 0
@@ -539,10 +547,15 @@ class BlockchainProcessor(Processor):
 
         elif method == 'blockchain.address.unsubscribe':
             try:
-                address = params[0]
-                self.watched_addresses.remove(address)
-                print_log('unsubscribed', address)
-                result = "ok"
+                password = params[0]
+                address = params[1]
+                if password == self.config.get('server','password'):
+                    self.watched_addresses.remove(address)
+                    print_log('unsubscribed', address)
+                    result = "ok"
+                else:
+                    print_log('incorrect password')
+                    result = "authentication error"
             except BaseException, e:
                 error = str(e) + ': ' + address
                 print_log( "error:", error )