@@ -358,9 +358,10 @@ type vmExecutorConfig struct {
358358}
359359
360360type vmExecutor struct {
361- config vmExecutorConfig
362- vm block.ChainVM
363- metrics * consensusMetrics
361+ config vmExecutorConfig
362+ vm block.ChainVM
363+ metrics * consensusMetrics
364+ etaTracker * timer.EtaTracker
364365}
365366
366367func newVMExecutor (vm block.ChainVM , config vmExecutorConfig ) (* vmExecutor , error ) {
@@ -373,6 +374,10 @@ func newVMExecutor(vm block.ChainVM, config vmExecutorConfig) (*vmExecutor, erro
373374 vm : vm ,
374375 metrics : metrics ,
375376 config : config ,
377+ // ETA tracker uses a 10-sample moving window to smooth rate estimates,
378+ // and a 1.2 slowdown factor to slightly pad ETA early in the run,
379+ // tapering to 1.0 as progress approaches 100%.
380+ etaTracker : timer .NewEtaTracker (10 , 1.2 ),
376381 }, nil
377382}
378383
@@ -409,6 +414,10 @@ func (e *vmExecutor) executeSequence(ctx context.Context, blkChan <-chan blockRe
409414 zap .Uint64 ("height" , blk .Height ()),
410415 )
411416
417+ // Initialize ETA tracking with a baseline sample at 0 progress
418+ totalWork := e .config .EndBlock - e .config .StartBlock
419+ e .etaTracker .AddSample (0 , totalWork , start )
420+
412421 if e .config .ExecutionTimeout > 0 {
413422 var cancel context.CancelFunc
414423 ctx , cancel = context .WithTimeout (ctx , e .config .ExecutionTimeout )
@@ -421,15 +430,20 @@ func (e *vmExecutor) executeSequence(ctx context.Context, blkChan <-chan blockRe
421430 }
422431
423432 if blkResult .Height % 1000 == 0 {
424- eta := timer .EstimateETA (
425- start ,
426- blkResult .Height - e .config .StartBlock ,
427- e .config .EndBlock - e .config .StartBlock ,
428- )
429- e .config .Log .Info ("executing block" ,
430- zap .Uint64 ("height" , blkResult .Height ),
431- zap .Duration ("eta" , eta ),
432- )
433+ completed := blkResult .Height - e .config .StartBlock
434+ etaPtr , progressPercentage := e .etaTracker .AddSample (completed , totalWork , time .Now ())
435+ if etaPtr != nil {
436+ e .config .Log .Info ("executing block" ,
437+ zap .Uint64 ("height" , blkResult .Height ),
438+ zap .Float64 ("progress_pct" , progressPercentage ),
439+ zap .Duration ("eta" , * etaPtr ),
440+ )
441+ } else {
442+ e .config .Log .Info ("executing block" ,
443+ zap .Uint64 ("height" , blkResult .Height ),
444+ zap .Float64 ("progress_pct" , progressPercentage ),
445+ )
446+ }
433447 }
434448 if err := e .execute (ctx , blkResult .BlockBytes ); err != nil {
435449 return err
0 commit comments