Skip to content

Commit 0ded552

Browse files
authored
Add tracing and metrics for blocks delta (#257)
1 parent 4e1805c commit 0ded552

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

src/payload.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,24 @@ impl OpExecutionPayloadEnvelope {
4343
}
4444
}
4545
}
46+
47+
pub fn tx_count(&self) -> usize {
48+
match self {
49+
OpExecutionPayloadEnvelope::V3(payload) => payload
50+
.execution_payload
51+
.payload_inner
52+
.payload_inner
53+
.transactions
54+
.len(),
55+
OpExecutionPayloadEnvelope::V4(payload) => payload
56+
.execution_payload
57+
.payload_inner
58+
.payload_inner
59+
.payload_inner
60+
.transactions
61+
.len(),
62+
}
63+
}
4664
}
4765

4866
impl From<OpExecutionPayloadEnvelope> for ExecutionPayload {

src/server.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,17 @@ impl RollupBoostServer {
184184
self.probes.set_health(Health::Healthy);
185185

186186
if let Ok(Some(builder_payload)) = builder_payload {
187+
// Record the delta (gas and txn) between the builder and l2 payload
188+
let span = tracing::Span::current();
189+
span.record(
190+
"gas_delta",
191+
(builder_payload.gas_used() - l2_payload.gas_used()).to_string(),
192+
);
193+
span.record(
194+
"tx_count_delta",
195+
(builder_payload.tx_count() - l2_payload.tx_count()).to_string(),
196+
);
197+
187198
// If execution mode is set to DryRun, fallback to the l2_payload,
188199
// otherwise prefer the builder payload
189200
if self.execution_mode().is_dry_run() {
@@ -388,7 +399,9 @@ impl EngineApiServer for RollupBoostServer {
388399
fields(
389400
otel.kind = ?SpanKind::Server,
390401
%payload_id,
391-
payload_source
402+
payload_source,
403+
gas_delta,
404+
tx_count_delta,
392405
)
393406
)]
394407
async fn get_payload_v3(
@@ -436,7 +449,9 @@ impl EngineApiServer for RollupBoostServer {
436449
fields(
437450
otel.kind = ?SpanKind::Server,
438451
%payload_id,
439-
payload_source
452+
payload_source,
453+
gas_delta,
454+
tx_count_delta,
440455
)
441456
)]
442457
async fn get_payload_v4(

src/tracing.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,34 @@ impl SpanProcessor for MetricsSpanProcessor {
5858
])
5959
.collect::<Vec<_>>();
6060

61+
// 0 = no difference in gas build via builder vs l2
62+
// > 0 = gas used by builder block is greater than l2 block
63+
// < 0 = gas used by l2 block is greater than builder block
64+
let gas_delta = span
65+
.attributes
66+
.iter()
67+
.find(|attr| attr.key.as_str() == "gas_delta")
68+
.map(|attr| attr.value.as_str().to_string());
69+
70+
if let Some(gas_delta) = gas_delta {
71+
histogram!("block_building_gas_delta", &labels)
72+
.record(gas_delta.parse::<u64>().unwrap_or_default() as f64);
73+
}
74+
75+
// 0 = no difference in tx count build via builder vs l2
76+
// > 0 = num txs in builder block is greater than l2 block
77+
// < 0 = num txs in l2 block is greater than builder block
78+
let tx_count_delta = span
79+
.attributes
80+
.iter()
81+
.find(|attr| attr.key.as_str() == "tx_count_delta")
82+
.map(|attr| attr.value.as_str().to_string());
83+
84+
if let Some(tx_count_delta) = tx_count_delta {
85+
histogram!("block_building_tx_count_delta", &labels)
86+
.record(tx_count_delta.parse::<u64>().unwrap_or_default() as f64);
87+
}
88+
6189
histogram!(format!("{}_duration", span.name), &labels).record(duration);
6290
}
6391

0 commit comments

Comments
 (0)