-
Notifications
You must be signed in to change notification settings - Fork 68
Add metrics for finalize batch check #820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThis PR introduces a new Prometheus gauge metric to track whether there are batches pending finalization. It adds the metric field and setter to the Metrics struct with full lifecycle management, then implements detection logic in the rollup service to identify when a finalize batch lies outside the challenge window and expose that state via the metric. Changes
Sequence Diagram(s)sequenceDiagram
participant Rollup as Rollup Service
participant Metrics as Metrics
participant Prometheus as Prometheus Registry
Note over Rollup: Periodic status update loop
Rollup->>Rollup: Check for pending finalize batch
Rollup->>Rollup: Verify batch outside challenge window
alt Batch found and outside window
Rollup->>Metrics: SetHasPendingFinalizeBatch(true)
Metrics->>Prometheus: Update gauge to 1
else No pending batch or inside window
Rollup->>Metrics: SetHasPendingFinalizeBatch(false)
Metrics->>Prometheus: Update gauge to 0
else Error checking challenge window
Note over Rollup: Log warning, leave as false
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
tx-submitter/services/rollup.go (1)
205-219: Preserve previous metric value on challenge-window RPC errorsThe detection logic for a finalizable batch (committed > finalized and
!BatchInsideChallengeWindow(nextToFinalize)) looks correct and consistent withfinalize(). The only nit is error handling: whenBatchInsideChallengeWindowerrors, you log a warning but still callSetHasPendingFinalizeBatch(false), which can incorrectly flip the metric from 1→0 on a transient RPC/revert issue, unlike the rest of this loop where youreturnon failures and keep existing values.You can align behavior with the other metrics by bailing out on error so the gauge stays unchanged on failures:
- inWindow, err := r.Rollup.BatchInsideChallengeWindow(nil, nextToFinalize) - if err != nil { - log.Warn("check challenge window error", "error", err, "batch_index", nextToFinalize.Uint64()) - } else if !inWindow { - // Batch is outside challenge window and ready to finalize - hasPendingFinalizeBatch = true - } + inWindow, err := r.Rollup.BatchInsideChallengeWindow(nil, nextToFinalize) + if err != nil { + log.Warn("check challenge window error", "error", err, "batch_index", nextToFinalize.Uint64()) + return + } + if !inWindow { + // Batch is outside challenge window and ready to finalize + hasPendingFinalizeBatch = true + }This keeps the metric stable when you can’t reliably determine the state.
tx-submitter/metrics/metrics.go (2)
15-30: Gauge wiring is solid; tweak metric description for precisionThe new
HasPendingFinalizeBatchgauge is correctly added to the struct, initialized, registered, and unregistered — the plumbing looks good.Given the actual logic in
rollup.goonly sets this to 1 when the next batch to finalize is outside the challenge window (i.e., ready to be finalized), you might want the Help text to reflect that more precisely:- HasPendingFinalizeBatch: prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "tx_submitter_has_pending_finalize_batch", - Help: "Whether there are batches pending finalization (1 = yes, 0 = no)", - }), + HasPendingFinalizeBatch: prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "tx_submitter_has_pending_finalize_batch", + Help: "Whether at least one committed batch is past its challenge window and pending finalization (1 = yes, 0 = no)", + }),That keeps the metric semantics in sync with the comment and implementation in
rollup.go.Also applies to: 75-79, 104-104, 211-212
153-161: Setter semantics match usage; consider clarifying comment
SetHasPendingFinalizeBatchdoing a simplebool→{0,1}mapping is idiomatic for Prometheus gauges and matches how you use it from the rollup service.To keep the exported API self-describing, you could mirror the more precise wording from the metric help string in the comment:
-// SetHasPendingFinalizeBatch sets whether there are batches pending finalization -// hasPending should be true if there are pending batches, false otherwise +// SetHasPendingFinalizeBatch sets whether at least one committed batch is past +// its challenge window and pending finalization. +// hasPending should be true if such a batch exists, false otherwise.Implementation-wise this method is fine as-is.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
go.work.sumis excluded by!**/*.sum
📒 Files selected for processing (2)
tx-submitter/metrics/metrics.go(5 hunks)tx-submitter/services/rollup.go(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tx-submitter/services/rollup.go (1)
bindings/bindings/rollup.go (1)
Rollup(82-86)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: test
- GitHub Check: Analyze (rust)
- GitHub Check: Analyze (go)
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.