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..a067d1956 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. + 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]