Skip to content

Commit cca18bc

Browse files
authored
op-node: revive async block processing timing log (#17915)
* op-node: revive async block processing timing log * op-node: add clarifying comments to logBlockProcessingMetrics
1 parent 7b57030 commit cca18bc

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

op-node/rollup/engine/payload_success.go

Lines changed: 43 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,47 @@ 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.Info("Envelope.ExecutionPayload not found, skipping block processing metrics")
65+
return
66+
}
67+
68+
mgas := float64(ev.Envelope.ExecutionPayload.GasUsed) / 1e6
69+
buildTime := time.Duration(0)
70+
insertTime := updateEngineFinish.Sub(ev.InsertStarted)
71+
totalTime := insertTime
72+
73+
// BuildStarted may be zero if sequencer already built + gossiped a block, but failed during
74+
// insertion and needed a retry of the insertion. In that case we use the default values above,
75+
// otherwise we calculate buildTime and totalTime below
76+
if !ev.BuildStarted.IsZero() {
77+
buildTime = ev.InsertStarted.Sub(ev.BuildStarted)
78+
totalTime = updateEngineFinish.Sub(ev.BuildStarted)
79+
}
80+
81+
// Protect against divide-by-zero
82+
var mgasps float64 // Mgas/s
83+
if totalTime > 0 {
84+
// Calculate "block-processing" Mgas/s.
85+
// NOTE: "realtime" mgasps (chain throughput) is a different calculation: (GasUsed / blockPeriod)
86+
mgasps = mgas / totalTime.Seconds()
87+
}
88+
89+
e.log.Info("Inserted new L2 unsafe block",
90+
"hash", ev.Envelope.ExecutionPayload.BlockHash,
91+
"number", uint64(ev.Envelope.ExecutionPayload.BlockNumber),
92+
"build_time", common.PrettyDuration(buildTime),
93+
"insert_time", common.PrettyDuration(insertTime),
94+
"total_time", common.PrettyDuration(totalTime),
95+
"mgas", mgas,
96+
"mgasps", mgasps,
97+
)
98+
}

0 commit comments

Comments
 (0)