Skip to content

Add tracing and metrics for blocks delta #257

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

Merged
merged 2 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<OpExecutionPayloadEnvelope> for ExecutionPayload {
Expand Down
19 changes: 17 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
28 changes: 28 additions & 0 deletions src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,34 @@ impl SpanProcessor for MetricsSpanProcessor {
])
.collect::<Vec<_>>();

// 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::<u64>().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::<u64>().unwrap_or_default() as f64);
}

histogram!(format!("{}_duration", span.name), &labels).record(duration);
}

Expand Down
Loading