wallet/rescan: add rescanWithTarget helper
This commit adds rescanWithTarget, in order to facilitate rescans beginning a certain height. This is done as a precursor to fixing a bug in the initial sync, that would cause us to miss relevant txns if they are confirmed before starting the initial rescan.
This commit is contained in:
parent
7b84dc25a6
commit
dfa3a88529
1 changed files with 16 additions and 1 deletions
|
@ -245,6 +245,14 @@ out:
|
||||||
// current best block in the main chain, and is considered an initial sync
|
// current best block in the main chain, and is considered an initial sync
|
||||||
// rescan.
|
// rescan.
|
||||||
func (w *Wallet) Rescan(addrs []btcutil.Address, unspent []wtxmgr.Credit) error {
|
func (w *Wallet) Rescan(addrs []btcutil.Address, unspent []wtxmgr.Credit) error {
|
||||||
|
return w.rescanWithTarget(addrs, unspent, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// rescanWithTarget performs a rescan starting at the optional startStamp. If
|
||||||
|
// none is provided, the rescan will begin from the manager's sync tip.
|
||||||
|
func (w *Wallet) rescanWithTarget(addrs []btcutil.Address,
|
||||||
|
unspent []wtxmgr.Credit, startStamp *waddrmgr.BlockStamp) error {
|
||||||
|
|
||||||
outpoints := make(map[wire.OutPoint]btcutil.Address, len(unspent))
|
outpoints := make(map[wire.OutPoint]btcutil.Address, len(unspent))
|
||||||
for _, output := range unspent {
|
for _, output := range unspent {
|
||||||
_, outputAddrs, _, err := txscript.ExtractPkScriptAddrs(
|
_, outputAddrs, _, err := txscript.ExtractPkScriptAddrs(
|
||||||
|
@ -257,11 +265,18 @@ func (w *Wallet) Rescan(addrs []btcutil.Address, unspent []wtxmgr.Credit) error
|
||||||
outpoints[output.OutPoint] = outputAddrs[0]
|
outpoints[output.OutPoint] = outputAddrs[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If a start block stamp was provided, we will use that as the initial
|
||||||
|
// starting point for the rescan.
|
||||||
|
if startStamp == nil {
|
||||||
|
startStamp = &waddrmgr.BlockStamp{}
|
||||||
|
*startStamp = w.Manager.SyncedTo()
|
||||||
|
}
|
||||||
|
|
||||||
job := &RescanJob{
|
job := &RescanJob{
|
||||||
InitialSync: true,
|
InitialSync: true,
|
||||||
Addrs: addrs,
|
Addrs: addrs,
|
||||||
OutPoints: outpoints,
|
OutPoints: outpoints,
|
||||||
BlockStamp: w.Manager.SyncedTo(),
|
BlockStamp: *startStamp,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Submit merged job and block until rescan completes.
|
// Submit merged job and block until rescan completes.
|
||||||
|
|
Loading…
Reference in a new issue