fix synchronizer hanging when not connected.
This commit is contained in:
parent
c3cba78659
commit
a4cb70649d
|
@ -41,7 +41,7 @@ class Blockchain(util.DaemonThread):
|
||||||
def run(self):
|
def run(self):
|
||||||
self.init_headers_file()
|
self.init_headers_file()
|
||||||
self.set_local_height()
|
self.set_local_height()
|
||||||
print_error( "blocks:", self.local_height )
|
self.print_error("%d blocks"%self.local_height)
|
||||||
|
|
||||||
while self.is_running():
|
while self.is_running():
|
||||||
try:
|
try:
|
||||||
|
@ -77,6 +77,8 @@ class Blockchain(util.DaemonThread):
|
||||||
continue
|
continue
|
||||||
self.network.new_blockchain_height(height, i)
|
self.network.new_blockchain_height(height, i)
|
||||||
|
|
||||||
|
self.print_error("stopped")
|
||||||
|
|
||||||
|
|
||||||
def verify_chain(self, chain):
|
def verify_chain(self, chain):
|
||||||
|
|
||||||
|
@ -267,7 +269,7 @@ class Blockchain(util.DaemonThread):
|
||||||
i.send_request({'method':'blockchain.block.get_header', 'params':[h]}, queue)
|
i.send_request({'method':'blockchain.block.get_header', 'params':[h]}, queue)
|
||||||
|
|
||||||
def retrieve_request(self, queue):
|
def retrieve_request(self, queue):
|
||||||
while True:
|
while self.is_running():
|
||||||
try:
|
try:
|
||||||
ir = queue.get(timeout=1)
|
ir = queue.get(timeout=1)
|
||||||
except Queue.Empty:
|
except Queue.Empty:
|
||||||
|
|
|
@ -166,10 +166,6 @@ class Network(util.DaemonThread):
|
||||||
self.requests_queue = Queue.Queue()
|
self.requests_queue = Queue.Queue()
|
||||||
self.set_proxy(deserialize_proxy(self.config.get('proxy')))
|
self.set_proxy(deserialize_proxy(self.config.get('proxy')))
|
||||||
|
|
||||||
|
|
||||||
def print_error(self, *msg):
|
|
||||||
util.print_error("[network]", *msg)
|
|
||||||
|
|
||||||
def get_server_height(self):
|
def get_server_height(self):
|
||||||
return self.heights.get(self.default_server, 0)
|
return self.heights.get(self.default_server, 0)
|
||||||
|
|
||||||
|
@ -502,6 +498,8 @@ class Network(util.DaemonThread):
|
||||||
for i in self.interfaces.values():
|
for i in self.interfaces.values():
|
||||||
i.stop()
|
i.stop()
|
||||||
|
|
||||||
|
self.print_error("stopped")
|
||||||
|
|
||||||
|
|
||||||
def on_header(self, i, r):
|
def on_header(self, i, r):
|
||||||
result = r.get('result')
|
result = r.get('result')
|
||||||
|
|
|
@ -78,11 +78,10 @@ class NetworkProxy(util.DaemonThread):
|
||||||
if response is None:
|
if response is None:
|
||||||
break
|
break
|
||||||
self.process(response)
|
self.process(response)
|
||||||
|
|
||||||
self.trigger_callback('stop')
|
self.trigger_callback('stop')
|
||||||
if self.network:
|
if self.network:
|
||||||
self.network.stop()
|
self.network.stop()
|
||||||
print_error("NetworkProxy: terminating")
|
self.print_error("stopped")
|
||||||
|
|
||||||
def process(self, response):
|
def process(self, response):
|
||||||
if self.debug:
|
if self.debug:
|
||||||
|
|
|
@ -49,8 +49,9 @@ class WalletSynchronizer(util.DaemonThread):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while self.is_running():
|
while self.is_running():
|
||||||
while not self.network.is_connected():
|
if not self.network.is_connected():
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
continue
|
||||||
self.run_interface()
|
self.run_interface()
|
||||||
|
|
||||||
def run_interface(self):
|
def run_interface(self):
|
||||||
|
@ -183,3 +184,5 @@ class WalletSynchronizer(util.DaemonThread):
|
||||||
# Updated gets called too many times from other places as well; if we use that signal we get the notification three times
|
# Updated gets called too many times from other places as well; if we use that signal we get the notification three times
|
||||||
self.network.trigger_callback("new_transaction")
|
self.network.trigger_callback("new_transaction")
|
||||||
self.was_updated = False
|
self.was_updated = False
|
||||||
|
|
||||||
|
self.print_error("stopped")
|
||||||
|
|
|
@ -43,6 +43,9 @@ class DaemonThread(threading.Thread):
|
||||||
with self.running_lock:
|
with self.running_lock:
|
||||||
self.running = False
|
self.running = False
|
||||||
|
|
||||||
|
def print_error(self, *msg):
|
||||||
|
print_error("[%s]"%self.__class__.__name__, *msg)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
is_verbose = False
|
is_verbose = False
|
||||||
|
|
|
@ -97,13 +97,12 @@ class TxVerifier(util.DaemonThread):
|
||||||
if self.network.send([ ('blockchain.transaction.get_merkle',[tx_hash, tx_height]) ], self.queue.put):
|
if self.network.send([ ('blockchain.transaction.get_merkle',[tx_hash, tx_height]) ], self.queue.put):
|
||||||
print_error('requesting merkle', tx_hash)
|
print_error('requesting merkle', tx_hash)
|
||||||
requested_merkle.append(tx_hash)
|
requested_merkle.append(tx_hash)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = self.queue.get(timeout=0.1)
|
r = self.queue.get(timeout=0.1)
|
||||||
except Queue.Empty:
|
except Queue.Empty:
|
||||||
continue
|
continue
|
||||||
|
if not r:
|
||||||
if not r: continue
|
continue
|
||||||
|
|
||||||
if r.get('error'):
|
if r.get('error'):
|
||||||
print_error('Verifier received an error:', r)
|
print_error('Verifier received an error:', r)
|
||||||
|
@ -118,6 +117,8 @@ class TxVerifier(util.DaemonThread):
|
||||||
tx_hash = params[0]
|
tx_hash = params[0]
|
||||||
self.verify_merkle(tx_hash, result)
|
self.verify_merkle(tx_hash, result)
|
||||||
|
|
||||||
|
self.print_error("stopped")
|
||||||
|
|
||||||
|
|
||||||
def verify_merkle(self, tx_hash, result):
|
def verify_merkle(self, tx_hash, result):
|
||||||
tx_height = result.get('block_height')
|
tx_height = result.get('block_height')
|
||||||
|
|
Loading…
Reference in New Issue