Commit 980064ab authored by Adrian Sutton's avatar Adrian Sutton

op-challenger: Fix recording of cannon execution time.

Previously only recorded failed cannon executions.
parent 174bfbd4
......@@ -124,10 +124,7 @@ func (e *Executor) GenerateProof(ctx context.Context, dir string, i uint64) erro
e.logger.Info("Generating trace", "proof", i, "cmd", e.cannon, "args", strings.Join(args, ", "))
execStart := time.Now()
err = e.cmdExecutor(ctx, e.logger.New("proof", i), e.cannon, args...)
if err != nil {
execDuration := time.Since(execStart).Seconds()
e.metrics.RecordCannonExecutionTime(execDuration)
}
e.metrics.RecordCannonExecutionTime(time.Since(execStart).Seconds())
return err
}
......
......@@ -40,7 +40,8 @@ func TestGenerateProof(t *testing.T) {
L2BlockNumber: big.NewInt(3333),
}
captureExec := func(t *testing.T, cfg config.Config, proofAt uint64) (string, string, map[string]string) {
executor := NewExecutor(testlog.Logger(t, log.LvlInfo), metrics.NoopMetrics, &cfg, inputs)
m := &cannonDurationMetrics{}
executor := NewExecutor(testlog.Logger(t, log.LvlInfo), m, &cfg, inputs)
executor.selectSnapshot = func(logger log.Logger, dir string, absolutePreState string, i uint64) (string, error) {
return input, nil
}
......@@ -63,6 +64,7 @@ func TestGenerateProof(t *testing.T) {
}
err := executor.GenerateProof(context.Background(), dir, proofAt)
require.NoError(t, err)
require.Equal(t, 1, m.executionTimeRecordCount, "Should record cannon execution time")
return binary, subcommand, args
}
......@@ -211,3 +213,12 @@ func TestFindStartingSnapshot(t *testing.T) {
require.Equal(t, filepath.Join(dir, "100.json.gz"), snapshot)
})
}
type cannonDurationMetrics struct {
metrics.NoopMetricsImpl
executionTimeRecordCount int
}
func (c *cannonDurationMetrics) RecordCannonExecutionTime(_ float64) {
c.executionTimeRecordCount++
}
......@@ -4,21 +4,21 @@ import (
txmetrics "github.com/ethereum-optimism/optimism/op-service/txmgr/metrics"
)
type noopMetrics struct {
type NoopMetricsImpl struct {
txmetrics.NoopTxMetrics
}
var NoopMetrics Metricer = new(noopMetrics)
var NoopMetrics Metricer = new(NoopMetricsImpl)
func (*noopMetrics) RecordInfo(version string) {}
func (*noopMetrics) RecordUp() {}
func (*NoopMetricsImpl) RecordInfo(version string) {}
func (*NoopMetricsImpl) RecordUp() {}
func (*noopMetrics) RecordGameMove() {}
func (*noopMetrics) RecordGameStep() {}
func (*NoopMetricsImpl) RecordGameMove() {}
func (*NoopMetricsImpl) RecordGameStep() {}
func (*noopMetrics) RecordCannonExecutionTime(t float64) {}
func (*NoopMetricsImpl) RecordCannonExecutionTime(t float64) {}
func (*noopMetrics) RecordGamesStatus(inProgress, defenderWon, challengerWon int) {}
func (*NoopMetricsImpl) RecordGamesStatus(inProgress, defenderWon, challengerWon int) {}
func (*noopMetrics) RecordGameUpdateScheduled() {}
func (*noopMetrics) RecordGameUpdateCompleted() {}
func (*NoopMetricsImpl) RecordGameUpdateScheduled() {}
func (*NoopMetricsImpl) RecordGameUpdateCompleted() {}
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