diff --git a/wallet/wallet.go b/wallet/wallet.go index 341ebfa..6b5e630 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -354,13 +354,39 @@ func (w *Wallet) syncWithChain(birthdayStamp *waddrmgr.BlockStamp) error { err) } + // We'll also determine our initial sync starting height. This + // is needed as the wallet can now begin storing blocks from an + // arbitrary height, rather than all the blocks from genesis, so + // we persist this height to ensure we don't store any blocks + // before it. + startHeight, _, err := w.getSyncRange(chainClient, birthdayStamp) + if err != nil { + return err + } + startHash, err := chainClient.GetBlockHash(int64(startHeight)) + if err != nil { + return err + } + startHeader, err := chainClient.GetBlockHeader(startHash) + if err != nil { + return err + } + err = walletdb.Update(w.db, func(tx walletdb.ReadWriteTx) error { ns := tx.ReadWriteBucket(waddrmgrNamespaceKey) + err := w.Manager.SetSyncedTo(ns, &waddrmgr.BlockStamp{ + Hash: *startHash, + Height: startHeight, + Timestamp: startHeader.Timestamp, + }) + if err != nil { + return err + } return w.Manager.SetBirthdayBlock(ns, *birthdayStamp, true) }) if err != nil { - return fmt.Errorf("unable to write birthday block: %v", - err) + return fmt.Errorf("unable to persist initial sync "+ + "data: %v", err) } }