Skip to content

Commit f19d4f6

Browse files
authored
Implement tracing spans for data columm RPC requests and responses (#7831)
#7830
1 parent 2d22357 commit f19d4f6

File tree

18 files changed

+491
-66
lines changed

18 files changed

+491
-66
lines changed

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ async fn process_block(&self, block: Block) -> Result<(), Error> {
293293
## Build and Development Notes
294294
- Full builds and tests take 5+ minutes - use large timeouts (300s+) for any `cargo build`, `cargo test`, or `make` commands
295295
- Use `cargo check` for faster iteration during development and always run after code changes
296+
- Use `cargo fmt --all && make lint-fix` to format code and fix linting issues once a task is complete
296297
- Prefer targeted package tests (`cargo test -p <package>`) and individual tests over full test suite when debugging specific issues
297298
- Always understand the broader codebase patterns before making changes
298299
- Minimum Supported Rust Version (MSRV) is documented in `lighthouse/Cargo.toml` - ensure Rust version meets or exceeds this requirement

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ members = [
1111
"beacon_node/http_api",
1212
"beacon_node/http_metrics",
1313
"beacon_node/lighthouse_network",
14+
"beacon_node/lighthouse_tracing",
1415
"beacon_node/network",
1516
"beacon_node/operation_pool",
1617
"beacon_node/store",
@@ -173,6 +174,7 @@ itertools = "0.10"
173174
kzg = { path = "crypto/kzg" }
174175
libsecp256k1 = "0.7"
175176
lighthouse_network = { path = "beacon_node/lighthouse_network" }
177+
lighthouse_tracing = { path = "beacon_node/lighthouse_tracing" }
176178
lighthouse_validator_store = { path = "validator_client/lighthouse_validator_store" }
177179
lighthouse_version = { path = "common/lighthouse_version" }
178180
lockfile = { path = "common/lockfile" }

beacon_node/beacon_chain/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ hex = { workspace = true }
3333
int_to_bytes = { workspace = true }
3434
itertools = { workspace = true }
3535
kzg = { workspace = true }
36+
lighthouse_tracing = { workspace = true }
3637
lighthouse_version = { workspace = true }
3738
logging = { workspace = true }
3839
lru = { workspace = true }

beacon_node/beacon_chain/src/block_verification.rs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ impl<T: BeaconChainTypes> GossipVerifiedBlock<T> {
826826
/// on the p2p network.
827827
///
828828
/// Returns an error if the block is invalid, or if the block was unable to be verified.
829-
#[instrument(name = "verify_gossip_block", skip_all)]
829+
#[instrument(name = "verify_gossip_block", skip_all, fields(block_root = tracing::field::Empty))]
830830
pub fn new(
831831
block: Arc<SignedBeaconBlock<T::EthSpec>>,
832832
chain: &BeaconChain<T>,
@@ -1227,27 +1227,20 @@ impl<T: BeaconChainTypes> SignatureVerifiedBlock<T> {
12271227
signature_verifier
12281228
.include_all_signatures_except_proposal(block.as_ref(), &mut consensus_context)?;
12291229

1230-
let sig_verify_span = info_span!("signature_verify", result = "started").entered();
1231-
let result = signature_verifier.verify();
1230+
let result = info_span!("signature_verify").in_scope(|| signature_verifier.verify());
12321231
match result {
1233-
Ok(_) => {
1234-
sig_verify_span.record("result", "ok");
1235-
Ok(Self {
1236-
block: MaybeAvailableBlock::AvailabilityPending {
1237-
block_root: from.block_root,
1238-
block,
1239-
},
1232+
Ok(_) => Ok(Self {
1233+
block: MaybeAvailableBlock::AvailabilityPending {
12401234
block_root: from.block_root,
1241-
parent: Some(parent),
1242-
consensus_context,
1243-
})
1244-
}
1245-
Err(_) => {
1246-
sig_verify_span.record("result", "fail");
1247-
Err(BlockError::InvalidSignature(
1248-
InvalidSignature::BlockBodySignatures,
1249-
))
1250-
}
1235+
block,
1236+
},
1237+
block_root: from.block_root,
1238+
parent: Some(parent),
1239+
consensus_context,
1240+
}),
1241+
Err(_) => Err(BlockError::InvalidSignature(
1242+
InvalidSignature::BlockBodySignatures,
1243+
)),
12511244
}
12521245
}
12531246

beacon_node/beacon_chain/src/data_availability_checker/overflow_lru_cache.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::block_verification_types::{
99
};
1010
use crate::data_availability_checker::{Availability, AvailabilityCheckError};
1111
use crate::data_column_verification::KzgVerifiedCustodyDataColumn;
12+
use lighthouse_tracing::SPAN_PENDING_COMPONENTS;
1213
use lru::LruCache;
1314
use parking_lot::RwLock;
1415
use std::cmp::Ordering;
@@ -288,7 +289,7 @@ impl<E: EthSpec> PendingComponents<E> {
288289

289290
/// Returns an empty `PendingComponents` object with the given block root.
290291
pub fn empty(block_root: Hash256, max_len: usize) -> Self {
291-
let span = debug_span!(parent: None, "pending_components", %block_root);
292+
let span = debug_span!(parent: None, SPAN_PENDING_COMPONENTS, %block_root);
292293
let _guard = span.clone().entered();
293294
Self {
294295
block_root,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[package]
2+
name = "lighthouse_tracing"
3+
version = "0.1.0"
4+
edition = { workspace = true }
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//! This module contains root span identifiers for key code paths in the beacon node.
2+
//!
3+
//! TODO: These span identifiers will be used to implement selective tracing export (to be implemented),
4+
//! where only the listed root spans and their descendants will be exported to the tracing backend.
5+
6+
/// Data Availability checker span identifiers
7+
pub const SPAN_PENDING_COMPONENTS: &str = "pending_components";
8+
9+
/// Gossip methods root spans
10+
pub const SPAN_PROCESS_GOSSIP_DATA_COLUMN: &str = "process_gossip_data_column";
11+
pub const SPAN_PROCESS_GOSSIP_BLOB: &str = "process_gossip_blob";
12+
pub const SPAN_PROCESS_GOSSIP_BLOCK: &str = "process_gossip_block";
13+
14+
/// Sync methods root spans
15+
pub const SPAN_SYNCING_CHAIN: &str = "syncing_chain";
16+
pub const SPAN_OUTGOING_RANGE_REQUEST: &str = "outgoing_range_request";
17+
pub const SPAN_OUTGOING_CUSTODY_REQUEST: &str = "outgoing_custody_request";
18+
pub const SPAN_PROCESS_RPC_BLOCK: &str = "process_rpc_block";
19+
pub const SPAN_PROCESS_RPC_BLOBS: &str = "process_rpc_blobs";
20+
pub const SPAN_PROCESS_RPC_CUSTODY_COLUMNS: &str = "process_rpc_custody_columns";
21+
pub const SPAN_PROCESS_CHAIN_SEGMENT: &str = "process_chain_segment";
22+
23+
/// RPC methods root spans
24+
pub const SPAN_HANDLE_BLOCKS_BY_RANGE_REQUEST: &str = "handle_blocks_by_range_request";
25+
pub const SPAN_HANDLE_BLOBS_BY_RANGE_REQUEST: &str = "handle_blobs_by_range_request";
26+
pub const SPAN_HANDLE_DATA_COLUMNS_BY_RANGE_REQUEST: &str = "handle_data_columns_by_range_request";
27+
pub const SPAN_HANDLE_BLOCKS_BY_ROOT_REQUEST: &str = "handle_blocks_by_root_request";
28+
pub const SPAN_HANDLE_BLOBS_BY_ROOT_REQUEST: &str = "handle_blobs_by_root_request";
29+
pub const SPAN_HANDLE_DATA_COLUMNS_BY_ROOT_REQUEST: &str = "handle_data_columns_by_root_request";
30+
pub const SPAN_HANDLE_LIGHT_CLIENT_UPDATES_BY_RANGE: &str = "handle_light_client_updates_by_range";
31+
pub const SPAN_HANDLE_LIGHT_CLIENT_BOOTSTRAP: &str = "handle_light_client_bootstrap";
32+
pub const SPAN_HANDLE_LIGHT_CLIENT_OPTIMISTIC_UPDATE: &str =
33+
"handle_light_client_optimistic_update";
34+
pub const SPAN_HANDLE_LIGHT_CLIENT_FINALITY_UPDATE: &str = "handle_light_client_finality_update";
35+
36+
/// List of all root span names that are allowed to be exported to the tracing backend.
37+
/// Only these spans and their descendants will be processed to reduce noise from
38+
/// uninstrumented code paths. New root spans must be added to this list to be traced.
39+
pub const LH_BN_ROOT_SPAN_NAMES: &[&str] = &[
40+
SPAN_SYNCING_CHAIN,
41+
SPAN_PENDING_COMPONENTS,
42+
SPAN_PROCESS_GOSSIP_DATA_COLUMN,
43+
SPAN_PROCESS_GOSSIP_BLOB,
44+
SPAN_PROCESS_GOSSIP_BLOCK,
45+
SPAN_OUTGOING_RANGE_REQUEST,
46+
SPAN_OUTGOING_CUSTODY_REQUEST,
47+
SPAN_PROCESS_RPC_BLOCK,
48+
SPAN_PROCESS_RPC_BLOBS,
49+
SPAN_PROCESS_RPC_CUSTODY_COLUMNS,
50+
SPAN_PROCESS_CHAIN_SEGMENT,
51+
SPAN_HANDLE_BLOCKS_BY_RANGE_REQUEST,
52+
SPAN_HANDLE_BLOBS_BY_RANGE_REQUEST,
53+
SPAN_HANDLE_DATA_COLUMNS_BY_RANGE_REQUEST,
54+
SPAN_HANDLE_BLOCKS_BY_ROOT_REQUEST,
55+
SPAN_HANDLE_BLOBS_BY_ROOT_REQUEST,
56+
SPAN_HANDLE_DATA_COLUMNS_BY_ROOT_REQUEST,
57+
SPAN_HANDLE_LIGHT_CLIENT_UPDATES_BY_RANGE,
58+
SPAN_HANDLE_LIGHT_CLIENT_BOOTSTRAP,
59+
SPAN_HANDLE_LIGHT_CLIENT_OPTIMISTIC_UPDATE,
60+
SPAN_HANDLE_LIGHT_CLIENT_FINALITY_UPDATE,
61+
];

beacon_node/network/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ hex = { workspace = true }
2828
igd-next = { version = "0.16", features = ["aio_tokio"] }
2929
itertools = { workspace = true }
3030
lighthouse_network = { workspace = true }
31+
lighthouse_tracing = { workspace = true }
3132
logging = { workspace = true }
3233
lru_cache = { workspace = true }
3334
metrics = { workspace = true }

beacon_node/network/src/network_beacon_processor/gossip_methods.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ use beacon_chain::{
2121
};
2222
use beacon_processor::{Work, WorkEvent};
2323
use lighthouse_network::{Client, MessageAcceptance, MessageId, PeerAction, PeerId, ReportSource};
24+
use lighthouse_tracing::{
25+
SPAN_PROCESS_GOSSIP_BLOB, SPAN_PROCESS_GOSSIP_BLOCK, SPAN_PROCESS_GOSSIP_DATA_COLUMN,
26+
};
2427
use logging::crit;
2528
use operation_pool::ReceivedPreCapella;
2629
use slot_clock::SlotClock;
@@ -602,7 +605,13 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
602605
}
603606
}
604607

605-
#[instrument(skip_all, level = "trace", fields(slot = ?column_sidecar.slot(), block_root = ?column_sidecar.block_root(), index = column_sidecar.index), parent = None)]
608+
#[instrument(
609+
name = SPAN_PROCESS_GOSSIP_DATA_COLUMN,
610+
parent = None,
611+
level = "debug",
612+
skip_all,
613+
fields(slot = ?column_sidecar.slot(), block_root = ?column_sidecar.block_root(), index = column_sidecar.index),
614+
)]
606615
pub async fn process_gossip_data_column_sidecar(
607616
self: &Arc<Self>,
608617
message_id: MessageId,
@@ -760,7 +769,16 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
760769
}
761770

762771
#[allow(clippy::too_many_arguments)]
763-
#[instrument(skip_all, level = "trace", fields(slot = ?blob_sidecar.slot(), block_root = ?blob_sidecar.block_root(), index = blob_sidecar.index), parent = None)]
772+
#[instrument(
773+
name = SPAN_PROCESS_GOSSIP_BLOB,
774+
parent = None,
775+
level = "debug",
776+
skip_all,
777+
fields(
778+
slot = ?blob_sidecar.slot(),
779+
block_root = ?blob_sidecar.block_root(),
780+
index = blob_sidecar.index),
781+
)]
764782
pub async fn process_gossip_blob(
765783
self: &Arc<Self>,
766784
message_id: MessageId,
@@ -1098,7 +1116,13 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
10981116
///
10991117
/// Raises a log if there are errors.
11001118
#[allow(clippy::too_many_arguments)]
1101-
#[instrument(skip_all, fields(block_root = tracing::field::Empty), parent = None)]
1119+
#[instrument(
1120+
name = SPAN_PROCESS_GOSSIP_BLOCK,
1121+
parent = None,
1122+
level = "debug",
1123+
skip_all,
1124+
fields(block_root = tracing::field::Empty),
1125+
)]
11021126
pub async fn process_gossip_block(
11031127
self: Arc<Self>,
11041128
message_id: MessageId,

0 commit comments

Comments
 (0)