Store sync and mempool sync state to internal state

pull/7/head
Martin Boehm 2018-05-22 17:34:37 +02:00
parent 291e99ba5f
commit af064a3921
2 changed files with 8 additions and 0 deletions

View File

@ -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")

View File

@ -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