Skip to content

Commit

Permalink
chain/neutrino: make private notifyReceived
Browse files Browse the repository at this point in the history
This also fixes an unprotected access of s.rescan when calling Update
without the lock held.
  • Loading branch information
cfromknecht committed Nov 18, 2020
1 parent 6d8b469 commit 0343fd6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions chain/neutrino.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,18 @@ func (s *NeutrinoClient) NotifyBlocks() error {
// NotifyReceived replicates the RPC client's NotifyReceived command.
func (s *NeutrinoClient) NotifyReceived(addrs []btcutil.Address) error {
s.clientMtx.Lock()
defer s.clientMtx.Unlock()

return s.notifyReceived(addrs)
}

// notifyReceived replicates the RPC client's NotifyReceived command.
//
// NOTE: The clienMtx MUST be held when invoking.
func (s *NeutrinoClient) notifyReceived(addrs []btcutil.Address) error {
// If we have a rescan running, we just need to add the appropriate
// addresses to the watch list.
if s.isScanning() {
s.clientMtx.Unlock()
return s.rescan.Update(neutrino.AddAddrs(addrs...))
}

Expand All @@ -487,7 +494,6 @@ func (s *NeutrinoClient) NotifyReceived(addrs []btcutil.Address) error {
)
s.rescan = newRescan
s.rescanErr = s.rescan.Start()
s.clientMtx.Unlock()
return nil
}

Expand Down

0 comments on commit 0343fd6

Please sign in to comment.