From e5e8da96616ea9399f9727d7588f89bdd491cd25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Thu, 26 Jul 2018 14:23:18 +0300 Subject: [PATCH] core: polish up chain export progress report a bit --- core/blockchain.go | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index d0c2c7bd3c..bc072bd4b0 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -448,30 +448,21 @@ func (bc *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error { if first > last { return fmt.Errorf("export failed: first (%d) is greater than last (%d)", first, last) } - batchSize := last - first + 1 - log.Info("Exporting batch of blocks", "count", batchSize) + log.Info("Exporting batch of blocks", "count", last-first+1) - exportTimeElapsed := mclock.Now() + start, reported := time.Now(), time.Now() for nr := first; nr <= last; nr++ { block := bc.GetBlockByNumber(nr) - var ( - now = mclock.Now() - elapsed = time.Duration(now) - time.Duration(exportTimeElapsed) - ) - - if elapsed >= statsReportLimit { - exportedBlocks := block.NumberU64() - first - log.Info("Exporting blocks", "exported", exportedBlocks, "elapsed", common.PrettyDuration(elapsed)) - exportTimeElapsed = mclock.Now() - } - if block == nil { return fmt.Errorf("export failed on #%d: not found", nr) } - if err := block.EncodeRLP(w); err != nil { return err } + if time.Since(reported) >= statsReportLimit { + log.Info("Exporting blocks", "exported", block.NumberU64()-first, "elapsed", common.PrettyDuration(time.Since(start))) + reported = time.Now() + } } return nil @@ -1216,8 +1207,8 @@ type insertStats struct { startTime mclock.AbsTime } -// statsReportLimit is the time limit during import and export after which we always print -// out progress. This avoids the user wondering what's going on. +// statsReportLimit is the time limit during import and export after which we +// always print out progress. This avoids the user wondering what's going on. const statsReportLimit = 8 * time.Second // report prints statistics if some number of blocks have been processed