Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions tests/reexecute/c/vm_reexecute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,10 @@ type vmExecutorConfig struct {
}

type vmExecutor struct {
config vmExecutorConfig
vm block.ChainVM
metrics *consensusMetrics
config vmExecutorConfig
vm block.ChainVM
metrics *consensusMetrics
etaTracker *timer.EtaTracker
}

func newVMExecutor(vm block.ChainVM, config vmExecutorConfig) (*vmExecutor, error) {
Expand All @@ -350,6 +351,10 @@ func newVMExecutor(vm block.ChainVM, config vmExecutorConfig) (*vmExecutor, erro
vm: vm,
metrics: metrics,
config: config,
// ETA tracker uses a 10-sample moving window to smooth rate estimates,
// and a 1.2 slowdown factor to slightly pad ETA early in the run,
// tapering to 1.0 as progress approaches 100%.
etaTracker: timer.NewEtaTracker(10, 1.2),
}, nil
}

Expand Down Expand Up @@ -386,6 +391,10 @@ func (e *vmExecutor) executeSequence(ctx context.Context, blkChan <-chan blockRe
zap.Uint64("height", blk.Height()),
)

// Initialize ETA tracking with a baseline sample at 0 progress
totalWork := e.config.EndBlock - e.config.StartBlock
e.etaTracker.AddSample(0, totalWork, start)

if e.config.ExecutionTimeout > 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, e.config.ExecutionTimeout)
Expand All @@ -398,15 +407,20 @@ func (e *vmExecutor) executeSequence(ctx context.Context, blkChan <-chan blockRe
}

if blkResult.Height%1000 == 0 {
eta := timer.EstimateETA(
start,
blkResult.Height-e.config.StartBlock,
e.config.EndBlock-e.config.StartBlock,
)
e.config.Log.Info("executing block",
zap.Uint64("height", blkResult.Height),
zap.Duration("eta", eta),
)
completed := blkResult.Height - e.config.StartBlock
etaPtr, progressPercentage := e.etaTracker.AddSample(completed, totalWork, time.Now())
if etaPtr != nil {
e.config.Log.Info("executing block",
zap.Uint64("height", blkResult.Height),
zap.Float64("progress_pct", progressPercentage),
zap.Duration("eta", *etaPtr),
)
} else {
e.config.Log.Info("executing block",
zap.Uint64("height", blkResult.Height),
zap.Float64("progress_pct", progressPercentage),
)
}
}
if err := e.execute(ctx, blkResult.BlockBytes); err != nil {
return err
Expand Down