diff --git a/cl/phase1/stages/stage_history_download.go b/cl/phase1/stages/stage_history_download.go index 7ab307901..f8cc5c99c 100644 --- a/cl/phase1/stages/stage_history_download.go +++ b/cl/phase1/stages/stage_history_download.go @@ -88,12 +88,16 @@ func SpawnStageHistoryDownload(cfg StageHistoryReconstructionCfg, ctx context.Co return err } defer tx.Rollback() + + bytesReadIn15Seconds := atomic.Uint64{} // Set up onNewBlock callback cfg.downloader.SetOnNewBlock(func(blk *cltypes.SignedBeaconBlock) (finished bool, err error) { if blk.Version() >= clparams.BellatrixVersion { currEth1Progress.Store(int64(blk.Block.Body.ExecutionPayload.BlockNumber)) } + bytesReadIn15Seconds.Add(uint64(blk.EncodingSizeSSZ())) + slot := blk.Block.Slot if destinationSlot <= blk.Block.Slot { if err := cfg.db.WriteBlock(ctx, tx, blk, true); err != nil { @@ -128,6 +132,18 @@ func SpawnStageHistoryDownload(cfg StageHistoryReconstructionCfg, ctx context.Co logInterval := time.NewTicker(logIntervalTime) finishCh := make(chan struct{}) // Start logging thread + + go func() { + t := time.NewTicker(15 * time.Second) + for { + select { + case <-t.C: + bytesReadIn15Seconds.Store(0) + case <-ctx.Done(): + return + } + } + }() go func() { for { select { @@ -143,7 +159,8 @@ func SpawnStageHistoryDownload(cfg StageHistoryReconstructionCfg, ctx context.Co } logArgs := []interface{}{} currProgress := cfg.downloader.Progress() - speed := float64(prevProgress-currProgress) / float64(logIntervalTime/time.Second) + blockProgress := float64(prevProgress - currProgress) + speed := blockProgress / float64(logIntervalTime/time.Second) prevProgress = currProgress peerCount, err := cfg.downloader.Peers() if err != nil { @@ -153,6 +170,7 @@ func SpawnStageHistoryDownload(cfg StageHistoryReconstructionCfg, ctx context.Co "slot", currProgress, "blockNumber", currEth1Progress.Load(), "blk/sec", fmt.Sprintf("%.1f", speed), + "mbps/sec", fmt.Sprintf("%.4f", float64(bytesReadIn15Seconds.Load())/(1000*1000*15)), "peers", peerCount) logger.Info("Downloading History", logArgs...) case <-finishCh: