Skip to content

Commit 890c311

Browse files
author
Solar Mithril
committed
fmt
Logic Add extended flashblocks tracing
1 parent 046a730 commit 890c311

File tree

13 files changed

+144
-18
lines changed

13 files changed

+144
-18
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,4 @@ ahash = "0.8.6"
184184
time = { version = "0.3.36", features = ["macros", "formatting", "parsing"] }
185185
vergen = "9.0.4"
186186
vergen-git2 = "1.0.5"
187+
opentelemetry = { version = "0.29.1", features = ["trace"] }

Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ docker-image-rbuilder: ## Build a rbuilder Docker image
4444
.PHONY: lint
4545
lint: ## Run the linters
4646
cargo +nightly fmt -- --check
47-
cargo +nightly clippy --features "$(FEATURES)" -- -D warnings
48-
cargo +nightly clippy -p op-rbuilder --features "$(FEATURES)" -- -D warnings
47+
cargo +nightly clippy --all-features -- -D warnings
4948

5049
.PHONY: test
5150
test: ## Run the tests for rbuilder and op-rbuilder
@@ -58,8 +57,7 @@ lt: lint test ## Run "lint" and "test"
5857
.PHONY: fmt
5958
fmt: ## Format the code
6059
cargo +nightly fmt
61-
cargo +nightly clippy --features "$(FEATURES)" --fix --allow-staged --allow-dirty
62-
cargo +nightly clippy -p op-rbuilder --features "$(FEATURES)" --fix --allow-staged --allow-dirty
60+
cargo +nightly clippy --all-features --fix --allow-staged --allow-dirty
6361
cargo +nightly fix --allow-staged --allow-dirty
6462

6563
.PHONY: bench

crates/op-rbuilder/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ thiserror.workspace = true
9999
parking_lot.workspace = true
100100
url.workspace = true
101101
anyhow = "1"
102+
opentelemetry = { workspace = true, optional = true }
102103

103104
tower = "0.5"
104105
futures = "0.3"
@@ -177,7 +178,10 @@ testing = [
177178

178179
interop = []
179180

180-
telemetry = ["reth-tracing-otlp"]
181+
telemetry = [
182+
"reth-tracing-otlp",
183+
"opentelemetry",
184+
]
181185

182186
custom-engine-api = []
183187

crates/op-rbuilder/src/args/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
metrics::{CARGO_PKG_VERSION, VERGEN_GIT_SHA},
44
};
55
use clap_builder::{CommandFactory, FromArgMatches};
6-
pub use op::{FlashblocksArgs, OpRbuilderArgs};
6+
pub use op::{FlashblocksArgs, OpRbuilderArgs, TelemetryArgs};
77
use playground::PlaygroundOptions;
88
use reth_optimism_cli::{chainspec::OpChainSpecParser, commands::Commands};
99

crates/op-rbuilder/src/args/op.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ pub struct OpRbuilderArgs {
5252
pub playground: Option<PathBuf>,
5353
#[command(flatten)]
5454
pub flashblocks: FlashblocksArgs,
55+
#[command(flatten)]
56+
pub telemetry: TelemetryArgs,
5557
}
5658

5759
impl Default for OpRbuilderArgs {
@@ -124,3 +126,15 @@ impl Default for FlashblocksArgs {
124126
node_command.ext.flashblocks
125127
}
126128
}
129+
130+
/// Parameters for telemetry configuration
131+
#[derive(Debug, Clone, Default, PartialEq, Eq, clap::Args)]
132+
pub struct TelemetryArgs {
133+
/// OpenTelemetry endpoint for traces
134+
#[arg(long = "telemetry.otlp-endpoint", env = "OTEL_EXPORTER_OTLP_ENDPOINT")]
135+
pub otlp_endpoint: Option<String>,
136+
137+
/// OpenTelemetry headers for authentication
138+
#[arg(long = "telemetry.otlp-headers", env = "OTEL_EXPORTER_OTLP_HEADERS")]
139+
pub otlp_headers: Option<String>,
140+
}

crates/op-rbuilder/src/builders/context.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,13 @@ impl OpPayloadBuilderCtx {
334334
let tx_da_limit = self.da_config.max_da_tx_size();
335335
let mut evm = self.evm_config.evm_with_env(&mut *db, self.evm_env.clone());
336336

337-
info!(target: "payload_builder", block_da_limit = ?block_da_limit, tx_da_size = ?tx_da_limit, block_gas_limit = ?block_gas_limit, "DA limits");
337+
info!(
338+
target: "payload_builder",
339+
message = "Executing best transactions",
340+
block_da_limit = ?block_da_limit,
341+
tx_da_limit = ?tx_da_limit,
342+
block_gas_limit = ?block_gas_limit,
343+
);
338344

339345
// Remove once we merge Reth 1.4.4
340346
// Fixed in https://github.com/paradigmxyz/reth/pull/16514
@@ -367,9 +373,18 @@ impl OpPayloadBuilderCtx {
367373
reverted_hashes.is_some() && !reverted_hashes.unwrap().contains(&tx_hash);
368374

369375
let log_txn = |result: TxnExecutionResult| {
370-
debug!(target: "payload_builder", tx_hash = ?tx_hash, tx_da_size = ?tx_da_size, exclude_reverting_txs = ?exclude_reverting_txs, result = %result, "Considering transaction");
376+
debug!(
377+
target: "payload_builder",
378+
message = "Considering transaction",
379+
tx_hash = ?tx_hash,
380+
tx_da_size = ?tx_da_size,
381+
exclude_reverting_txs = ?exclude_reverting_txs,
382+
result = %result,
383+
);
371384
};
372385

386+
num_txs_considered += 1;
387+
373388
if let Some(conditional) = conditional {
374389
// TODO: ideally we should get this from the txpool stream
375390
if !conditional.matches_block_attributes(&block_attr) {
@@ -391,7 +406,6 @@ impl OpPayloadBuilderCtx {
391406
}
392407
}
393408

394-
num_txs_considered += 1;
395409
// ensure we still have capacity for this transaction
396410
if let Err(result) = info.is_tx_over_limits(
397411
tx_da_size,
@@ -512,6 +526,13 @@ impl OpPayloadBuilderCtx {
512526
.payload_num_tx_simulated_fail
513527
.record(num_txs_simulated_fail as f64);
514528

529+
debug!(
530+
target: "payload_builder",
531+
message = "Completed executing best transactions",
532+
txs_executed = num_txs_considered,
533+
txs_applied = num_txs_simulated_success,
534+
txs_rejected = num_txs_simulated_fail,
535+
);
515536
Ok(None)
516537
}
517538

crates/op-rbuilder/src/builders/flashblocks/payload.rs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use rollup_boost::{
4343
};
4444
use serde::{Deserialize, Serialize};
4545
use tokio::sync::mpsc;
46-
use tracing::{debug, error, warn};
46+
use tracing::{debug, error, metadata::Level, span, warn};
4747

4848
#[derive(Debug, Default)]
4949
struct ExtraExecutionInfo {
@@ -138,6 +138,18 @@ where
138138
let block_build_start_time = Instant::now();
139139
let BuildArguments { config, cancel, .. } = args;
140140

141+
// We log only every 100th block to reduce usage
142+
let span = if cfg!(feature = "telemetry") && config.parent_header.number % 100 == 0 {
143+
span!(Level::INFO, "build_payload")
144+
} else {
145+
tracing::Span::none()
146+
};
147+
let _enter = span.enter();
148+
span.record(
149+
"payload_id",
150+
config.attributes.payload_attributes.id.to_string(),
151+
);
152+
141153
let chain_spec = self.client.chain_spec();
142154
let timestamp = config.attributes.timestamp();
143155
let block_env_attributes = OpNextBlockEnvAttributes {
@@ -211,7 +223,12 @@ where
211223
.publish(&fb_payload)
212224
.map_err(PayloadBuilderError::other)?;
213225

214-
tracing::info!(target: "payload_builder", "Fallback block built");
226+
tracing::info!(
227+
target: "payload_builder",
228+
message = "Fallback block built",
229+
payload_id = fb_payload.payload_id.to_string(),
230+
);
231+
215232
ctx.metrics
216233
.payload_num_tx
217234
.record(info.executed_transactions.len() as f64);
@@ -276,6 +293,16 @@ where
276293

277294
// Process flashblocks in a blocking loop
278295
loop {
296+
let fb_span = if span.is_none() {
297+
tracing::Span::none()
298+
} else {
299+
span!(
300+
parent: &span,
301+
Level::INFO,
302+
"build_flashblock",
303+
)
304+
};
305+
let _entered = fb_span.enter();
279306
// Block on receiving a message, break on cancellation or closed channel
280307
let received = tokio::task::block_in_place(|| {
281308
// Get runtime handle
@@ -430,7 +457,13 @@ where
430457
}
431458
}
432459
flashblock_count += 1;
433-
tracing::info!(target: "payload_builder", "Flashblock {} built", flashblock_count);
460+
tracing::info!(
461+
target: "payload_builder",
462+
message = "Flashblock built",
463+
?flashblock_count,
464+
current_gas = info.cumulative_gas_used,
465+
current_da = info.cumulative_da_bytes_used,
466+
);
434467
}
435468
}
436469
}
@@ -440,6 +473,11 @@ where
440473
self.metrics
441474
.flashblock_count
442475
.record(flashblock_count as f64);
476+
debug!(
477+
target: "payload_builder",
478+
message = "Payload building complete, channel closed or job cancelled"
479+
);
480+
span.record("flashblock_count", flashblock_count);
443481
return Ok(());
444482
}
445483
}

crates/op-rbuilder/src/builders/flashblocks/wspub.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use tokio_tungstenite::{
2020
tungstenite::{Message, Utf8Bytes},
2121
WebSocketStream,
2222
};
23-
use tracing::warn;
23+
use tracing::{debug, warn};
2424

2525
use crate::metrics::OpRBuilderMetrics;
2626

@@ -65,6 +65,14 @@ impl WebSocketPublisher {
6565
// Serialize the payload to a UTF-8 string
6666
// serialize only once, then just copy around only a pointer
6767
// to the serialized data for each subscription.
68+
debug!(
69+
target: "payload_builder",
70+
message = "Sending flashblock to rollup-boost",
71+
payload_id = payload.payload_id.to_string(),
72+
index = payload.index,
73+
base = payload.base.is_some(),
74+
);
75+
6876
let serialized = serde_json::to_string(payload)?;
6977
let utf8_bytes = Utf8Bytes::from(serialized);
7078

crates/op-rbuilder/src/launcher.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,22 @@ use std::{marker::PhantomData, sync::Arc};
2626
pub fn launch() -> Result<()> {
2727
let cli = Cli::parsed();
2828
let mode = cli.builder_mode();
29+
30+
#[cfg(feature = "telemetry")]
31+
let telemetry_args = match &cli.command {
32+
reth_optimism_cli::commands::Commands::Node(node_command) => {
33+
node_command.ext.telemetry.clone()
34+
}
35+
_ => Default::default(),
36+
};
37+
2938
let mut cli_app = cli.configure();
3039

3140
#[cfg(feature = "telemetry")]
3241
{
33-
let otlp = reth_tracing_otlp::layer("op-reth");
34-
cli_app.access_tracing_layers()?.add_layer(otlp);
42+
use crate::primitives::telemetry::setup_telemetry_layer;
43+
let telemetry_layer = setup_telemetry_layer(&telemetry_args)?;
44+
cli_app.access_tracing_layers()?.add_layer(telemetry_layer);
3545
}
3646

3747
cli_app.init_tracing()?;

0 commit comments

Comments
 (0)