Skip to content
Open
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
10 changes: 10 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,16 @@ recomputation), and p2p's column rows: `column_checks::column_rows` (after the c
`passed_rows` called directly by the gossip-accept path and by this node's own fulu columns. See
[`docs/telemetry.md`](docs/telemetry.md).

The same crate holds the **PQ timing export** (`ethlambda_telemetry::pq_timing`,
`--pq-timing-output`): PQ vote receipts and verdicts and every attestation proof, as JSON-lines
events in a run directory, in the schema the PQ devnets' clients share (Lighthouse's
`scripts/pq-measurement`, 1). Another global sink, installed in `run_node` after leanVM and closed
in `wait_for_shutdown`; its emitters (`message_received`, `validated`, `Job`, `proposal_snapshot`)
build nothing when it is off. The emit sites are p2p's `beacon::pq::triage` and `verdict::report`,
rpc's seat prover and `pq_proposal`, and `pq_attestation_packing`. Tests of an emit site capture
the events in memory (`pq_timing::testing::capture`, behind the crate's `test-utils` feature); the
session is the process's, so one capture runs at a time. See [`docs/pq_timing.md`](docs/pq_timing.md).

## Beacon Chain types (`crates/common/types/src/beacon/`)

`ethlambda-types` carries the **Ethereum Beacon Chain** containers (phase0
Expand Down
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ thiserror = "2.0.9"
serde = { version = "1", features = ["derive"] }
serde_json = "1.0.117"
serde_yaml_ng = "0.10"
# The PQ timing export's chunks (`ethlambda-telemetry`). `zstd-sys` is already
# built for RocksDB; this adds the two safe wrappers over it.
zstd = "0.13"
hex = "0.4"
hmac = "0.12"
base64 = "0.22"
Expand Down
24 changes: 24 additions & 0 deletions bin/ethlambda/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,18 @@ pub(crate) struct MainnetOptions {
#[arg(long, default_value_t = 0)]
pub(crate) pq_prover_threads: usize,

/// Record PQ gossip and proving timings under this directory, one
/// sub-directory per run, in the format the PQ devnets' clients share
/// (schema 1 of Lighthouse's `scripts/pq-measurement`): when each PQ
/// attestation and aggregate arrived and what validation made of it, and
/// every committee proof and block-proof merge this node made.
///
/// Off when unset, and read only on a network that schedules the PQ
/// fork. A run keeps at most 8 GiB, removing its oldest events first. See
/// `docs/pq_timing.md`.
#[arg(long, value_name = "DIR")]
pub(crate) pq_timing_output: Option<PathBuf>,

/// Base URL of a builder API endpoint, normally MEV-Boost (for example
/// `http://127.0.0.1:18550`) or a relay directly. Without it every block
/// is built locally, and `register_validator` answers 500 so a validator
Expand Down Expand Up @@ -1209,6 +1221,18 @@ mod tests {
}
}

/// `--pq-timing-output` names a directory, and is off without it.
#[test]
fn the_pq_timing_output_is_a_directory_and_off_by_default() {
assert_eq!(parse_beacon(beacon_args()).mainnet.pq_timing_output, None);
let mut args = beacon_args();
args.extend(["--pq-timing-output", "/data/pq-timing"]);
assert_eq!(
parse_beacon(args).mainnet.pq_timing_output,
Some(PathBuf::from("/data/pq-timing"))
);
}

/// A client name alone configures nothing, so it is a usage error rather
/// than a flag silently ignored.
///
Expand Down
26 changes: 26 additions & 0 deletions bin/ethlambda/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod keygen;
mod network;
mod pq_keys;
mod pq_prover_check;
mod pq_timing;
mod shutdown;
mod slashing_protection;
mod validator;
Expand Down Expand Up @@ -494,6 +495,28 @@ async fn run_node(options: Options) -> eyre::Result<()> {
);
stark::install_leanvm(config).wrap_err("cannot start leanVM's prover")?;
}
// After the prover, whose backend the run names.
if let Some(output) = &mainnet.pq_timing_output {
if pq_epoch == ethlambda_types::beacon::constants::FAR_FUTURE_EPOCH {
warn!(
network = source.name(),
"--pq-timing-output is set, but this network does not schedule the PQ fork: nothing to record"
);
} else {
let run = pq_timing::run(
output.clone(),
source.name(),
source.genesis(),
source.config(),
mainnet.pq_prover_threads,
);
let run_dir =
ethlambda_telemetry::pq_timing::install(run).wrap_err_with(|| {
format!("cannot record PQ timing under {}", output.display())
})?;
info!(run_dir = %run_dir.display(), "Recording PQ timing");
}
}
(Some(source), bootnodes)
}
};
Expand Down Expand Up @@ -1242,6 +1265,9 @@ async fn wait_for_shutdown(node: RunningNode) {
let _ = node.http.await;
// After the actors, which are the only emitters, have stopped.
ethlambda_telemetry::shutdown(TELEMETRY_FLUSH_TIMEOUT).await;
// The PQ timing run's last chunk and its end. A proof still running on a
// blocking thread reports to nobody after this.
ethlambda_telemetry::pq_timing::close();

info!("Shutdown complete");
}
Expand Down
101 changes: 101 additions & 0 deletions bin/ethlambda/src/pq_timing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
//! What a `--pq-timing-output` run records about itself: the network, the
//! prover, and where in a slot this node does each step of PQ aggregation.
//! The export itself is `ethlambda_telemetry::pq_timing`; see
//! `docs/pq_timing.md`.

use std::path::PathBuf;
use std::time::Duration;

use ethlambda_blockchain::payload_attributes::lookahead_start;
use ethlambda_crypto::stark::{
self,
leanvm::{LEANVM_REV, LeanVmConfig, PROTOCOL_VERSION},
};
use ethlambda_state_transition::beacon::fork_choice::{
get_aggregation_cutoff_ms, get_attestation_due_ms, get_pq_aggregate_due_ms,
};
use ethlambda_telemetry::pq_timing::{Prover, Run, Timing};
use ethlambda_types::beacon::{
config::Config, fork::ForkName, preset::MIN_ATTESTATION_INCLUSION_DELAY_PQ,
};

use crate::beacon::Genesis;

/// The run for a node on `network`, recording under `output`, whose prover
/// was asked for `prover_threads` threads (0 for one per core). Call after
/// the prover is installed: the run names the backend in use.
pub(crate) fn run(
output: PathBuf,
network: &str,
genesis: Genesis,
config: &Config,
prover_threads: usize,
) -> Run {
let cores = std::thread::available_parallelism().map_or(1, usize::from);
Run {
output,
network: network.to_string(),
client_version: crate::version::client_version().to_string(),
genesis_time: genesis.genesis_time,
genesis_validators_root: genesis.genesis_validators_root.0,
prover: Prover {
backend: stark::backend_name(),
leanvm_revision: LEANVM_REV,
leanvm_protocol_version: PROTOCOL_VERSION,
log_inv_rate: LeanVmConfig::default().log_inv_rate,
// Left to leanVM, the count is its own: one per physical core.
threads: (prover_threads > 0).then(|| prover_threads.min(cores)),
threads_configured: prover_threads,
},
timing: timing(config),
}
}

/// Where in a slot this node does each step, on `config`'s PQ timing: the
/// first aggregator seat's cutoff and broadcast, and when the merge ahead of
/// a proposal starts, counted from the start of its votes' slot.
fn timing(config: &Config) -> Timing {
let ms = Duration::from_millis;
let slot_ms = config.slot_duration_ms;
let pq_epoch = config.fork_epoch(ForkName::Pq);
let aggregate_due = get_pq_aggregate_due_ms(0, config);
// A block packs votes from `MIN_ATTESTATION_INCLUSION_DELAY_PQ` slots
// back, and its packing starts with its payload build, in the slot
// before it.
let slots_before_packing = MIN_ATTESTATION_INCLUSION_DELAY_PQ.saturating_sub(1);
Timing {
slot: ms(slot_ms),
attestation_due: ms(get_attestation_due_ms(pq_epoch, config)),
committee_collection: ms(get_aggregation_cutoff_ms(0, config)),
aggregator_delay: ms(get_pq_aggregate_due_ms(1, config).saturating_sub(aggregate_due)),
aggregate_due: ms(aggregate_due),
initial_merge: ms(slots_before_packing.saturating_mul(slot_ms)) + lookahead_start(slot_ms),
proposal_lag_slots: MIN_ATTESTATION_INCLUSION_DELAY_PQ,
}
}

#[cfg(test)]
mod tests {
use super::*;

/// A 12-second slot: attestations due at 3 s, the first seat collects
/// until 4.8 s and broadcasts at 7.2 s, each next seat 0.6 s later, and a
/// block's packing starts 8 s into the slot before it, 20 s after its
/// newest votes' slot began.
#[test]
fn the_timing_is_the_pq_slots_own() {
let config = Config::mainnet()
.with_fork_epoch(ForkName::Gloas, 0)
.with_fork_epoch(ForkName::Eip8483, 0)
.with_fork_epoch(ForkName::Pq, 0);
let timing = timing(&config);
let ms = Duration::from_millis;
assert_eq!(timing.slot, ms(12_000));
assert_eq!(timing.attestation_due, ms(3_000));
assert_eq!(timing.committee_collection, ms(4_800));
assert_eq!(timing.aggregator_delay, ms(600));
assert_eq!(timing.aggregate_due, ms(7_200));
assert_eq!(timing.initial_merge, ms(20_000));
assert_eq!(timing.proposal_lag_slots, 2);
}
}
3 changes: 3 additions & 0 deletions crates/blockchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ hex.workspace = true
# `test_state`'s validator keys, so a test can sign a block that has to pass
# the proposer-signature precheck before its blobs are asked for.
ethlambda-state-transition = { workspace = true, features = ["test-utils"] }
# `test-utils` for `pq_timing::testing`: the PQ timing events a packing emits,
# captured in memory.
ethlambda-telemetry = { workspace = true, features = ["test-utils"] }
hex = { workspace = true }
libssz.workspace = true
libssz-types.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/blockchain/src/payload_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ pub(crate) fn next_payload(

/// How far into a slot the next slot's attributes are first published: a
/// third of a slot before it ends, Lighthouse's default lookahead.
pub(crate) fn lookahead_start(slot_duration_ms: u64) -> Duration {
pub fn lookahead_start(slot_duration_ms: u64) -> Duration {
Duration::from_millis(slot_duration_ms - slot_duration_ms / 3)
}

Expand Down
Loading
Loading