Skip to content

Commit

Permalink
chain/neutrino: fix race in NotifyBlock
Browse files Browse the repository at this point in the history
Currently NotifyBlock releases the clientMtx before calling a public
version of NotifyReceived that reacquires clientMtx. This can have
unexpected behavior because the value of isScanning() could change
between lock acquisitions. We switch to using the internal
notifyReceived so that our read on isScanning() is consistent for the
duration of the call.
  • Loading branch information
cfromknecht committed Dec 8, 2020
1 parent 5bc2264 commit 09647c5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions chain/neutrino.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,13 +443,13 @@ func (s *NeutrinoClient) Rescan(startHash *chainhash.Hash, addrs []btcutil.Addre
// NotifyBlocks replicates the RPC client's NotifyBlocks command.
func (s *NeutrinoClient) NotifyBlocks() error {
s.clientMtx.Lock()
defer s.clientMtx.Unlock()

// If we're scanning, we're already notifying on blocks. Otherwise,
// start a rescan without watching any addresses.
if !s.isScanning() {
s.clientMtx.Unlock()
return s.NotifyReceived([]btcutil.Address{})
return s.notifyReceived([]btcutil.Address{})
}
s.clientMtx.Unlock()
return nil
}

Expand Down

0 comments on commit 09647c5

Please sign in to comment.