From 0efe836773ec5ab078a508be1998ca9560a9d1b3 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Sat, 11 May 2019 13:05:32 -0700 Subject: [PATCH] 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. --- chain/bitcoind_client.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/chain/bitcoind_client.go b/chain/bitcoind_client.go index ff27ee9..2e42e7d 100644 --- a/chain/bitcoind_client.go +++ b/chain/bitcoind_client.go @@ -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 }