Browse Source

Restarting tumbler waits on gettransaction not gettxout

Fixes #362. Prior to this commit, if tumbler was invoked with
the --restart flag, it waited for the presence of the 0 index
output of the last seen tumbler transaction in the utxo set,
which was an unreliable indicator as that output could have,
in the meantime, been spent.
After this commit, we utilise the fact that the transaction
must be an in-wallet transaction, and use the rpc gettransaction
to check whether it has 1 or more confirmations, instead, which
should always work whether any outputs are spent or not.
master
AdamISZ 7 years ago
parent
commit
3602b93e1b
No known key found for this signature in database
GPG Key ID: 141001A1AF77F20B
  1. 26
      jmclient/jmclient/taker_utils.py
  2. 2
      scripts/joinmarket-qt.py
  3. 2
      scripts/tumbler.py

26
jmclient/jmclient/taker_utils.py

@ -134,16 +134,28 @@ def get_tumble_log(logsdir):
return tumble_log return tumble_log
def restart_wait(txid): def restart_wait(txid):
"""Here txid is of form txid:N for direct utxo query. """ Returns true only if the transaction txid is seen in the wallet,
Returns true only if the utxo is reported to have at least 1 and confirmed (it must be an in-wallet transaction since it always
confirm by the blockchain interface. spends coins from the wallet).
""" """
res = jm_single().bc_interface.query_utxo_set(txid, includeconf=True) try:
if not res[0]: res = jm_single().bc_interface.rpc('gettransaction', [txid, True])
except JsonRpcError as e:
return False return False
if res[0]['confirms'] > 0: if not res:
return False
if "confirmations" not in res:
log.debug("Malformed gettx result: " + str(res))
return False
if res["confirmations"] == 0:
return False
if res["confirmations"] < 0:
log.warn("Tx: " + txid + " has a conflict, abandoning.")
sys.exit(0)
else:
log.debug("Tx: " + str(txid) + " has " + str(
res["confirmations"]) + " confirmations.")
return True return True
return False
def restart_waiter(txid): def restart_waiter(txid):
"""Given a txid, wait for confirmation by polling the blockchain """Given a txid, wait for confirmation by polling the blockchain

2
scripts/joinmarket-qt.py

@ -582,7 +582,7 @@ class SpendTab(QWidget):
#since we already updated state to running, user cannot #since we already updated state to running, user cannot
#start another transactions while waiting. Also, use :0 because #start another transactions while waiting. Also, use :0 because
#it always exists #it always exists
self.waitingtxid=txid+":0" self.waitingtxid=txid
self.restartTimer.timeout.connect(self.restartWaitWrap) self.restartTimer.timeout.connect(self.restartWaitWrap)
self.restartTimer.start(5000) self.restartTimer.start(5000)
return return

2
scripts/tumbler.py

@ -72,7 +72,7 @@ def main():
#ensure last transaction is confirmed before restart #ensure last transaction is confirmed before restart
tumble_log.info("WAITING TO RESTART...") tumble_log.info("WAITING TO RESTART...")
txid = schedule[0][5] txid = schedule[0][5]
restart_waiter(txid + ":0") #add 0 index because all have it restart_waiter(txid)
#remove the already-done entry (this connects to the other TODO, #remove the already-done entry (this connects to the other TODO,
#probably better *not* to truncate the done-already txs from file, #probably better *not* to truncate the done-already txs from file,
#but simplest for now. #but simplest for now.

Loading…
Cancel
Save