chain/neutrino: fix deadlock

This commit is contained in:
Alex 2017-12-12 00:25:22 -07:00 committed by Olaoluwa Osuntokun
parent 73dbcf3943
commit 78a69b4802

View file

@ -201,7 +201,6 @@ func (s *NeutrinoClient) Rescan(startHash *chainhash.Hash, addrs []btcutil.Addre
// notification indicating the rescan has "finished". // notification indicating the rescan has "finished".
if header.BlockHash() == *startHash { if header.BlockHash() == *startHash {
s.finished = true s.finished = true
s.clientMtx.Unlock()
select { select {
case s.enqueueNotification <- &RescanFinished{ case s.enqueueNotification <- &RescanFinished{
Hash: startHash, Hash: startHash,
@ -213,7 +212,6 @@ func (s *NeutrinoClient) Rescan(startHash *chainhash.Hash, addrs []btcutil.Addre
case <-s.rescanQuit: case <-s.rescanQuit:
return nil return nil
} }
s.clientMtx.Lock()
} }
s.rescan = s.CS.NewRescan( s.rescan = s.CS.NewRescan(
@ -249,11 +247,11 @@ func (s *NeutrinoClient) NotifyBlocks() error {
// NotifyReceived replicates the RPC client's NotifyReceived command. // NotifyReceived replicates the RPC client's NotifyReceived command.
func (s *NeutrinoClient) NotifyReceived(addrs []btcutil.Address) error { func (s *NeutrinoClient) NotifyReceived(addrs []btcutil.Address) error {
s.clientMtx.Lock() s.clientMtx.Lock()
defer s.clientMtx.Unlock()
// If we have a rescan running, we just need to add the appropriate // If we have a rescan running, we just need to add the appropriate
// addresses to the watch list. // addresses to the watch list.
if s.scanning { if s.scanning {
s.clientMtx.Unlock()
return s.rescan.Update(neutrino.AddAddrs(addrs...)) return s.rescan.Update(neutrino.AddAddrs(addrs...))
} }
@ -276,6 +274,7 @@ func (s *NeutrinoClient) NotifyReceived(addrs []btcutil.Address) error {
neutrino.WatchAddrs(addrs...), neutrino.WatchAddrs(addrs...),
) )
s.rescanErr = s.rescan.Start() s.rescanErr = s.rescan.Start()
s.clientMtx.Unlock()
return nil return nil
} }