mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-31 09:21:39 +00:00
nodaemon
This commit is contained in:
parent
8308440ded
commit
0ad7f72d3d
3 changed files with 39 additions and 9 deletions
11
electrum
11
electrum
|
@ -250,6 +250,9 @@ if __name__ == '__main__':
|
||||||
verifier.start()
|
verifier.start()
|
||||||
gui.main(url)
|
gui.main(url)
|
||||||
wallet.save()
|
wallet.save()
|
||||||
|
verifier.stop()
|
||||||
|
synchronizer.stop()
|
||||||
|
#interface.stop()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if cmd not in known_commands:
|
if cmd not in known_commands:
|
||||||
|
@ -343,10 +346,11 @@ if __name__ == '__main__':
|
||||||
# open session
|
# open session
|
||||||
if cmd not in offline_commands and not options.offline:
|
if cmd not in offline_commands and not options.offline:
|
||||||
interface = Interface(config)
|
interface = Interface(config)
|
||||||
interface.register_callback('connected', lambda: print_error("Connected to " + interface.connection_msg))
|
interface.register_callback('connected', lambda: sys.stderr.write("Connected to " + interface.connection_msg + "\n"))
|
||||||
interface.start()
|
interface.start()
|
||||||
wallet.interface = interface
|
wallet.interface = interface
|
||||||
WalletSynchronizer(wallet, config).start()
|
synchronizer = WalletSynchronizer(wallet, config)
|
||||||
|
synchronizer.start()
|
||||||
wallet.update()
|
wallet.update()
|
||||||
wallet.save()
|
wallet.save()
|
||||||
|
|
||||||
|
@ -643,3 +647,6 @@ if __name__ == '__main__':
|
||||||
addr = args[1]
|
addr = args[1]
|
||||||
print_msg(wallet.unprioritize(addr))
|
print_msg(wallet.unprioritize(addr))
|
||||||
|
|
||||||
|
|
||||||
|
if cmd not in offline_commands and not options.offline:
|
||||||
|
synchronizer.stop()
|
||||||
|
|
|
@ -29,7 +29,7 @@ class WalletVerifier(threading.Thread):
|
||||||
|
|
||||||
def __init__(self, interface, config):
|
def __init__(self, interface, config):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.daemon = True
|
#self.daemon = True
|
||||||
self.config = config
|
self.config = config
|
||||||
self.interface = interface
|
self.interface = interface
|
||||||
self.transactions = {} # requested verifications (with height sent by the requestor)
|
self.transactions = {} # requested verifications (with height sent by the requestor)
|
||||||
|
@ -45,6 +45,7 @@ class WalletVerifier(threading.Thread):
|
||||||
self.local_height = 0
|
self.local_height = 0
|
||||||
self.init_headers_file()
|
self.init_headers_file()
|
||||||
self.set_local_height()
|
self.set_local_height()
|
||||||
|
self.running = False
|
||||||
|
|
||||||
def get_confirmations(self, tx):
|
def get_confirmations(self, tx):
|
||||||
""" return the number of confirmations of a monitored transaction. """
|
""" return the number of confirmations of a monitored transaction. """
|
||||||
|
@ -62,7 +63,15 @@ class WalletVerifier(threading.Thread):
|
||||||
if tx_hash not in self.transactions.keys():
|
if tx_hash not in self.transactions.keys():
|
||||||
self.transactions[tx_hash] = tx_height
|
self.transactions[tx_hash] = tx_height
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
with self.lock: self.running = False
|
||||||
|
|
||||||
|
def is_running(self):
|
||||||
|
with self.lock: return self.running
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
with self.lock:
|
||||||
|
self.running = True
|
||||||
requested_merkle = []
|
requested_merkle = []
|
||||||
requested_chunks = []
|
requested_chunks = []
|
||||||
requested_headers = []
|
requested_headers = []
|
||||||
|
@ -71,7 +80,7 @@ class WalletVerifier(threading.Thread):
|
||||||
# subscribe to block headers
|
# subscribe to block headers
|
||||||
self.interface.send([ ('blockchain.headers.subscribe',[])], 'verifier')
|
self.interface.send([ ('blockchain.headers.subscribe',[])], 'verifier')
|
||||||
|
|
||||||
while True:
|
while self.is_running():
|
||||||
# request missing chunks
|
# request missing chunks
|
||||||
if not all_chunks and self.height and not requested_chunks:
|
if not all_chunks and self.height and not requested_chunks:
|
||||||
|
|
||||||
|
@ -117,9 +126,8 @@ class WalletVerifier(threading.Thread):
|
||||||
self.pending_headers.remove(header)
|
self.pending_headers.remove(header)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = self.interface.get_response('verifier',timeout=1)
|
r = self.interface.get_response('verifier',timeout=0.1)
|
||||||
except Queue.Empty:
|
except Queue.Empty:
|
||||||
time.sleep(1)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 3. handle response
|
# 3. handle response
|
||||||
|
|
|
@ -1153,13 +1153,21 @@ class WalletSynchronizer(threading.Thread):
|
||||||
|
|
||||||
def __init__(self, wallet, config):
|
def __init__(self, wallet, config):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self.daemon = True
|
# self.daemon = True
|
||||||
self.wallet = wallet
|
self.wallet = wallet
|
||||||
self.interface = self.wallet.interface
|
self.interface = self.wallet.interface
|
||||||
self.interface.register_channel('synchronizer')
|
self.interface.register_channel('synchronizer')
|
||||||
self.wallet.interface.register_callback('connected', lambda: self.wallet.set_up_to_date(False))
|
self.wallet.interface.register_callback('connected', lambda: self.wallet.set_up_to_date(False))
|
||||||
self.wallet.interface.register_callback('connected', lambda: self.interface.send([('server.banner',[])],'synchronizer') )
|
self.wallet.interface.register_callback('connected', lambda: self.interface.send([('server.banner',[])],'synchronizer') )
|
||||||
self.was_updated = True
|
self.was_updated = True
|
||||||
|
self.running = False
|
||||||
|
self.lock = threading.Lock()
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
with self.lock: self.running = False
|
||||||
|
|
||||||
|
def is_running(self):
|
||||||
|
with self.lock: return self.running
|
||||||
|
|
||||||
def synchronize_wallet(self):
|
def synchronize_wallet(self):
|
||||||
new_addresses = self.wallet.synchronize()
|
new_addresses = self.wallet.synchronize()
|
||||||
|
@ -1186,6 +1194,8 @@ class WalletSynchronizer(threading.Thread):
|
||||||
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
with self.lock: self.running = True
|
||||||
|
|
||||||
requested_tx = []
|
requested_tx = []
|
||||||
missing_tx = []
|
missing_tx = []
|
||||||
requested_histories = {}
|
requested_histories = {}
|
||||||
|
@ -1208,7 +1218,7 @@ class WalletSynchronizer(threading.Thread):
|
||||||
# subscriptions
|
# subscriptions
|
||||||
self.subscribe_to_addresses(self.wallet.all_addresses())
|
self.subscribe_to_addresses(self.wallet.all_addresses())
|
||||||
|
|
||||||
while True:
|
while self.is_running():
|
||||||
# 1. send new requests
|
# 1. send new requests
|
||||||
self.synchronize_wallet()
|
self.synchronize_wallet()
|
||||||
|
|
||||||
|
@ -1223,7 +1233,12 @@ class WalletSynchronizer(threading.Thread):
|
||||||
self.was_updated = False
|
self.was_updated = False
|
||||||
|
|
||||||
# 2. get a response
|
# 2. get a response
|
||||||
r = self.interface.get_response('synchronizer')
|
try:
|
||||||
|
r = self.interface.get_response('synchronizer', timeout=0.1)
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# poke sends None. (check if still needed)
|
||||||
if not r:
|
if not r:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue