diff --git a/CHANGELOG.md b/CHANGELOG.md index 485e7f9b4e0..b1f6a265cc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Ethrex Changelog +## Observability + +### 2026-05-27 + +- Add BAL (EIP-7928) Prometheus instruments (`bal_blocks_total`, `bal_size_bytes`, `bal_size_bytes_histogram`, `bal_account_count`, `bal_slot_count`) and a BAL row in the `ethrex_l1_perf` Grafana dashboard [#6678](https://github.com/lambdaclass/ethrex/pull/6678) + ## Perf ### 2026-05-19 diff --git a/crates/blockchain/blockchain.rs b/crates/blockchain/blockchain.rs index 225cc5bc65b..ba992e1ebdd 100644 --- a/crates/blockchain/blockchain.rs +++ b/crates/blockchain/blockchain.rs @@ -110,6 +110,8 @@ use tokio_util::sync::CancellationToken; use vm::StoreVmDatabase; +#[cfg(feature = "metrics")] +use ethrex_metrics::bal::METRICS_BAL; #[cfg(feature = "metrics")] use ethrex_metrics::blocks::METRICS_BLOCKS; @@ -1980,6 +1982,17 @@ impl Blockchain { ); } + metrics!(if let Some(bal_ref) = produced_bal.as_ref().or(bal) { + let account_count = bal_ref.accounts().len() as u64; + let slot_count = bal_ref.item_count().saturating_sub(account_count); + let size_bytes = bal_ref.length() as f64; + METRICS_BAL.blocks_total.inc(); + METRICS_BAL.size_bytes.set(size_bytes); + METRICS_BAL.size_bytes_histogram.observe(size_bytes); + METRICS_BAL.account_count.set(account_count as i64); + METRICS_BAL.slot_count.set(slot_count as i64); + }); + Ok((produced_bal, result)) } diff --git a/crates/blockchain/metrics/bal.rs b/crates/blockchain/metrics/bal.rs new file mode 100644 index 00000000000..092dfdf1acf --- /dev/null +++ b/crates/blockchain/metrics/bal.rs @@ -0,0 +1,76 @@ +use prometheus::{ + Gauge, Histogram, IntCounter, IntGauge, register_gauge, register_histogram, + register_int_counter, register_int_gauge, +}; +use std::sync::LazyLock; + +// Metrics defined in this module register into the Prometheus default registry. +// The metrics API exposes them via `gather_default_metrics()`. + +pub static METRICS_BAL: LazyLock = LazyLock::new(MetricsBal::default); + +// Histogram bucket layout for RLP-encoded BAL sizes: 1 KiB base, doubling, 16 +// buckets -> 1 KiB, 2 KiB, 4 KiB, ..., 32 MiB. Observed sizes are always >= 1 +// byte (the smallest BAL RLP-encodes to a non-empty list), so there is no zero +// floor bucket. +const BAL_SIZE_BUCKET_START_BYTES: f64 = 1024.0; +const BAL_SIZE_BUCKET_FACTOR: f64 = 2.0; +const BAL_SIZE_BUCKET_COUNT: usize = 16; + +#[derive(Debug, Clone)] +pub struct MetricsBal { + /// Cumulative count of BAL-carrying blocks processed (post-Amsterdam). + pub blocks_total: IntCounter, + /// RLP-encoded size of the most recent BAL, in bytes (per-block snapshot). + pub size_bytes: Gauge, + /// Distribution of RLP-encoded BAL sizes in bytes. + pub size_bytes_histogram: Histogram, + /// Number of accounts in the most recent BAL (per-block snapshot). + pub account_count: IntGauge, + /// Unique storage slots (writes + reads) in the most recent BAL (per-block snapshot). + pub slot_count: IntGauge, +} + +impl Default for MetricsBal { + fn default() -> Self { + Self::new() + } +} + +impl MetricsBal { + pub fn new() -> Self { + MetricsBal { + blocks_total: register_int_counter!( + "bal_blocks_total", + "Cumulative count of Block Access List (EIP-7928) carrying blocks processed" + ) + .expect("Failed to create bal_blocks_total metric"), + size_bytes: register_gauge!( + "bal_size_bytes", + "RLP-encoded size of the most recent Block Access List, in bytes" + ) + .expect("Failed to create bal_size_bytes metric"), + size_bytes_histogram: register_histogram!( + "bal_size_bytes_histogram", + "Distribution of RLP-encoded Block Access List sizes in bytes", + prometheus::exponential_buckets( + BAL_SIZE_BUCKET_START_BYTES, + BAL_SIZE_BUCKET_FACTOR, + BAL_SIZE_BUCKET_COUNT, + ) + .expect("Invalid BAL histogram bucket params") + ) + .expect("Failed to create bal_size_bytes_histogram metric"), + account_count: register_int_gauge!( + "bal_account_count", + "Number of accounts in the most recent Block Access List" + ) + .expect("Failed to create bal_account_count metric"), + slot_count: register_int_gauge!( + "bal_slot_count", + "Unique storage slots (writes + reads) in the most recent BAL" + ) + .expect("Failed to create bal_slot_count metric"), + } + } +} diff --git a/crates/blockchain/metrics/mod.rs b/crates/blockchain/metrics/mod.rs index 82df7e57065..f162628b9b6 100644 --- a/crates/blockchain/metrics/mod.rs +++ b/crates/blockchain/metrics/mod.rs @@ -1,6 +1,8 @@ #[cfg(feature = "api")] pub mod api; #[cfg(any(feature = "api", feature = "metrics"))] +pub mod bal; +#[cfg(any(feature = "api", feature = "metrics"))] pub mod blocks; #[cfg(feature = "api")] pub mod l2; diff --git a/metrics/provisioning/grafana/dashboards/common_dashboards/ethrex_l1_perf.json b/metrics/provisioning/grafana/dashboards/common_dashboards/ethrex_l1_perf.json index 43ad6d11665..a17ef407428 100644 --- a/metrics/provisioning/grafana/dashboards/common_dashboards/ethrex_l1_perf.json +++ b/metrics/provisioning/grafana/dashboards/common_dashboards/ethrex_l1_perf.json @@ -1554,6 +1554,524 @@ "title": "Block Execution Breakdown ", "type": "row" }, + { + "collapsed": true, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 26 + }, + "id": 300, + "panels": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "description": "Rate of EIP-7928 BAL-carrying blocks processed.", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "showValues": false, + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": 0 + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "cps" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 6, + "x": 0, + "y": 27 + }, + "id": 301, + "interval": "10s", + "options": { + "legend": { + "calcs": [ + "mean", + "max" + ], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "hideZeros": false, + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "12.2.1", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "rate(bal_blocks_total{job=\"$job\", instance=~\"$instance(:\\\\d+)?$\"}[$__rate_interval])", + "instant": false, + "legendFormat": "{{instance}}", + "range": true, + "refId": "A" + } + ], + "title": "BAL Blocks Rate", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "description": "RLP-encoded size of the most recent BAL.", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "showValues": false, + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": 0 + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "bytes" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 6, + "x": 6, + "y": 27 + }, + "id": 302, + "interval": "10s", + "options": { + "legend": { + "calcs": [ + "mean", + "max" + ], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "hideZeros": false, + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "12.2.1", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "bal_size_bytes{job=\"$job\", instance=~\"$instance(:\\\\d+)?$\"}", + "instant": false, + "legendFormat": "{{instance}}", + "range": true, + "refId": "A" + } + ], + "title": "BAL Size (bytes)", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "description": "Number of accounts in the most recent BAL.", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "showValues": false, + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": 0 + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "short" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 6, + "x": 12, + "y": 27 + }, + "id": 304, + "interval": "10s", + "options": { + "legend": { + "calcs": [ + "mean", + "max" + ], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "hideZeros": false, + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "12.2.1", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "bal_account_count{job=\"$job\", instance=~\"$instance(:\\\\d+)?$\"}", + "instant": false, + "legendFormat": "{{instance}}", + "range": true, + "refId": "A" + } + ], + "title": "BAL Account Count", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "description": "Unique storage slots (writes + reads) in the most recent BAL.", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "showValues": false, + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": 0 + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "short" + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 6, + "x": 18, + "y": 27 + }, + "id": 305, + "interval": "10s", + "options": { + "legend": { + "calcs": [ + "mean", + "max" + ], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "hideZeros": false, + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "12.2.1", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "bal_slot_count{job=\"$job\", instance=~\"$instance(:\\\\d+)?$\"}", + "instant": false, + "legendFormat": "{{instance}}", + "range": true, + "refId": "A" + } + ], + "title": "BAL Slot Count", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "description": "Distribution of BAL sizes (heatmap of histogram buckets).", + "fieldConfig": { + "defaults": { + "custom": { + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "scaleDistribution": { + "type": "linear" + } + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 24, + "x": 0, + "y": 35 + }, + "id": 303, + "interval": "10s", + "options": { + "calculate": false, + "cellGap": 1, + "color": { + "exponent": 0.5, + "fill": "dark-orange", + "mode": "scheme", + "reverse": false, + "scale": "exponential", + "scheme": "Oranges", + "steps": 64 + }, + "exemplars": { + "color": "rgba(255,0,255,0.7)" + }, + "filterValues": { + "le": 1e-09 + }, + "legend": { + "show": true + }, + "rowsFrame": { + "layout": "auto" + }, + "showValue": "never", + "tooltip": { + "mode": "single", + "showColorScale": false, + "yHistogram": false + }, + "yAxis": { + "axisPlacement": "left", + "reverse": false, + "unit": "bytes" + } + }, + "pluginVersion": "12.2.1", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "${DS_PROMETHEUS}" + }, + "editorMode": "code", + "expr": "sum by (le)(rate(bal_size_bytes_histogram_bucket{job=\"$job\", instance=~\"$instance(:\\\\d+)?$\"}[$__rate_interval]))", + "format": "heatmap", + "instant": false, + "legendFormat": "{{le}}", + "range": true, + "refId": "A" + } + ], + "title": "BAL Size Distribution", + "type": "heatmap" + } + ], + "title": "BAL (EIP-7928)", + "type": "row" + }, { "collapsed": true, "gridPos": { @@ -4195,7 +4713,7 @@ "refId": "B" } ], - "title": "Host Ram (GiB) — Used vs Total", + "title": "Host Ram (GiB) \u2014 Used vs Total", "type": "timeseries" }, {