Commit 11a402f7 authored by Raghav Sood's avatar Raghav Sood Committed by Péter Szilágyi

core: report progress on log chain exports (#17066)

* core/blockchain: export progress

* core: polish up chain export progress report a bit
parent 021d6fbb
...@@ -94,7 +94,8 @@ processing will proceed even if an individual RLP-file import failure occurs.`, ...@@ -94,7 +94,8 @@ processing will proceed even if an individual RLP-file import failure occurs.`,
Requires a first argument of the file to write to. Requires a first argument of the file to write to.
Optional second and third arguments control the first and Optional second and third arguments control the first and
last block to write. In this mode, the file will be appended last block to write. In this mode, the file will be appended
if already existing.`, if already existing. If the file ends with .gz, the output will
be gzipped.`,
} }
importPreimagesCommand = cli.Command{ importPreimagesCommand = cli.Command{
Action: utils.MigrateFlags(importPreimages), Action: utils.MigrateFlags(importPreimages),
......
...@@ -450,15 +450,19 @@ func (bc *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error { ...@@ -450,15 +450,19 @@ func (bc *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error {
} }
log.Info("Exporting batch of blocks", "count", last-first+1) log.Info("Exporting batch of blocks", "count", last-first+1)
start, reported := time.Now(), time.Now()
for nr := first; nr <= last; nr++ { for nr := first; nr <= last; nr++ {
block := bc.GetBlockByNumber(nr) block := bc.GetBlockByNumber(nr)
if block == nil { if block == nil {
return fmt.Errorf("export failed on #%d: not found", nr) return fmt.Errorf("export failed on #%d: not found", nr)
} }
if err := block.EncodeRLP(w); err != nil { if err := block.EncodeRLP(w); err != nil {
return err 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 return nil
...@@ -1203,8 +1207,8 @@ type insertStats struct { ...@@ -1203,8 +1207,8 @@ type insertStats struct {
startTime mclock.AbsTime startTime mclock.AbsTime
} }
// statsReportLimit is the time limit during import after which we always print // statsReportLimit is the time limit during import and export after which we
// out progress. This avoids the user wondering what's going on. // always print out progress. This avoids the user wondering what's going on.
const statsReportLimit = 8 * time.Second const statsReportLimit = 8 * time.Second
// report prints statistics if some number of blocks have been processed // report prints statistics if some number of blocks have been processed
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment