fix synchronizer: ask for missing txns on start
Previously it could happen that a wallet was fully synced, except it had missing transactions, and it would not recover from this state.
This commit is contained in:
@@ -22,19 +22,15 @@
|
||||
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
import traceback
|
||||
import ssl
|
||||
import asyncio
|
||||
from aiorpcx import ClientSession, Request, Notification, TaskGroup
|
||||
from threading import Lock
|
||||
import hashlib
|
||||
import concurrent.futures
|
||||
|
||||
# from .bitcoin import Hash, hash_encode
|
||||
from aiorpcx import TaskGroup
|
||||
|
||||
from .transaction import Transaction
|
||||
from .util import ThreadJob, bh2u, PrintError, aiosafe, bfh
|
||||
from .util import bh2u, PrintError
|
||||
from .bitcoin import address_to_scripthash
|
||||
from .version import ELECTRUM_VERSION, PROTOCOL_VERSION
|
||||
|
||||
|
||||
def history_status(h):
|
||||
if not h:
|
||||
@@ -45,7 +41,6 @@ def history_status(h):
|
||||
return bh2u(hashlib.sha256(status.encode('ascii')).digest())
|
||||
|
||||
|
||||
|
||||
class Synchronizer(PrintError):
|
||||
'''The synchronizer keeps the wallet up-to-date with its set of
|
||||
addresses and their transactions. It subscribes over the network
|
||||
@@ -65,7 +60,9 @@ class Synchronizer(PrintError):
|
||||
self.status_queue = asyncio.Queue()
|
||||
|
||||
def is_up_to_date(self):
|
||||
return (not self.requested_addrs and not self.requested_histories)
|
||||
return (not self.requested_addrs
|
||||
and not self.requested_histories
|
||||
and not self.requested_tx)
|
||||
|
||||
def add(self, addr):
|
||||
self.requested_addrs.add(addr)
|
||||
@@ -167,7 +164,17 @@ class Synchronizer(PrintError):
|
||||
return s
|
||||
|
||||
async def main(self):
|
||||
for addr in self.wallet.get_addresses(): self.add(addr)
|
||||
# request missing txns, if any
|
||||
async with TaskGroup() as group:
|
||||
for history in self.wallet.history.values():
|
||||
# Old electrum servers returned ['*'] when all history for the address
|
||||
# was pruned. This no longer happens but may remain in old wallets.
|
||||
if history == ['*']: continue
|
||||
await group.spawn(self.request_missing_txs, history)
|
||||
# add addresses to bootstrap
|
||||
for addr in self.wallet.get_addresses():
|
||||
self.add(addr)
|
||||
# main loop
|
||||
while True:
|
||||
await asyncio.sleep(0.1)
|
||||
self.wallet.synchronize()
|
||||
|
||||
Reference in New Issue
Block a user