diff --git a/src/payload.rs b/src/payload.rs index 0e9c5944..1ed6707e 100644 --- a/src/payload.rs +++ b/src/payload.rs @@ -43,6 +43,24 @@ impl OpExecutionPayloadEnvelope { } } } + + pub fn tx_count(&self) -> usize { + match self { + OpExecutionPayloadEnvelope::V3(payload) => payload + .execution_payload + .payload_inner + .payload_inner + .transactions + .len(), + OpExecutionPayloadEnvelope::V4(payload) => payload + .execution_payload + .payload_inner + .payload_inner + .payload_inner + .transactions + .len(), + } + } } impl From for ExecutionPayload { diff --git a/src/server.rs b/src/server.rs index 72dd6e62..d1319776 100644 --- a/src/server.rs +++ b/src/server.rs @@ -184,6 +184,17 @@ impl RollupBoostServer { self.probes.set_health(Health::Healthy); if let Ok(Some(builder_payload)) = builder_payload { + // Record the delta (gas and txn) between the builder and l2 payload + let span = tracing::Span::current(); + span.record( + "gas_delta", + (builder_payload.gas_used() - l2_payload.gas_used()).to_string(), + ); + span.record( + "tx_count_delta", + (builder_payload.tx_count() - l2_payload.tx_count()).to_string(), + ); + // If execution mode is set to DryRun, fallback to the l2_payload, // otherwise prefer the builder payload if self.execution_mode().is_dry_run() { @@ -388,7 +399,9 @@ impl EngineApiServer for RollupBoostServer { fields( otel.kind = ?SpanKind::Server, %payload_id, - payload_source + payload_source, + gas_delta, + tx_count_delta, ) )] async fn get_payload_v3( @@ -436,7 +449,9 @@ impl EngineApiServer for RollupBoostServer { fields( otel.kind = ?SpanKind::Server, %payload_id, - payload_source + payload_source, + gas_delta, + tx_count_delta, ) )] async fn get_payload_v4( diff --git a/src/tracing.rs b/src/tracing.rs index 2844d1e3..ff78a950 100644 --- a/src/tracing.rs +++ b/src/tracing.rs @@ -58,6 +58,34 @@ impl SpanProcessor for MetricsSpanProcessor { ]) .collect::>(); + // 0 = no difference in gas build via builder vs l2 + // > 0 = gas used by builder block is greater than l2 block + // < 0 = gas used by l2 block is greater than builder block + let gas_delta = span + .attributes + .iter() + .find(|attr| attr.key.as_str() == "gas_delta") + .map(|attr| attr.value.as_str().to_string()); + + if let Some(gas_delta) = gas_delta { + histogram!("block_building_gas_delta", &labels) + .record(gas_delta.parse::().unwrap_or_default() as f64); + } + + // 0 = no difference in tx count build via builder vs l2 + // > 0 = num txs in builder block is greater than l2 block + // < 0 = num txs in l2 block is greater than builder block + let tx_count_delta = span + .attributes + .iter() + .find(|attr| attr.key.as_str() == "tx_count_delta") + .map(|attr| attr.value.as_str().to_string()); + + if let Some(tx_count_delta) = tx_count_delta { + histogram!("block_building_tx_count_delta", &labels) + .record(tx_count_delta.parse::().unwrap_or_default() as f64); + } + histogram!(format!("{}_duration", span.name), &labels).record(duration); }