solve deadlock during restore
This commit is contained in:
parent
5bb441ce37
commit
39a85767a3
11
electrum
11
electrum
|
@ -193,6 +193,10 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
gui = gui.ElectrumGui(wallet, config)
|
gui = gui.ElectrumGui(wallet, config)
|
||||||
interface.register_callback('peers', gui.server_list_changed)
|
interface.register_callback('peers', gui.server_list_changed)
|
||||||
|
|
||||||
|
verifier = WalletVerifier(interface, config)
|
||||||
|
wallet.set_verifier(verifier)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
found = config.wallet_file_exists
|
found = config.wallet_file_exists
|
||||||
if not found:
|
if not found:
|
||||||
|
@ -208,12 +212,7 @@ if __name__ == '__main__':
|
||||||
if not found:
|
if not found:
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
verifier = WalletVerifier(interface, config)
|
verifier.start()
|
||||||
wallet.set_verifier(verifier)
|
|
||||||
if not config.get('disable_spv'):
|
|
||||||
verifier.start()
|
|
||||||
else:
|
|
||||||
print "warning: SPV is disabled"
|
|
||||||
|
|
||||||
gui.main(url)
|
gui.main(url)
|
||||||
wallet.save()
|
wallet.save()
|
||||||
|
|
|
@ -75,7 +75,7 @@ class Interface(threading.Thread):
|
||||||
def queue_json_response(self, c):
|
def queue_json_response(self, c):
|
||||||
|
|
||||||
# uncomment to debug
|
# uncomment to debug
|
||||||
# print_error( "<--",c )
|
print_error( "<--",c )
|
||||||
|
|
||||||
msg_id = c.get('id')
|
msg_id = c.get('id')
|
||||||
error = c.get('error')
|
error = c.get('error')
|
||||||
|
|
|
@ -344,3 +344,11 @@ class WalletVerifier(threading.Thread):
|
||||||
new_bits = c + MM * i
|
new_bits = c + MM * i
|
||||||
return new_bits, new_target
|
return new_bits, new_target
|
||||||
|
|
||||||
|
def get_timestamp(self, tx_height):
|
||||||
|
if tx_height>0:
|
||||||
|
header = self.read_header(tx_height)
|
||||||
|
timestamp = header.get('timestamp')
|
||||||
|
else:
|
||||||
|
timestamp = 1e12
|
||||||
|
return timestamp
|
||||||
|
|
||||||
|
|
|
@ -356,11 +356,12 @@ class Wallet:
|
||||||
def fill_addressbook(self):
|
def fill_addressbook(self):
|
||||||
for tx_hash, tx in self.transactions.items():
|
for tx_hash, tx in self.transactions.items():
|
||||||
if self.get_tx_value(tx_hash)<0:
|
if self.get_tx_value(tx_hash)<0:
|
||||||
for i in tx['outputs']:
|
for o in tx['outputs']:
|
||||||
if not self.is_mine(i) and i not in self.addressbook:
|
addr = o.get('address')
|
||||||
self.addressbook.append(i)
|
if not self.is_mine(addr) and addr not in self.addressbook:
|
||||||
|
self.addressbook.append(addr)
|
||||||
# redo labels
|
# redo labels
|
||||||
self.update_tx_labels()
|
# self.update_tx_labels()
|
||||||
|
|
||||||
|
|
||||||
def get_address_flags(self, addr):
|
def get_address_flags(self, addr):
|
||||||
|
@ -537,9 +538,9 @@ class Wallet:
|
||||||
|
|
||||||
def receive_tx_callback(self, tx_hash, d):
|
def receive_tx_callback(self, tx_hash, d):
|
||||||
#print "updating history for", addr
|
#print "updating history for", addr
|
||||||
with self.lock:
|
#with self.lock:
|
||||||
self.transactions[tx_hash] = d
|
self.transactions[tx_hash] = d
|
||||||
self.update_tx_outputs(tx_hash)
|
self.update_tx_outputs(tx_hash)
|
||||||
|
|
||||||
if self.verifier: self.verifier.add(tx_hash)
|
if self.verifier: self.verifier.add(tx_hash)
|
||||||
self.save()
|
self.save()
|
||||||
|
@ -869,13 +870,7 @@ class Wallet:
|
||||||
self.verifier.add(tx_hash)
|
self.verifier.add(tx_hash)
|
||||||
|
|
||||||
|
|
||||||
def set_tx_timestamp(self, tx_hash, tx_height):
|
def set_tx_timestamp(self, tx_hash, timestamp):
|
||||||
if tx_height>0:
|
|
||||||
header = self.verifier.read_header(tx_height)
|
|
||||||
timestamp = header.get('timestamp')
|
|
||||||
else:
|
|
||||||
timestamp = 1e12
|
|
||||||
|
|
||||||
with self.lock:
|
with self.lock:
|
||||||
self.transactions[tx_hash]['timestamp'] = timestamp
|
self.transactions[tx_hash]['timestamp'] = timestamp
|
||||||
|
|
||||||
|
@ -957,7 +952,8 @@ class WalletSynchronizer(threading.Thread):
|
||||||
|
|
||||||
# 2. get a response
|
# 2. get a response
|
||||||
r = self.interface.get_response('synchronizer')
|
r = self.interface.get_response('synchronizer')
|
||||||
if not r: continue
|
if not r:
|
||||||
|
continue
|
||||||
|
|
||||||
# 3. handle response
|
# 3. handle response
|
||||||
method = r['method']
|
method = r['method']
|
||||||
|
@ -982,14 +978,14 @@ class WalletSynchronizer(threading.Thread):
|
||||||
if (tx_hash, tx_height) not in requested_tx and (tx_hash, tx_height) not in missing_tx:
|
if (tx_hash, tx_height) not in requested_tx and (tx_hash, tx_height) not in missing_tx:
|
||||||
missing_tx.append( (tx_hash, tx_height) )
|
missing_tx.append( (tx_hash, tx_height) )
|
||||||
else:
|
else:
|
||||||
self.wallet.set_tx_timestamp(tx_hash, tx_height)
|
timestamp = self.wallet.verifier.get_timestamp(tx_height)
|
||||||
|
self.wallet.set_tx_timestamp(tx_hash, timestamp)
|
||||||
|
|
||||||
elif method == 'blockchain.transaction.get':
|
elif method == 'blockchain.transaction.get':
|
||||||
tx_hash = params[0]
|
tx_hash = params[0]
|
||||||
tx_height = params[1]
|
tx_height = params[1]
|
||||||
d = self.deserialize_tx(tx_hash, tx_height, result)
|
d = self.deserialize_tx(tx_hash, tx_height, result)
|
||||||
self.wallet.receive_tx_callback(tx_hash, d)
|
self.wallet.receive_tx_callback(tx_hash, d)
|
||||||
self.wallet.set_tx_timestamp(tx_hash, tx_height)
|
|
||||||
self.was_updated = True
|
self.was_updated = True
|
||||||
requested_tx.remove( (tx_hash, tx_height) )
|
requested_tx.remove( (tx_hash, tx_height) )
|
||||||
print_error("received tx:", d)
|
print_error("received tx:", d)
|
||||||
|
@ -1018,5 +1014,6 @@ class WalletSynchronizer(threading.Thread):
|
||||||
vds.write(raw_tx.decode('hex'))
|
vds.write(raw_tx.decode('hex'))
|
||||||
d = deserialize.parse_Transaction(vds)
|
d = deserialize.parse_Transaction(vds)
|
||||||
d['tx_hash'] = tx_hash
|
d['tx_hash'] = tx_hash
|
||||||
|
d['timestamp'] = self.wallet.verifier.get_timestamp(tx_height)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue