wallet: store reorg safe height upon initial sync
Currently, wallet rescans start from its known tip of the chain. Since we no longer store blocks all the way from genesis to the tip of the chain, performing a rescan would cause us to scan blocks all the way from genesis, which we want to avoid. To prevent this, we set the wallet's tip to be the current reorg safe height. This ensures that we're unable to scan any blocks before it, and that we maintain MaxReorgDepth blocks stored.
This commit is contained in:
parent
e754478496
commit
fa65c1b5f7
1 changed files with 28 additions and 2 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue