From: fsb4000 Date: Mon, 27 Jul 2015 07:34:58 +0000 (+0600) Subject: обработка исключения при реорге X-Git-Url: https://git.novaco.in/?p=electrum-server.git;a=commitdiff_plain;h=e7eb59d5695bf1e4723fee44c0039a38b8c4ae50 обработка исключения при реорге --- diff --git a/backends/bitcoind/blockchain_processor.py b/backends/bitcoind/blockchain_processor.py index 7f65aa6..1b8d92f 100644 --- a/backends/bitcoind/blockchain_processor.py +++ b/backends/bitcoind/blockchain_processor.py @@ -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: