From 2d3a7f227c3668f3e367748d7de48ff0ea5fa774 Mon Sep 17 00:00:00 2001 From: Adam Gibson Date: Fri, 10 Feb 2017 21:03:00 +0200 Subject: [PATCH] update state on unconfirmed, and handle failed pushtx --- jmclient/jmclient/taker.py | 5 ++++- scripts/tumbler.py | 44 ++++++++++++++++++++++++++------------ 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/jmclient/jmclient/taker.py b/jmclient/jmclient/taker.py index 92036a7..d123bcd 100644 --- a/jmclient/jmclient/taker.py +++ b/jmclient/jmclient/taker.py @@ -601,7 +601,10 @@ class Taker(object): self.txid = btc.txhash(tx) jlog.debug('txid = ' + self.txid) pushed = jm_single().bc_interface.pushtx(tx) - jm_single().bc_interface.add_tx_notify( + if not pushed: + self.on_finished_callback(False, fromtx=True) + else: + jm_single().bc_interface.add_tx_notify( self.latest_tx, self.unconfirm_callback, self.confirm_callback, self.my_cj_addr) diff --git a/scripts/tumbler.py b/scripts/tumbler.py index 61a9c0e..fca4e41 100644 --- a/scripts/tumbler.py +++ b/scripts/tumbler.py @@ -99,28 +99,42 @@ def main(): #callback for order checking; dummy/passthrough def filter_orders_callback(orders_fees, cjamount): return True - #callback between transactions + def taker_finished(res, fromtx=False, waittime=0.0): - if fromtx: + """on_finished_callback for tumbler + """ + def unconf_update(): #on taker side, cache index update is only required after tx #push, to avoid potential of address reuse in case of a crash, #because addresses are not public until broadcast (whereas for makers, #they are public *during* negotiation). So updating the cache here #is sufficient taker.wallet.update_cache_index() - if res: - #We persist the fact that the transaction is complete to the - #schedule file. Note that if a tweak to the schedule occurred, - #it only affects future (non-complete) transactions, so the final - #full record should always be accurate; but TUMBLE.log should be - #used for checking what actually happened. - taker.schedule[taker.schedule_index][5] = 1 - with open(os.path.join(logsdir, options['schedulefile']), - "wb") as f: - f.write(schedule_to_text(taker.schedule)) + #We persist the fact that the transaction is complete to the + #schedule file. Note that if a tweak to the schedule occurred, + #it only affects future (non-complete) transactions, so the final + #full record should always be accurate; but TUMBLE.log should be + #used for checking what actually happened. + taker.schedule[taker.schedule_index][5] = 1 + with open(os.path.join(logsdir, options['schedulefile']), + "wb") as f: + f.write(schedule_to_text(taker.schedule)) + + if fromtx == "unconfirmed": + #unconfirmed event means transaction has been propagated, + #we update state to prevent accidentally re-creating it in + #any crash/restart condition + unconf_update() + return + + if fromtx: + if res: tumble_log.info("Completed successfully this entry:") - #the log output depends on if it's a sweep, and if it's to INTERNAL + #this has no effect except in the rare case that confirmation + #is immediate + unconf_update() + #the log output depends on if it's to INTERNAL hrdestn = None if taker.schedule[taker.schedule_index][3] == "INTERNAL": hrdestn = taker.my_cj_addr @@ -128,10 +142,12 @@ def main(): hramt = taker.cjamount tumble_log.info(human_readable_schedule_entry( taker.schedule[taker.schedule_index], hramt, hrdestn)) + tumble_log.info("Txid was: " + taker.txid) waiting_message = "Waiting for: " + str(waittime) + " minutes." tumble_log.info(waiting_message) - sync_wallet(wallet, fast=options['fastsync']) log.info(waiting_message) + + sync_wallet(wallet, fast=options['fastsync']) reactor.callLater(waittime*60, clientfactory.getClient().clientStart) else: