Skip to content

Commit b599ffe

Browse files
feat(taiko-client): add more preconfirmation metrics (#19523)
1 parent bb1fec4 commit b599ffe

File tree

4 files changed

+48
-16
lines changed

4 files changed

+48
-16
lines changed

packages/taiko-client/driver/preconf_blocks/api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/modern-go/reflect2"
1818

1919
"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/encoding"
20+
"github.com/taikoxyz/taiko-mono/packages/taiko-client/internal/metrics"
2021
"github.com/taikoxyz/taiko-mono/packages/taiko-client/pkg/utils"
2122
)
2223

@@ -232,6 +233,8 @@ func (s *PreconfBlockAPIServer) BuildPreconfBlock(c echo.Context) error {
232233
)
233234
}
234235

236+
metrics.DriverL2PreconfBlocksFromRPCGauge.Inc()
237+
235238
return c.JSON(http.StatusOK, BuildPreconfBlockResponseBody{BlockHeader: header})
236239
}
237240

packages/taiko-client/driver/preconf_blocks/queue.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/ethereum-optimism/optimism/op-service/eth"
88
"github.com/ethereum/go-ethereum/common"
9+
"github.com/taikoxyz/taiko-mono/packages/taiko-client/internal/metrics"
910
)
1011

1112
// maxTrackedPayloads is the maximum number of prepared payloads the execution
@@ -45,6 +46,7 @@ func (q *payloadQueue) put(id uint64, payload *eth.ExecutionPayload) {
4546
payload: payload,
4647
}
4748
q.totalCached++
49+
metrics.DriverPreconfEnvelopeCachedCounter.Inc()
4850
}
4951

5052
// get retrieves a previously stored payload item or nil if it does not exist.

packages/taiko-client/driver/preconf_blocks/server.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ func (s *PreconfBlockAPIServer) OnUnsafeL2Payload(
209209

210210
if msg == nil || msg.ExecutionPayload == nil {
211211
log.Warn("Empty preconfirmation block payload", "peer", from)
212+
metrics.DriverPreconfInvalidEnvelopeCounter.Inc()
212213
return nil
213214
}
214215

@@ -223,6 +224,7 @@ func (s *PreconfBlockAPIServer) OnUnsafeL2Payload(
223224
"gasUsed", uint64(msg.ExecutionPayload.GasUsed),
224225
"endOfSequencing", msg.EndOfSequencing != nil,
225226
)
227+
metrics.DriverPreconfEnvelopeCounter.Inc()
226228

227229
// Check if the payload is valid.
228230
if err := s.ValidateExecutionPayload(msg.ExecutionPayload); err != nil {
@@ -234,7 +236,7 @@ func (s *PreconfBlockAPIServer) OnUnsafeL2Payload(
234236
"parentHash", msg.ExecutionPayload.ParentHash.Hex(),
235237
"error", err,
236238
)
237-
metrics.DriverPreconfP2PInvalidEnvelopeCounter.Inc()
239+
metrics.DriverPreconfInvalidEnvelopeCounter.Inc()
238240
return nil
239241
}
240242

@@ -260,8 +262,6 @@ func (s *PreconfBlockAPIServer) OnUnsafeL2Payload(
260262
return nil
261263
}
262264

263-
metrics.DriverPreconfP2PEnvelopeCounter.Inc()
264-
265265
// Ensure the preconfirmation block number is greater than the current head L1 origin block ID.
266266
headL1Origin, err := checkMessageBlockNumber(ctx, s.rpc, msg)
267267
if err != nil {
@@ -303,6 +303,8 @@ func (s *PreconfBlockAPIServer) OnUnsafeL2Response(
303303
return nil
304304
}
305305

306+
metrics.DriverPreconfOnL2UnsafeResponseCounter.Inc()
307+
306308
// Ignore the message if it is in the cache already.
307309
if s.payloadsCache.has(uint64(msg.ExecutionPayload.BlockNumber), msg.ExecutionPayload.BlockHash) {
308310
log.Debug(
@@ -324,7 +326,7 @@ func (s *PreconfBlockAPIServer) OnUnsafeL2Response(
324326
"parentHash", msg.ExecutionPayload.ParentHash.Hex(),
325327
"error", err,
326328
)
327-
metrics.DriverPreconfP2PInvalidEnvelopeCounter.Inc()
329+
metrics.DriverPreconfInvalidEnvelopeCounter.Inc()
328330
return nil
329331
}
330332

@@ -355,8 +357,6 @@ func (s *PreconfBlockAPIServer) OnUnsafeL2Response(
355357
"transactions", len(msg.ExecutionPayload.Transactions),
356358
)
357359

358-
metrics.DriverPreconfP2PResponseEnvelopeCounter.Inc()
359-
360360
// Ensure the preconfirmation block number is greater than the current head L1 origin block ID.
361361
headL1Origin, err := checkMessageBlockNumber(ctx, s.rpc, msg)
362362
if err != nil {
@@ -401,6 +401,8 @@ func (s *PreconfBlockAPIServer) OnUnsafeL2Request(
401401

402402
log.Info("🔊 New preconfirmation block request from P2P network", "peer", from, "hash", hash.Hex())
403403

404+
metrics.DriverPreconfOnL2UnsafeRequestCounter.Inc()
405+
404406
headL1Origin, err := s.rpc.L2.HeadL1Origin(ctx)
405407
if err != nil && err.Error() != ethereum.NotFound.Error() {
406408
return fmt.Errorf("failed to fetch head L1 origin: %w", err)
@@ -476,6 +478,8 @@ func (s *PreconfBlockAPIServer) OnUnsafeL2EndOfSequencingRequest(
476478
"epoch", epoch,
477479
)
478480

481+
metrics.DriverPreconfOnEndOfSequencingRequestCounter.Inc()
482+
479483
hash, ok := s.sequencingEndedForEpochCache.Get(epoch)
480484
if !ok {
481485
return fmt.Errorf("failed to find the end of sequencing block for the given epoch: %d", epoch)
@@ -635,6 +639,8 @@ func (s *PreconfBlockAPIServer) ImportMissingAncientsFromCache(
635639
return fmt.Errorf("failed to insert ancient preconfirmation blocks from cache: %w", err)
636640
}
637641

642+
metrics.DriverImportedPreconBlocksFromCacheCounter.Add(float64(len(payloadsToImport)))
643+
638644
return nil
639645
}
640646

@@ -663,6 +669,8 @@ func (s *PreconfBlockAPIServer) ImportChildBlocksFromCache(
663669
return fmt.Errorf("failed to insert child preconfirmation blocks from cache: %w", err)
664670
}
665671

672+
metrics.DriverImportedPreconBlocksFromCacheCounter.Add(float64(len(childPayloads)))
673+
666674
return nil
667675
}
668676

@@ -794,7 +802,7 @@ func (s *PreconfBlockAPIServer) GetLookahead() *Lookahead {
794802
}
795803

796804
// CheckLookaheadHandover returns nil if feeRecipient is allowed to build at slot globalSlot (absolute L1 slot).
797-
// and checks the handover window to see if we need to request the end of sequencing
805+
// and checks the handover window to see if we need to request the end of sequencing
798806
// block.
799807
func (s *PreconfBlockAPIServer) CheckLookaheadHandover(feeRecipient common.Address, globalSlot uint64) error {
800808
s.lookaheadMutex.Lock()
@@ -868,6 +876,8 @@ func (s *PreconfBlockAPIServer) recordLatestSeenProposal(proposal *encoding.Last
868876
"lastBlockID", proposal.Pacaya().GetLastBlockID(),
869877
)
870878
s.latestSeenProposal = proposal
879+
metrics.DriverLastSeenBlockInProposalGauge.Set(float64(proposal.Pacaya().GetLastBlockID()))
880+
871881
// If the latest seen proposal is reorged, reset the highest unsafe L2 payload block ID.
872882
if s.latestSeenProposal.PreconfChainReorged {
873883
s.highestUnsafeL2PayloadBlockID = proposal.Pacaya().GetLastBlockID()
@@ -877,6 +887,7 @@ func (s *PreconfBlockAPIServer) recordLatestSeenProposal(proposal *encoding.Last
877887
"lastBlockID", s.highestUnsafeL2PayloadBlockID,
878888
"highestUnsafeL2PayloadBlockID", s.highestUnsafeL2PayloadBlockID,
879889
)
890+
metrics.DriverReorgsByProposalCounter.Inc()
880891
}
881892
}
882893

@@ -1018,6 +1029,7 @@ func (s *PreconfBlockAPIServer) updateHighestUnsafeL2Payload(blockID uint64) {
10181029
)
10191030
}
10201031
s.highestUnsafeL2PayloadBlockID = blockID
1032+
metrics.DriverHighestPreconfUnsafePayloadGauge.Set(float64(blockID))
10211033
}
10221034

10231035
// webSocketSever is a WebSocket server that handles incoming connections,

packages/taiko-client/internal/metrics/metrics.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,36 @@ var (
2626
DriverL1CurrentHeightGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "driver_l1Current_height"})
2727
DriverL2HeadIDGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "driver_l2Head_id"})
2828
DriverL2VerifiedHeightGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "driver_l2Verified_id"})
29-
DriverPreconfP2PEnvelopeCounter = factory.NewCounter(prometheus.CounterOpts{Name: "driver_p2p_envelope"})
30-
DriverPreconfP2PInvalidEnvelopeCounter = factory.NewCounter(prometheus.CounterOpts{
29+
DriverHighestPreconfUnsafePayloadGauge = factory.NewGauge(prometheus.GaugeOpts{Name: "driver_highest_unsafe_payload"})
30+
DriverReorgsByProposalCounter = factory.NewCounter(prometheus.CounterOpts{Name: "driver_reorgs_by_proposal"})
31+
DriverPreconfEnvelopeCounter = factory.NewCounter(prometheus.CounterOpts{Name: "driver_p2p_envelope"})
32+
DriverLastSeenBlockInProposalGauge = factory.NewGauge(prometheus.GaugeOpts{
33+
Name: "driver_last_seen_block_in_proposal",
34+
})
35+
DriverL2PreconfBlocksFromRPCGauge = factory.NewGauge(prometheus.GaugeOpts{
36+
Name: "driver_preconf_blocks_from_rpc",
37+
})
38+
DriverPreconfInvalidEnvelopeCounter = factory.NewCounter(prometheus.CounterOpts{
3139
Name: "driver_p2p_invalid_envelope",
3240
})
33-
DriverPreconfP2POutdatedEnvelopeCounter = factory.NewCounter(prometheus.CounterOpts{
41+
DriverPreconfOutdatedEnvelopeCounter = factory.NewCounter(prometheus.CounterOpts{
3442
Name: "driver_p2p_outdated_envelope",
3543
})
36-
DriverPreconfP2PEnvelopeCachedCounter = factory.NewCounter(prometheus.CounterOpts{
44+
DriverPreconfEnvelopeCachedCounter = factory.NewCounter(prometheus.CounterOpts{
3745
Name: "driver_p2p_envelope_cached",
3846
})
39-
DriverPreconfP2PResponseEnvelopeCounter = factory.NewCounter(
40-
prometheus.CounterOpts{
41-
Name: "driver_p2p_response_envelope",
42-
},
43-
)
47+
DriverPreconfOnL2UnsafeRequestCounter = factory.NewCounter(prometheus.CounterOpts{
48+
Name: "driver_on_l2_unsafe_request",
49+
})
50+
DriverPreconfOnL2UnsafeResponseCounter = factory.NewCounter(prometheus.CounterOpts{
51+
Name: "driver_on_l2_unsafe_response",
52+
})
53+
DriverPreconfOnEndOfSequencingRequestCounter = factory.NewCounter(prometheus.CounterOpts{
54+
Name: "driver_on_end_of_sequencing_request",
55+
})
56+
DriverImportedPreconBlocksFromCacheCounter = factory.NewCounter(prometheus.CounterOpts{
57+
Name: "driver_imported_preconf_blocks_from_cache",
58+
})
4459

4560
// Proposer
4661
ProposerProposeEpochCounter = factory.NewCounter(prometheus.CounterOpts{Name: "proposer_epoch"})

0 commit comments

Comments
 (0)