Skip to content

Commit

Permalink
Follow-up to previous -- made the 'is_coin_busy_shuffling' check better
Browse files Browse the repository at this point in the history
The previous check could have potentially suffered from a race
condition making it less accurate for GUI update code. And it was a little
bit slower too.  This one is faster.
  • Loading branch information
cculianu committed Feb 23, 2019
1 parent 5284cfb commit dd48787
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions plugins/shuffle/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ def __init__(self, window, wallet, network_settings,
self.last_idle_check = 0
self.done_utxos = dict()
self._paused = False
self._coins_busy_shuffling = set() # 'prevout_hash:n' (name) set of all coins that are currently being shuffled by a ProtocolThread.

def set_password(self, password):
with self.lock:
Expand Down Expand Up @@ -472,9 +473,9 @@ def stop_protocol_thread(self, thr, scale, sender, message):
retVal = True # indicate to interesteed callers that we had a completion. Our thread loop uses this retval to decide to scan for UTXOs to shuffle immediately.
with self.wallet.lock, self.wallet.transaction_lock:
self.wallet.set_frozen_coin_state([sender], False)
coins_for_shuffling = set(self.wallet.storage.get("coins_frozen_by_shuffling",[]))
coins_for_shuffling -= {sender}
self.wallet.storage.put("coins_frozen_by_shuffling", list(coins_for_shuffling))
self._coins_busy_shuffling = set(self.wallet.storage.get("coins_frozen_by_shuffling",[]))
self._coins_busy_shuffling -= {sender}
self.wallet.storage.put("coins_frozen_by_shuffling", list(self._coins_busy_shuffling))
if message.startswith("Error"):
# unreserve addresses that were previously reserved iff error
self.wallet._addresses_cashshuffle_reserved -= { thr.addr_new_addr, thr.change_addr }
Expand Down Expand Up @@ -557,9 +558,9 @@ def get_coin_for_shuffling(scale, coins):
raise RuntimeWarning('Invalid Password caught when trying to export a private key -- if this keeps happening tell the devs!')
utxo_name = get_name(coin)
self.wallet.set_frozen_coin_state([utxo_name], True)
coins_for_shuffling = set(self.wallet.storage.get("coins_frozen_by_shuffling",[]))
coins_for_shuffling |= {utxo_name}
self.wallet.storage.put("coins_frozen_by_shuffling", list(coins_for_shuffling))
self._coins_busy_shuffling = set(self.wallet.storage.get("coins_frozen_by_shuffling",[]))
self._coins_busy_shuffling |= {utxo_name}
self.wallet.storage.put("coins_frozen_by_shuffling", list(self._coins_busy_shuffling))
inputs = {}
sks = {}
public_key = self.wallet.get_public_key(coin['address'])
Expand Down Expand Up @@ -602,7 +603,7 @@ def is_coin_busy_shuffling(self, utxo_name_or_dict):
name = utxo_name_or_dict
# name must be an str at this point!
with self.wallet.lock, self.wallet.transaction_lock:
return any(thr for thr in self.threads.values() if thr and thr.coin == name)
return name in self._coins_busy_shuffling

def is_wallet_ready(self):
return bool( self.wallet and self.wallet.is_up_to_date()
Expand Down

0 comments on commit dd48787

Please sign in to comment.