electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit c0abd3c34eaf1220c8ac08ab68f2fe5ec5988679
parent a38298c5ee583625318ce72f0e6d13254c62a88c
Author: ThomasV <thomasv@gitorious>
Date:   Sat,  5 Oct 2013 00:21:48 +0200

show lag in status line

Diffstat:
Mgui/qt/main_window.py | 4++--
Mlib/blockchain.py | 36++++++++++++++----------------------
Mlib/network.py | 15+++++++++++++++
3 files changed, 31 insertions(+), 24 deletions(-)

diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -538,8 +538,8 @@ class ElectrumWindow(QMainWindow): if not self.wallet.up_to_date: text = _("Synchronizing...") icon = QIcon(":icons/status_waiting.png") - elif self.network.is_lagging: - text = _("Server is lagging") + elif self.network.server_lag > 1: + text = _("Server is lagging (%d blocks)"%self.network.server_lag) icon = QIcon(":icons/status_lagging.png") else: c, u = self.wallet.get_account_balance(self.current_account) diff --git a/lib/blockchain.py b/lib/blockchain.py @@ -36,8 +36,6 @@ class Blockchain(threading.Thread): self.headers_url = 'http://headers.electrum.org/blockchain_headers' self.set_local_height() self.queue = Queue.Queue() - self.servers_height = {} - self.is_lagging = False def stop(self): @@ -69,11 +67,13 @@ class Blockchain(threading.Thread): if not header: continue height = header.get('block_height') - self.servers_height[i.server] = height + + if height <= self.local_height: + continue if height > self.local_height + 50: - self.get_chunks(i, header, height) - self.network.trigger_callback('updated') + if not self.get_and_verify_chunks(i, header, height): + continue if height > self.local_height: # get missing parts from interface (until it connects to my chain) @@ -91,22 +91,9 @@ class Blockchain(threading.Thread): else: print_error("error", i.server) # todo: dismiss that server + continue - if self.network.is_connected(): - h = self.servers_height.get(self.network.interface.server) - else: - h = None - - if h is not None and h < height - 1: - print_error( "Server is lagging", height, h) - if self.config.get('auto_cycle'): - self.network.set_server(i.server) - else: - self.network.is_lagging = True - else: - self.network.is_lagging = False - - self.network.trigger_callback('updated') + self.network.new_blockchain_height(height, i) @@ -385,7 +372,7 @@ class Blockchain(threading.Thread): return chain - def get_chunks(self, i, header, height): + def get_and_verify_chunks(self, i, header, height): requested_chunks = [] queue = Queue.Queue() min_index = (self.local_height + 1)/2016 @@ -412,9 +399,14 @@ class Blockchain(threading.Thread): result = r['result'] index = params[0] - self.verify_chunk(index, result) + try: + self.verify_chunk(index, result) + except: + return False requested_chunks.remove(index) + return True + diff --git a/lib/network.py b/lib/network.py @@ -61,6 +61,7 @@ class Network(threading.Thread): self.interface = None self.proxy = self.config.get('proxy') self.heights = {} + self.server_lag = 0 dir_path = os.path.join( self.config.path, 'certs') if not os.path.exists(dir_path): @@ -206,6 +207,18 @@ class Network(threading.Thread): self.config.set_key('recent_servers', self.recent_servers) + def new_blockchain_height(self, blockchain_height, i): + if self.is_connected(): + h = self.heights.get(self.interface.server) + if h: + self.server_lag = blockchain_height - h + if self.server_lag > 1: + print_error( "Server is lagging", blockchain_height, h) + if self.config.get('auto_cycle'): + self.set_server(i.server) + + self.trigger_callback('updated') + def run(self): self.blockchain.start() @@ -231,6 +244,8 @@ class Network(threading.Thread): else: self.disconnected_servers.append(i.server) self.interfaces.pop(i.server) + if i.server in self.heights: + self.heights.pop(i.server) if i == self.interface: self.interface = None self.trigger_callback('disconnected')