[downloader] fix explorer node get stuck when doing short range sync (#4150)

* [downloader] fix explorer node get stuck when doing short range sync

* [downloader] add log message
pull/4168/head
Jacky Wang 3 years ago committed by GitHub
parent 708a6e18c1
commit 22e595df82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      cmd/harmony/main.go
  2. 18
      hmy/downloader/downloader.go

@ -813,7 +813,7 @@ func setupSyncService(node *node.Node, host p2p.Host, hc harmonyconfig.HarmonyCo
node.RegisterService(service.Synchronize, s)
d := s.Downloaders.GetShardDownloader(node.Blockchain().ShardID())
if hc.Sync.Downloader {
if hc.Sync.Downloader && hc.General.NodeType != nodeTypeExplorer {
node.Consensus.SetDownloader(d) // Set downloader when stream client is active
}
}

@ -32,8 +32,10 @@ type (
ctx context.Context
cancel func()
evtDownloadFinished event.Feed // channel for each download task finished
evtDownloadStarted event.Feed // channel for each download has started
evtDownloadFinished event.Feed // channel for each download task finished
evtDownloadFinishedSubscribed bool
evtDownloadStarted event.Feed // channel for each download has started
evtDownloadStartedSubscribed bool
status status
config Config
@ -127,11 +129,13 @@ func (d *Downloader) SyncStatus() (bool, uint64, uint64) {
// SubscribeDownloadStarted subscribe download started
func (d *Downloader) SubscribeDownloadStarted(ch chan struct{}) event.Subscription {
d.evtDownloadStartedSubscribed = true
return d.evtDownloadStarted.Subscribe(ch)
}
// SubscribeDownloadFinishedEvent subscribe the download finished
// SubscribeDownloadFinished subscribe the download finished
func (d *Downloader) SubscribeDownloadFinished(ch chan struct{}) event.Subscription {
d.evtDownloadFinishedSubscribed = true
return d.evtDownloadFinished.Subscribe(ch)
}
@ -251,12 +255,16 @@ func (d *Downloader) doDownload(initSync bool) (n int, err error) {
func (d *Downloader) startSyncing() {
d.status.startSyncing()
d.evtDownloadStarted.Send(struct{}{})
if d.evtDownloadStartedSubscribed {
d.evtDownloadStarted.Send(struct{}{})
}
}
func (d *Downloader) finishSyncing() {
d.status.finishSyncing()
d.evtDownloadFinished.Send(struct{}{})
if d.evtDownloadFinishedSubscribed {
d.evtDownloadFinished.Send(struct{}{})
}
}
var emptySigVerifyErr *sigVerifyErr

Loading…
Cancel
Save