From 992c3467403fa0b7fcaaef087a949ff9108a0c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Thu, 26 Nov 2026 19:08:32 -0300 Subject: [PATCH 1/2] perf(pq): sign the payload committee's votes after the slot's attestations A leanXMSS signature costs about 0.3 s of a core. A devnet host's twenty attestations and fifteen payload committee votes per slot used to sign at once on the same cores, so both batches finished within milliseconds of each other, a second or more after the block. The attestations are due a quarter into the slot, the votes three quarters in. At a PQ slot the committee vote now starts once the slot's attestations are out, or their duty failed or gave up, and before the aggregation's wait, so the attestations get the cores to themselves. Earlier forks are unchanged: a BLS signature costs microseconds. --- crates/validator/src/lib.rs | 37 ++++++++++++++++++++++++++---- crates/validator/src/slot_clock.rs | 21 +++++++++++++++++ 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/crates/validator/src/lib.rs b/crates/validator/src/lib.rs index b520727a1..449d85cdb 100644 --- a/crates/validator/src/lib.rs +++ b/crates/validator/src/lib.rs @@ -1078,6 +1078,17 @@ async fn run_until_stopped( /// one after another, so the committee vote, which the payload can start /// before the aggregation is due, is not held behind it. Each is bounded by /// the end of the slot. +/// +/// # From PQ the committee vote waits for the slot's attestations +/// +/// A leanXMSS signature costs about 0.3 s of a core (see `pq::sign_batch`), +/// and the slot's attestations and committee votes, twenty and fifteen of +/// them on a devnet host, used to sign at once on the same cores, so both +/// finished together. The attestations are due a quarter into the slot and +/// the votes three quarters in, so at PQ the vote starts only once the +/// attestations are out (or their duty gave up), and the attestations have +/// the cores to themselves. Not the aggregation: that comes later in the +/// slot, and its own wait would hold the vote for nothing. #[allow(clippy::too_many_arguments)] async fn serve_slot_duties( attestation: &AttestationService, @@ -1092,6 +1103,9 @@ async fn serve_slot_duties( sync_duties: &[crate::beacon_node::dto::SyncDutyDto], store: &RwLock, ) { + // Dropped unsent when the attestation part ends without signing (no + // duties, or abandoned), which releases the vote just the same. + let (attested, attestations_out) = tokio::sync::oneshot::channel::<()>(); let attest = async { if !slot_duties.is_empty() { attest_and_aggregate( @@ -1102,12 +1116,16 @@ async fn serve_slot_duties( slot, slot_duties, store, + attested, ) .await; } }; let vote = async { if clock.is_gloas(slot) && !committee.is_empty() { + if clock.is_pq(slot) { + let _ = attestations_out.await; + } payload_attest(payload_attestation, triggers, clock, slot, committee, store).await; } }; @@ -1189,6 +1207,10 @@ async fn sync_committee_duty( /// /// Split out of the loop so the loop can go on to the payload committee duty /// whether or not this client has an attester duty in the slot. +/// +/// `attested` is told once the attestations are out, or the duty failed or +/// gave up, before the aggregation's wait. +#[allow(clippy::too_many_arguments)] async fn attest_and_aggregate( attestation: &AttestationService, aggregation: &AggregationService, @@ -1197,6 +1219,7 @@ async fn attest_and_aggregate( slot: u64, slot_duties: &[crate::beacon_node::dto::AttesterDutyDto], store: &RwLock, + attested: tokio::sync::oneshot::Sender<()>, ) { // Bound the slot's work by what is left of the slot. // @@ -1218,9 +1241,11 @@ async fn attest_and_aggregate( clock.until_attestation(slot, now), clock.remaining_in(slot, now), ); - let attested = triggers.attest(attestation, slot, wait, slot_duties, store); - let attempt = tokio::time::timeout(budget, attested); - match attempt.await.unwrap_or_else(|_| { + let attempt = tokio::time::timeout( + budget, + triggers.attest(attestation, slot, wait, slot_duties, store), + ); + let outcome = attempt.await.unwrap_or_else(|_| { warn!( %slot, budget_ms = budget.as_millis() as u64, @@ -1228,7 +1253,11 @@ async fn attest_and_aggregate( ); metrics::inc_attestation_deadline_missed(); Err(Error::AttestationDeadline { slot }) - }) { + }); + // A committee vote waiting for the cores (see `serve_slot_duties`) may go + // now; nobody waiting is fine. + let _ = attested.send(()); + match outcome { // `attest` scopes its own read guard away from every await (see // its doc comment), so passing the shared `store` straight // through here holds nothing across this call. diff --git a/crates/validator/src/slot_clock.rs b/crates/validator/src/slot_clock.rs index 4ab2bf808..ee150dc0e 100644 --- a/crates/validator/src/slot_clock.rs +++ b/crates/validator/src/slot_clock.rs @@ -90,6 +90,11 @@ impl SlotClock { self.config.fork_at_epoch(self.epoch_of(slot)) >= ForkName::Gloas } + /// Whether `slot` is a PQ slot, where every duty signs with leanXMSS. + pub fn is_pq(&self, slot: Slot) -> bool { + self.config.fork_at_epoch(self.epoch_of(slot)) == ForkName::Pq + } + /// The slot containing `now`, or `None` before genesis. /// /// Divides in milliseconds, not seconds, so a chain whose slot is not a @@ -622,6 +627,22 @@ mod tests { assert_eq!(now + delay, clock.start_of(0)); } + /// A PQ slot is one from the PQ fork epoch on, and gloas too. + #[test] + fn pq_starts_at_its_fork_epoch() { + let config = Config::mainnet() + .with_fork_epoch(ForkName::Gloas, 0) + .with_fork_epoch(ForkName::Eip8483, 0) + .with_fork_epoch(ForkName::Pq, 2); + let clock = SlotClock::from_config(GENESIS, &config); + let first_pq = 2 * slots_per_epoch(); + assert!(!clock.is_pq(first_pq - 1)); + assert!(clock.is_pq(first_pq)); + assert!(clock.is_gloas(first_pq)); + let without_pq = SlotClock::from_config(GENESIS, &Config::mainnet()); + assert!(!without_pq.is_pq(first_pq)); + } + /// Slots before the gloas epoch keep the pre-gloas offsets and slots from /// it on take the gloas ones, on both sides of the boundary. #[test] From c17e5fdc08dd740e3fc75eb2810ff03112c91f6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Gr=C3=BCner?= <47506558+MegaRedHand@users.noreply.github.com> Date: Thu, 26 Nov 2026 19:15:40 -0300 Subject: [PATCH 2/2] refactor(validator): SlotClock::is_pq as pq-devnet-1 words it #896 adds the same helper at the same place; identical lines merge cleanly when pq-devnet-0 is merged into pq-devnet-1. --- crates/validator/src/slot_clock.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/validator/src/slot_clock.rs b/crates/validator/src/slot_clock.rs index ee150dc0e..a067d1956 100644 --- a/crates/validator/src/slot_clock.rs +++ b/crates/validator/src/slot_clock.rs @@ -90,9 +90,9 @@ impl SlotClock { self.config.fork_at_epoch(self.epoch_of(slot)) >= ForkName::Gloas } - /// Whether `slot` is a PQ slot, where every duty signs with leanXMSS. + /// Whether `slot` is a PQ slot. pub fn is_pq(&self, slot: Slot) -> bool { - self.config.fork_at_epoch(self.epoch_of(slot)) == ForkName::Pq + self.config.fork_at_epoch(self.epoch_of(slot)) >= ForkName::Pq } /// The slot containing `now`, or `None` before genesis.