From 56fa0583cbaea62f19b8ee4ae209cd7dad2f0eed Mon Sep 17 00:00:00 2001 From: AdamISZ Date: Sat, 16 Sep 2017 17:32:59 +0200 Subject: [PATCH] respect index_cache in electrum wallet sync --- jmclient/jmclient/electruminterface.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/jmclient/jmclient/electruminterface.py b/jmclient/jmclient/electruminterface.py index ca87c99..e3f4e1f 100644 --- a/jmclient/jmclient/electruminterface.py +++ b/jmclient/jmclient/electruminterface.py @@ -476,11 +476,13 @@ class ElectrumInterface(BlockchainInterface): #Having updated this specific record, check if the entire batch from start_index #has been synchronized if all([tah[i]['synced'] for i in range(start_index, start_index + self.BATCH_SIZE)]): - #check if unused goes back as much as gaplimit; if so, end, else, continue + #check if unused goes back as much as gaplimit *and* we are ahead of any + #existing index_cache from the wallet file; if both true, end, else, continue #to next batch if all([tah[i]['used'] is False for i in range( start_index+self.BATCH_SIZE-wallet.gaplimit, - start_index+self.BATCH_SIZE)]): + start_index+self.BATCH_SIZE)]) and is_index_ahead_of_cache( + wallet, mixdepth, forchange): last_used_addr = None #to find last used, note that it may be in the *previous* batch; #may as well just search from the start, since it takes no time. @@ -491,6 +493,9 @@ class ElectrumInterface(BlockchainInterface): wallet.index[mixdepth][forchange] = wallet.addr_cache[last_used_addr][2] + 1 else: wallet.index[mixdepth][forchange] = 0 + #account for index_cache + if not is_index_ahead_of_cache(wallet, mixdepth, forchange): + wallet.index[mixdepth][forchange] = wallet.index_cache[mixdepth][forchange] tah["finished"] = True #check if all branches are finished to trigger next stage of sync. addr_sync_complete = True