Skip to content

Conversation

@m-Peter
Copy link
Collaborator

@m-Peter m-Peter commented Jan 9, 2026

Closes: #947

Description

Tracking this field from the EVM.BlockExecuted event payload, can be useful and will allow us to create alerts for abnormal fluctuations on the totalSupply value.


For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Summary by CodeRabbit

  • New Features
    • Added total supply metrics: the system now collects and exposes the total supply of Flow tokens as a new metric. This metric is automatically gathered during block processing and published alongside existing metrics, improving observability and supply monitoring.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 9, 2026

📝 Walkthrough

Walkthrough

This change adds a Prometheus gauge flow_total_supply, a FlowTotalSupply(*big.Int) method to the Collector interface and its implementations, and emits the metric from the ingestion engine when processing EVM block events.

Changes

Cohort / File(s) Summary
Collector interface & DefaultCollector
metrics/collector.go
Add FlowTotalSupply(totalSupply *big.Int) to Collector; add flowTotalSupply prometheus.Gauge and logger zerolog.Logger fields to DefaultCollector; register flow_total_supply gauge and initialize in NewCollector; implement method converting *big.Int to float, warn on precision loss, update gauge.
No-op collector
metrics/nop.go
Add FlowTotalSupply(totalSupply *big.Int) no-op implementation and import math/big.
Ingestion metric emission
services/ingestion/engine.go
Emit FlowTotalSupply from processEvents using total supply extracted from the EVM block payload.

Sequence Diagram(s)

sequenceDiagram
    participant Ingest as Ingestion Engine
    participant Collector as Collector (interface)
    participant Default as DefaultCollector
    participant Prom as Prometheus

    Ingest->>Collector: FlowTotalSupply(totalSupply *big.Int)
    Collector->>Default: FlowTotalSupply(totalSupply)
    Default->>Default: convert big.Int -> float64 (check precision)
    Default-->>Prom: Set gauge flow_total_supply value
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • zhangchiqing
  • janezpodhostnik
  • peterargue

Poem

🐰
I hopped through code with metrics bright,
Counting Flow by block and night,
Big ints danced and gauges grew,
Prometheus hummed a monitoring tune,
Carrots measured, all in sight 🥕📈

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding a metric to track Flow total supply per block.
Linked Issues check ✅ Passed The PR fully satisfies issue #947 requirements: extracts totalSupply from EVM.BlockExecuted event, records it as a Prometheus gauge metric, and enables monitoring for abnormal fluctuations.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the linked issue: new Prometheus gauge metric, collector interface/implementation updates, and metric emission in the ingestion engine are all required for tracking totalSupply.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In @metrics/collector.go:
- Around line 259-262: In DefaultCollector.FlowTotalSupply, add a nil check for
the totalSupply parameter to avoid panics and replace the blind
totalSupply.Float64() call with a safe conversion that checks the returned
Accuracy and handles overflow/precision loss: convert the *big.Int to a
big.Float (e.g., big.NewFloat(0).SetInt(totalSupply)), call bigFloat.Float64()
and inspect the accuracy (big.Exact/Above/Below) or detect +Inf; if nil or
conversion is inaccurate/overflowing, log or clamp to a sensible value (or skip
updating) instead of silently setting an imprecise metric when calling
c.flowTotalSupply.Set.

In @services/ingestion/engine.go:
- Line 215: The call passes events.Block().TotalSupply (a *big.Int) directly
into e.collector.FlowTotalSupply which can panic when TotalSupply is nil; add a
nil guard before calling FlowTotalSupply (e.g., check events.Block() != nil &&
events.Block().TotalSupply != nil) and only call e.collector.FlowTotalSupply
when TotalSupply is non-nil, or alternatively update metrics/collector.go's
FlowTotalSupply to defensively handle a nil *big.Int by treating it as zero or
returning early—modify either the call site in engine.go (around
e.collector.FlowTotalSupply) or the FlowTotalSupply method to handle nil inputs.
🧹 Nitpick comments (1)
metrics/collector.go (1)

90-93: Consider clarifying the help text.

The help text "Total supply of native EVM FLOW token at a given time" contains "native EVM FLOW token" which might be clearer as "FLOW tokens in EVM" or simply "EVM FLOW supply".

📝 Suggested help text improvement
 var flowTotalSupply = prometheus.NewGauge(prometheus.GaugeOpts{
 	Name: prefixedName("flow_total_supply"),
-	Help: "Total supply of native EVM FLOW token at a given time",
+	Help: "Total supply of FLOW tokens in EVM at a given time",
 })
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 576c361 and 1292926.

📒 Files selected for processing (3)
  • metrics/collector.go
  • metrics/nop.go
  • services/ingestion/engine.go
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-10-18T19:26:37.579Z
Learnt from: peterargue
Repo: onflow/flow-evm-gateway PR: 617
File: api/stream.go:62-67
Timestamp: 2024-10-18T19:26:37.579Z
Learning: In the `flow-evm-gateway` project, within the Go file `api/stream.go`, the `prepareBlockResponse` method includes the Bloom filter as the field `LogsBloom` in the returned `Block` struct.

Applied to files:

  • services/ingestion/engine.go
⏰ 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). (1)
  • GitHub Check: Test
🔇 Additional comments (2)
metrics/nop.go (1)

4-4: LGTM!

The no-op implementation correctly satisfies the updated Collector interface with the appropriate signature.

Also applies to: 28-28

metrics/collector.go (1)

111-111: LGTM!

The gauge is correctly registered in the metrics slice, added to the interface, included in the struct, and properly initialized in the constructor.

Also applies to: 129-129, 151-151, 176-176

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 (1)
metrics/collector.go (1)

90-93: Clarify the unit of measurement in the help text.

The help text should specify whether flow_total_supply represents the smallest unit (similar to wei in Ethereum) or whole FLOW tokens. This clarity will help operators correctly interpret the metric values and set appropriate alert thresholds.

📝 Suggested help text improvement
 var flowTotalSupply = prometheus.NewGauge(prometheus.GaugeOpts{
 	Name: prefixedName("flow_total_supply"),
-	Help: "Total supply of FLOW tokens in EVM at a given time",
+	Help: "Total supply of FLOW tokens in EVM at a given time (in smallest unit)",
 })
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1292926 and 4f61e97.

📒 Files selected for processing (1)
  • metrics/collector.go
⏰ 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). (1)
  • GitHub Check: Test
🔇 Additional comments (6)
metrics/collector.go (6)

5-5: LGTM!

The math/big import is appropriate for handling large FLOW token supply values that may exceed standard integer types.


111-111: LGTM!

The flowTotalSupply metric is correctly added to the registration list.


129-129: LGTM!

The method signature correctly uses *big.Int to handle potentially large FLOW token supply values.


135-135: LGTM!

Adding the logger field to DefaultCollector enables proper logging of precision loss warnings in the FlowTotalSupply method. The initialization in NewCollector is correct.

Also applies to: 163-163


153-153: LGTM!

The flowTotalSupply field and its initialization follow the established pattern for metric collection in this codebase.

Also applies to: 179-179


262-273: Verify that float64 precision is sufficient for the expected total supply values.

The conversion from *big.Int to float64 will lose precision for values exceeding 2^53 (~9 × 10^15). If the total supply is measured in the smallest unit (similar to wei in Ethereum), values may frequently exceed this threshold, leading to:

  • Inaccurate absolute values in the metric
  • Potential issues detecting small fluctuations
  • Misleading data for alerting purposes

The nil check and precision loss warning are good defensive measures. However, consider whether:

  1. The expected magnitude of totalSupply values will fit within float64 precision
  2. Converting to a larger unit (e.g., whole FLOW tokens) before the float64 conversion would preserve sufficient precision for your alerting needs
  3. The current precision is adequate for detecting abnormal fluctuations (the stated goal in issue #947)

Could you verify the typical range of totalSupply values and confirm that float64 precision is acceptable for your monitoring and alerting requirements?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add metric to track the totalSupply when indexing EVM blocks

2 participants