обработка исключения при реорге 3/head
authorfsb4000 <fsb4000@yandex.ru>
Mon, 27 Jul 2015 07:34:58 +0000 (13:34 +0600)
committerfsb4000 <fsb4000@yandex.ru>
Mon, 27 Jul 2015 07:34:58 +0000 (13:34 +0600)
backends/bitcoind/blockchain_processor.py

index 7f65aa6..1b8d92f 100644 (file)
@@ -620,14 +620,19 @@ class BlockchainProcessor(Processor):
                 self.up_to_date = True
                 break
 
+            # fixme: this is unsafe, if we revert when the undo info is not yet written
+            revert = (random.randint(1, 100) == 1) if self.test_reorgs else False
+
             # not done..
             self.up_to_date = False
-            next_block = self.bitcoind('getblockbynumber', [self.storage.height + 1, True])
-            next_block_hash = next_block.get('hash')
-            self.mtime('daemon')
+            try:
+                next_block = self.bitcoind('getblockbynumber', [self.storage.height + 1, True])
+                next_block_hash = next_block.get('hash')
+            except BaseException, e:
+                revert = True
+                next_block = next_block.get(self.storage.last_hash)
 
-            # fixme: this is unsafe, if we revert when the undo info is not yet written
-            revert = (random.randint(1, 100) == 1) if self.test_reorgs else False
+            self.mtime('daemon')
 
             if (next_block.get('previousblockhash') == self.storage.last_hash) and not revert: