chain: avoid using defer for BitcoindClient onRescanFinished notification
Since defer will copy the function with the parameters evaluated at its invocation, the RescanFinished notification would be dispatched with the incorrect block. To fix this, we'll just send the notification at the end ourselves manually.
This commit is contained in:
parent
28161bee42
commit
0efe836773
1 changed files with 2 additions and 7 deletions
|
@ -945,13 +945,6 @@ func (c *BitcoindClient) rescan(start chainhash.Hash) error {
|
||||||
}
|
}
|
||||||
headers.PushBack(previousHeader)
|
headers.PushBack(previousHeader)
|
||||||
|
|
||||||
// Queue a RescanFinished notification to the caller with the last block
|
|
||||||
// processed throughout the rescan once done.
|
|
||||||
defer c.onRescanFinished(
|
|
||||||
previousHash, previousHeader.Height,
|
|
||||||
time.Unix(previousHeader.Time, 0),
|
|
||||||
)
|
|
||||||
|
|
||||||
// Cycle through all of the blocks known to bitcoind, being mindful of
|
// Cycle through all of the blocks known to bitcoind, being mindful of
|
||||||
// reorgs.
|
// reorgs.
|
||||||
for i := previousHeader.Height + 1; i <= bestBlock.Height; i++ {
|
for i := previousHeader.Height + 1; i <= bestBlock.Height; i++ {
|
||||||
|
@ -1089,6 +1082,8 @@ func (c *BitcoindClient) rescan(start chainhash.Hash) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.onRescanFinished(bestHash, bestHeight, time.Unix(bestHeader.Time, 0))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue