electrum

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

commit af3fd62fd4eaac1365b0b1f3bd5c6dde3e2182c6
parent 96070246b72acb4c97d8e0726c636cea3adc4fea
Author: ThomasV <thomasv@gitorious>
Date:   Fri, 25 Jul 2014 16:32:19 +0200

send server height and server lag with daemon

Diffstat:
Melectrum | 5+++--
Mgui/qt/main_window.py | 7++++---
Mlib/daemon.py | 2+-
Mlib/network.py | 33+++++++++++++++++----------------
Mlib/network_proxy.py | 10+++++++---
5 files changed, 32 insertions(+), 25 deletions(-)

diff --git a/electrum b/electrum @@ -272,8 +272,9 @@ if __name__ == '__main__': network.start() if arg == 'status': print_json({ - 'main_server': network.get_parameters()[0], - 'height': network.get_local_height(), + 'server': network.get_parameters()[0], + 'blockchain_height': network.get_local_height(), + 'server_height': network.get_server_height(), 'nodes': network.get_interfaces(), 'connected': network.is_connected() }) diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -467,12 +467,13 @@ class ElectrumWindow(QMainWindow): icon = QIcon(":icons/status_disconnected.png") elif self.network.is_connected(): + server_lag = self.network.get_local_height() - self.network.get_server_height() if not self.wallet.up_to_date: text = _("Synchronizing...") icon = QIcon(":icons/status_waiting.png") - #elif self.network.server_lag > 1: - # text = _("Server is lagging (%d blocks)"%self.network.server_lag) - # icon = QIcon(":icons/status_lagging.png") + elif server_lag > 1: + text = _("Server is lagging (%d blocks)"%server_lag) + icon = QIcon(":icons/status_lagging.png") else: c, u = self.wallet.get_account_balance(self.current_account) text = _( "Balance" ) + ": %s "%( self.format_amount(c) ) + self.base_unit() diff --git a/lib/daemon.py b/lib/daemon.py @@ -199,7 +199,7 @@ class NetworkServer: elif key == 'banner': value = self.network.banner elif key == 'updated': - value = self.network.get_local_height() + value = (self.network.get_local_height(), self.network.get_server_height()) elif key == 'servers': value = self.network.get_servers() elif key == 'interfaces': diff --git a/lib/network.py b/lib/network.py @@ -105,7 +105,6 @@ class Network(threading.Thread): self.heights = {} self.merkle_roots = {} self.utxo_roots = {} - self.server_lag = 0 dir_path = os.path.join( self.config.path, 'certs') if not os.path.exists(dir_path): @@ -119,6 +118,17 @@ class Network(threading.Thread): self.connection_status = 'connecting' + def get_server_height(self): + return self.heights.get(self.default_server,0) + + def server_is_lagging(self): + h = self.get_server_height() + if not h: + print_error('no height for main interface') + return False + lag = self.get_local_height() - self.get_server_height() + return lag > 1 + def set_status(self, status): self.connection_status = status self.trigger_callback('status') @@ -247,7 +257,7 @@ class Network(threading.Thread): if not self.interface.is_connected: self.switch_to_random_interface() else: - if self.server_lag > 0: + if self.server_is_lagging(): self.stop_interface() else: self.set_server(server) @@ -262,9 +272,6 @@ class Network(threading.Thread): server = interface.server print_error("switching to", server) self.interface = interface - h = self.heights.get(server) - if h: - self.server_lag = self.blockchain.height() - h self.config.set_key('server', server, False) self.default_server = server self.send_subscriptions() @@ -310,15 +317,10 @@ class Network(threading.Thread): 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) - else: - print_error('no height for main interface') + if self.server_is_lagging(): + print_error( "Server is lagging", blockchain_height, h) + if self.config.get('auto_cycle'): + self.set_server(i.server) self.trigger_callback('updated') @@ -377,8 +379,7 @@ class Network(threading.Thread): self.blockchain.queue.put((i,result)) if i == self.interface: - self.server_lag = self.blockchain.height() - height - if self.server_lag > 1 and self.config.get('auto_cycle'): + if self.server_is_lagging() and self.config.get('auto_cycle'): print_error( "Server lagging, stopping interface") self.stop_interface() diff --git a/lib/network_proxy.py b/lib/network_proxy.py @@ -57,7 +57,8 @@ class NetworkProxy(threading.Thread): self.status = 'connecting' self.servers = {} self.banner = '' - self.height = 0 + self.blockchain_height = 0 + self.server_height = 0 self.interfaces = [] def is_running(self): @@ -99,7 +100,7 @@ class NetworkProxy(threading.Thread): elif key == 'banner': self.banner = value elif key == 'updated': - self.height = value + self.blockchain_height, self.server_height = value elif key == 'servers': self.servers = value elif key == 'interfaces': @@ -176,7 +177,10 @@ class NetworkProxy(threading.Thread): return self.synchronous_get([('network.get_header',[height])])[0] def get_local_height(self): - return self.height + return self.blockchain_height + + def get_server_height(self): + return self.server_height def is_connected(self): return self.status == 'connected'