URI: 
       tfix #3955: fix interference between verifier and catch_up - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 0928ac961a33faab0a831f3d79fe9a52fe338a25
   DIR parent 1f1844ac13235b39b04d7f7cf935747d25ab40a3
  HTML Author: ThomasV <thomasv@electrum.org>
       Date:   Thu, 22 Feb 2018 16:33:39 +0100
       
       fix #3955: fix interference between verifier and catch_up
       
       Diffstat:
         M lib/blockchain.py                   |       5 +++--
         M lib/network.py                      |       9 +++++----
         M lib/verifier.py                     |      10 +++++++---
       
       3 files changed, 15 insertions(+), 9 deletions(-)
       ---
   DIR diff --git a/lib/blockchain.py b/lib/blockchain.py
       t@@ -181,7 +181,8 @@ class Blockchain(util.PrintError):
                if d < 0:
                    chunk = chunk[-d:]
                    d = 0
       -        self.write(chunk, d, index > len(self.checkpoints))
       +        truncate = index >= len(self.checkpoints)
       +        self.write(chunk, d, truncate)
                self.swap_with_parent()
        
            def swap_with_parent(self):
       t@@ -338,7 +339,7 @@ class Blockchain(util.PrintError):
                    self.save_chunk(idx, data)
                    return True
                except BaseException as e:
       -            self.print_error('verify_chunk failed', str(e))
       +            self.print_error('verify_chunk %d failed'%idx, str(e))
                    return False
        
            def get_checkpoints(self):
   DIR diff --git a/lib/network.py b/lib/network.py
       t@@ -777,6 +777,7 @@ class Network(util.DaemonThread):
                error = response.get('error')
                result = response.get('result')
                params = response.get('params')
       +        blockchain = interface.blockchain
                if result is None or params is None or error is not None:
                    interface.print_error(error or 'bad response')
                    return
       t@@ -785,17 +786,17 @@ class Network(util.DaemonThread):
                if index not in self.requested_chunks:
                    return
                self.requested_chunks.remove(index)
       -        connect = interface.blockchain.connect_chunk(index, result)
       +        connect = blockchain.connect_chunk(index, result)
                if not connect:
                    self.connection_down(interface.server)
                    return
                # If not finished, get the next chunk
       -        if interface.blockchain.height() < interface.tip:
       +        if index >= len(blockchain.checkpoints) and blockchain.height() < interface.tip:
                    self.request_chunk(interface, index+1)
                else:
                    interface.mode = 'default'
       -            interface.print_error('catch up done', interface.blockchain.height())
       -            interface.blockchain.catch_up = None
       +            interface.print_error('catch up done', blockchain.height())
       +            blockchain.catch_up = None
                self.notify('updated')
        
            def request_header(self, interface, height):
   DIR diff --git a/lib/verifier.py b/lib/verifier.py
       t@@ -36,15 +36,19 @@ class SPV(ThreadJob):
                self.merkle_roots = {}
        
            def run(self):
       +        if not self.network.interface:
       +            return
                lh = self.network.get_local_height()
                unverified = self.wallet.get_unverified_txs()
       +        blockchain = self.network.blockchain()
                for tx_hash, tx_height in unverified.items():
                    # do not request merkle branch before headers are available
                    if (tx_height > 0) and (tx_height <= lh):
       -                header = self.network.blockchain().read_header(tx_height)
       -                if header is None and self.network.interface:
       +                header = blockchain.read_header(tx_height)
       +                if header is None:
                            index = tx_height // 2016
       -                    self.network.request_chunk(self.network.interface, index)
       +                    if index < len(blockchain.checkpoints):
       +                        self.network.request_chunk(self.network.interface, index)
                        else:
                            if tx_hash not in self.merkle_roots:
                                request = ('blockchain.transaction.get_merkle',