tnetwork: use check_headers for binary search - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 8260dfdbe7fa9faa828945a0ca890fde34b1e0e2 DIR parent acd0ea3ff371af2e2a528b8b1cee9f4913cc5ce1 HTML Author: ThomasV <thomasv@electrum.org> Date: Mon, 17 Jul 2017 11:19:42 +0200 network: use check_headers for binary search Diffstat: M lib/network.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) --- DIR diff --git a/lib/network.py b/lib/network.py t@@ -815,9 +815,10 @@ class Network(util.DaemonThread): self.connection_down(interface.server) interface.request = None return - can_connect = interface.blockchain.can_connect(header) + + ok = interface.blockchain.check_header(header) if interface.mode == 'backward': - if can_connect: + if ok: interface.good = height interface.mode = 'binary' interface.print_error("binary search") t@@ -831,7 +832,7 @@ class Network(util.DaemonThread): delta = interface.tip - height next_height = max(0, interface.tip - 2 * delta) elif interface.mode == 'binary': - if can_connect: + if ok: interface.good = height else: interface.bad = height t@@ -848,18 +849,19 @@ class Network(util.DaemonThread): next_height = interface.tip else: if b is None: - b = interface.blockchain.fork(interface.good) - self.blockchains[interface.good] = b + b = interface.blockchain.fork(interface.bad) + self.blockchains[interface.bad] = b interface.print_error("catching up on new blockchain", b.filename) if b.catch_up is None: b.catch_up = interface.server interface.blockchain = b interface.mode = 'catch_up' - next_height = interface.good + next_height = interface.bad # todo: garbage collect blockchain objects self.notify('updated') elif interface.mode == 'catch_up': + can_connect = interface.blockchain.can_connect(header) if can_connect: interface.blockchain.save_header(header) next_height = height + 1 if height < interface.tip else None t@@ -985,7 +987,7 @@ class Network(util.DaemonThread): interface.bad = height self.request_header(interface, local_height) else: - if not interface.blockchain.can_connect(header): + if not interface.blockchain.check_header(header): self.print_error("backward", height) interface.mode = 'backward' interface.bad = height