Skip to content

Commit 074e2eb

Browse files
committed
op-node: revive async block processing timing log
1 parent eed9012 commit 074e2eb

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

op-node/rollup/engine/payload_success.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"time"
66

77
"github.com/ethereum-optimism/optimism/op-service/eth"
8+
"github.com/ethereum/go-ethereum/common"
89
)
910

1011
type PayloadSuccessEvent struct {
@@ -51,5 +52,42 @@ func (e *EngineController) onPayloadSuccess(ctx context.Context, ev PayloadSucce
5152
err := e.tryUpdateEngineInternal(ctx)
5253
if err != nil {
5354
e.log.Error("Failed to update engine", "error", err)
55+
} else {
56+
updateEngineFinish := time.Now()
57+
e.logBlockProcessingMetrics(updateEngineFinish, ev)
5458
}
5559
}
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

Comments
 (0)