diff --git a/erigon-lib/downloader/downloader.go b/erigon-lib/downloader/downloader.go index 9e6d3373cee..cf89315feb3 100644 --- a/erigon-lib/downloader/downloader.go +++ b/erigon-lib/downloader/downloader.go @@ -2930,6 +2930,8 @@ func calculateTime(amountLeft, rate uint64) string { } func (d *Downloader) Completed() bool { + d.lock.RLock() + defer d.lock.RUnlock() return d.stats.Completed } @@ -2955,7 +2957,7 @@ func (d *Downloader) notifyCompleted(tName string, tHash *prototypes.H160) { d.onTorrentComplete(tName, tHash) } -func (d *Downloader) getCompletedTorrents() map[string]completedTorrentInfo { +func (d *Downloader) CompletedTorrents() map[string]completedTorrentInfo { d.lock.RLock() defer d.lock.RUnlock() diff --git a/erigon-lib/downloader/downloader_grpc_server.go b/erigon-lib/downloader/downloader_grpc_server.go index e878c1a4112..2330a2b89fc 100644 --- a/erigon-lib/downloader/downloader_grpc_server.go +++ b/erigon-lib/downloader/downloader_grpc_server.go @@ -160,8 +160,7 @@ func (s *GrpcServer) TorrentCompleted(req *proto_downloader.TorrentCompletedRequ s.mu.Unlock() //Notifying about all completed torrents to the new subscriber - cmp := s.d.getCompletedTorrents() - for _, cmpInfo := range cmp { + for _, cmpInfo := range s.d.CompletedTorrents() { s.onTorrentComplete(cmpInfo.path, cmpInfo.hash) } diff --git a/erigon-lib/go.mod b/erigon-lib/go.mod index c9da468c0af..93bc2644848 100644 --- a/erigon-lib/go.mod +++ b/erigon-lib/go.mod @@ -41,7 +41,7 @@ require ( github.com/spaolacci/murmur3 v1.1.0 github.com/stretchr/testify v1.9.0 github.com/tidwall/btree v1.6.0 - go.uber.org/mock v0.5.0 + go.uber.org/mock v0.5.0 golang.org/x/crypto v0.28.0 golang.org/x/exp v0.0.0-20231226003508-02704c960a9b golang.org/x/sync v0.8.0