From af064a3921110c704c2d7a114ba0b30c7e2e485a Mon Sep 17 00:00:00 2001 From: Martin Boehm Date: Tue, 22 May 2018 17:34:37 +0200 Subject: [PATCH] Store sync and mempool sync state to internal state --- blockbook.go | 3 +++ db/sync.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/blockbook.go b/blockbook.go index 83a71ee7..a3672b42 100644 --- a/blockbook.go +++ b/blockbook.go @@ -350,8 +350,11 @@ func syncMempoolLoop() { glog.Info("syncMempoolLoop starting") // resync mempool about every minute if there are no chanSyncMempool requests, with debounce 1 second tickAndDebounce(resyncMempoolPeriodMs*time.Millisecond, debounceResyncMempoolMs*time.Millisecond, chanSyncMempool, func() { + common.IS.StartedMempoolSync() if err := chain.ResyncMempool(onNewTxAddr); err != nil { glog.Error("syncMempoolLoop ", errors.ErrorStack(err)) + } else { + common.IS.FinishedMempoolSync() } }) glog.Info("syncMempoolLoop stopped") diff --git a/db/sync.go b/db/sync.go index 7f25a56a..4e8efbcd 100644 --- a/db/sync.go +++ b/db/sync.go @@ -47,6 +47,7 @@ var errSynced = errors.New("synced") // onNewBlock is called when new block is connected, but not in initial parallel sync func (w *SyncWorker) ResyncIndex(onNewBlock func(hash string)) error { start := time.Now() + common.IS.StartedSync() err := w.resyncIndex(onNewBlock) @@ -56,6 +57,10 @@ func (w *SyncWorker) ResyncIndex(onNewBlock func(hash string)) error { glog.Info("resync: finished in ", d) w.metrics.IndexResyncDuration.Observe(float64(d) / 1e6) // in milliseconds w.metrics.IndexDBSize.Set(float64(w.db.DatabaseSizeOnDisk())) + bh, _, err := w.db.GetBestBlock() + if err == nil { + common.IS.FinishedSync(bh) + } fallthrough case errSynced: // this is not actually error but flag that resync wasn't necessary