Skip to content

Commit

Permalink
Simplify the 'coins_frozen_by_shuffle' wallet storage var
Browse files Browse the repository at this point in the history
We don't need to read it back each time, as we now have a private copy
of the set in BackgroundProcess. Instead, we just write out to it from
our _coins_busy_shuffling set, which we keep in memory.
  • Loading branch information
cculianu committed Feb 23, 2019
1 parent dd48787 commit da5efec
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions plugins/shuffle/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +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.
self._coins_busy_shuffling = set() # 'prevout_hash:n' (name) set of all coins that are currently being shuffled by a ProtocolThread. Both wallet locks should be held to read/write this.

def set_password(self, password):
with self.lock:
Expand Down Expand Up @@ -473,8 +473,7 @@ 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)
self._coins_busy_shuffling = set(self.wallet.storage.get("coins_frozen_by_shuffling",[]))
self._coins_busy_shuffling -= {sender}
self._coins_busy_shuffling.discard(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
Expand Down Expand Up @@ -558,8 +557,7 @@ 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)
self._coins_busy_shuffling = set(self.wallet.storage.get("coins_frozen_by_shuffling",[]))
self._coins_busy_shuffling |= {utxo_name}
self._coins_busy_shuffling.add(utxo_name)
self.wallet.storage.put("coins_frozen_by_shuffling", list(self._coins_busy_shuffling))
inputs = {}
sks = {}
Expand Down

0 comments on commit da5efec

Please sign in to comment.