|
|
@ -227,9 +227,7 @@ class Network(util.DaemonThread): |
|
|
|
self.banner = '' |
|
|
|
self.donation_address = '' |
|
|
|
self.relay_fee = None |
|
|
|
self.heights = {} |
|
|
|
self.merkle_roots = {} |
|
|
|
self.utxo_roots = {} |
|
|
|
self.headers = {} |
|
|
|
# callbacks passed with subscriptions |
|
|
|
self.subscriptions = defaultdict(list) |
|
|
|
self.sub_cache = {} |
|
|
@ -297,7 +295,8 @@ class Network(util.DaemonThread): |
|
|
|
pass |
|
|
|
|
|
|
|
def get_server_height(self): |
|
|
|
return self.heights.get(self.default_server, 0) |
|
|
|
h = self.headers.get(self.default_server) |
|
|
|
return h['block_height'] if h else 0 |
|
|
|
|
|
|
|
def server_is_lagging(self): |
|
|
|
sh = self.get_server_height() |
|
|
@ -494,7 +493,12 @@ class Network(util.DaemonThread): |
|
|
|
if suggestion and self.protocol == deserialize_server(suggestion)[2]: |
|
|
|
self.switch_to_interface(suggestion) |
|
|
|
else: |
|
|
|
self.switch_to_random_interface() |
|
|
|
# switch to one that has the correct header (not height) |
|
|
|
header = self.get_header(self.get_local_height()) |
|
|
|
filtered = map(lambda x:x[0], filter(lambda x: x[1]==header, self.headers.items())) |
|
|
|
if filtered: |
|
|
|
choice = random.choice(filtered) |
|
|
|
self.switch_to_interface(choice) |
|
|
|
|
|
|
|
def switch_to_interface(self, server): |
|
|
|
'''Switch to server as our interface. If no connection exists nor |
|
|
@ -676,7 +680,7 @@ class Network(util.DaemonThread): |
|
|
|
self.set_status('disconnected') |
|
|
|
if server in self.interfaces: |
|
|
|
self.close_interface(self.interfaces[server]) |
|
|
|
self.heights.pop(server, None) |
|
|
|
self.headers.pop(server, None) |
|
|
|
self.notify('interfaces') |
|
|
|
|
|
|
|
def new_interface(self, server, socket): |
|
|
@ -857,9 +861,7 @@ class Network(util.DaemonThread): |
|
|
|
height = header.get('block_height') |
|
|
|
if not height: |
|
|
|
return |
|
|
|
self.heights[i.server] = height |
|
|
|
self.merkle_roots[i.server] = header.get('merkle_root') |
|
|
|
self.utxo_roots[i.server] = header.get('utxo_root') |
|
|
|
self.headers[i.server] = header |
|
|
|
|
|
|
|
# Queue this interface's height for asynchronous catch-up |
|
|
|
self.bc_requests.append((i, {'if_height': height})) |
|
|
|