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:
Wilmer Paulino 2019-05-11 13:05:32 -07:00
parent 28161bee42
commit 0efe836773
No known key found for this signature in database
GPG key ID: 6DF57B9F9514972F

View file

@ -945,13 +945,6 @@ func (c *BitcoindClient) rescan(start chainhash.Hash) error {
}
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
// reorgs.
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
}