|
5 | 5 | "time" |
6 | 6 |
|
7 | 7 | "github.com/ethereum-optimism/optimism/op-service/eth" |
| 8 | + "github.com/ethereum/go-ethereum/common" |
8 | 9 | ) |
9 | 10 |
|
10 | 11 | type PayloadSuccessEvent struct { |
@@ -51,5 +52,42 @@ func (e *EngineController) onPayloadSuccess(ctx context.Context, ev PayloadSucce |
51 | 52 | err := e.tryUpdateEngineInternal(ctx) |
52 | 53 | if err != nil { |
53 | 54 | e.log.Error("Failed to update engine", "error", err) |
| 55 | + } else { |
| 56 | + updateEngineFinish := time.Now() |
| 57 | + e.logBlockProcessingMetrics(updateEngineFinish, ev) |
54 | 58 | } |
55 | 59 | } |
| 60 | + |
| 61 | +func (e *EngineController) logBlockProcessingMetrics(updateEngineFinish time.Time, ev PayloadSuccessEvent) { |
| 62 | + // Protect against nil pointer dereferences |
| 63 | + if ev.Envelope == nil || ev.Envelope.ExecutionPayload == nil { |
| 64 | + e.log.Debug("Envelope.ExecutionPayload not found, skipping block processing metrics") |
| 65 | + return |
| 66 | + } |
| 67 | + |
| 68 | + buildTime := ev.InsertStarted.Sub(ev.BuildStarted) |
| 69 | + insertTime := updateEngineFinish.Sub(ev.InsertStarted) |
| 70 | + |
| 71 | + var totalTime time.Duration |
| 72 | + if !ev.BuildStarted.IsZero() { |
| 73 | + totalTime = updateEngineFinish.Sub(ev.BuildStarted) |
| 74 | + } else { |
| 75 | + totalTime = insertTime |
| 76 | + } |
| 77 | + |
| 78 | + // Protect against divide-by-zero |
| 79 | + var mgasps float64 |
| 80 | + if totalTime > 0 { |
| 81 | + mgasps = float64(ev.Envelope.ExecutionPayload.GasUsed) * 1000 / float64(totalTime) |
| 82 | + } |
| 83 | + |
| 84 | + e.log.Info("Inserted new L2 unsafe block", |
| 85 | + "hash", ev.Envelope.ExecutionPayload.BlockHash, |
| 86 | + "number", uint64(ev.Envelope.ExecutionPayload.BlockNumber), |
| 87 | + "build_time", common.PrettyDuration(buildTime), |
| 88 | + "insert_time", common.PrettyDuration(insertTime), |
| 89 | + "total_time", common.PrettyDuration(totalTime), |
| 90 | + "mgas", float64(ev.Envelope.ExecutionPayload.GasUsed)/1000000, |
| 91 | + "mgasps", mgasps, |
| 92 | + ) |
| 93 | +} |
0 commit comments