Skip to content

Commit

Permalink
synchronizer: fix race in _on_address_status
Browse files Browse the repository at this point in the history
Triggering needs two consecutive scripthash status changes
in very quick succession. Client gets notification from server,
but then response to "blockchain.scripthash.get_history" will already contain
the changed-again history that has a different status.

20190627T101547.902638Z |     INFO | synchronizer.[default_wallet] | receiving history mwXtx49BCGAiy4tU1r7MBX5VVLWSdtasCL 1
20190627T101547.903262Z |     INFO | synchronizer.[default_wallet] | error: status mismatch: mwXtx49BCGAiy4tU1r7MBX5VVLWSdtasCL
  • Loading branch information
SomberNight committed Jun 29, 2019
1 parent 37809be commit 72d0603
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions electrum/synchronizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def __init__(self, wallet: 'AddressSynchronizer'):
def _reset(self):
super()._reset()
self.requested_tx = {}
self.requested_histories = {}
self.requested_histories = set()

def diagnostic_name(self):
return self.wallet.diagnostic_name()
Expand All @@ -161,10 +161,10 @@ async def _on_address_status(self, addr, status):
history = self.wallet.db.get_addr_history(addr)
if history_status(history) == status:
return
if addr in self.requested_histories:
if (addr, status) in self.requested_histories:
return
# request address history
self.requested_histories[addr] = status
self.requested_histories.add((addr, status))
h = address_to_scripthash(addr)
self._requests_sent += 1
result = await self.network.get_history_for_scripthash(h)
Expand All @@ -188,7 +188,7 @@ async def _on_address_status(self, addr, status):
await self._request_missing_txs(hist)

# Remove request; this allows up_to_date to be True
self.requested_histories.pop(addr)
self.requested_histories.discard((addr, status))

async def _request_missing_txs(self, hist, *, allow_server_not_finding_tx=False):
# "hist" is a list of [tx_hash, tx_height] lists
Expand Down

0 comments on commit 72d0603

Please sign in to comment.