From fc64a1c70473500ca3adc740a79c5cdb5c96907a Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 13 Mar 2020 10:59:51 +0100 Subject: [PATCH] wallet: wait for chain sync on Neutrino recovery Normally the wallet doesn't wait for the chain backend to be synced on regtest/simnet because there we cannot be certain if we are at the chain tip, as there are no other nodes to compare to. For Neutrino, this is a bit different because we rely on the cfheader server to tell us what it thinks the chain tip is. For a wallet recovery on Neutrino we therefore need to make sure we are at least synced up to what the server thinks is the tip. --- wallet/wallet.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/wallet/wallet.go b/wallet/wallet.go index 2309b69..a3e092c 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -336,10 +336,21 @@ func (w *Wallet) syncWithChain(birthdayStamp *waddrmgr.BlockStamp) error { return err } + // Neutrino relies on the information given to it by the cfheader server + // so it knows exactly whether it's synced up to the server's state or + // not, even on dev chains. To recover a Neutrino wallet, we need to + // make sure it's synced before we start scanning for addresses, + // otherwise we might miss some if we only scan up to its current sync + // point. + neutrinoRecovery := chainClient.BackEnd() == "neutrino" && + w.recoveryWindow > 0 + // We'll wait until the backend is synced to ensure we get the latest // MaxReorgDepth blocks to store. We don't do this for development - // environments as we can't guarantee a lively chain. - if !w.isDevEnv() { + // environments as we can't guarantee a lively chain, except for + // Neutrino, where the cfheader server tells us what it believes the + // chain tip is. + if !w.isDevEnv() || neutrinoRecovery { log.Debug("Waiting for chain backend to sync to tip") if err := w.waitUntilBackendSynced(chainClient); err != nil { return err