Skip to content
Merged
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
37 changes: 33 additions & 4 deletions crates/validator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B: BeaconNodeApi>(
attestation: &AttestationService<B>,
Expand All @@ -1092,6 +1103,9 @@ async fn serve_slot_duties<B: BeaconNodeApi>(
sync_duties: &[crate::beacon_node::dto::SyncDutyDto],
store: &RwLock<ValidatorStore>,
) {
// 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(
Expand All @@ -1102,12 +1116,16 @@ async fn serve_slot_duties<B: BeaconNodeApi>(
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;
}
};
Expand Down Expand Up @@ -1189,6 +1207,10 @@ async fn sync_committee_duty<B: BeaconNodeApi>(
///
/// 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<B: BeaconNodeApi>(
attestation: &AttestationService<B>,
aggregation: &AggregationService<B>,
Expand All @@ -1197,6 +1219,7 @@ async fn attest_and_aggregate<B: BeaconNodeApi>(
slot: u64,
slot_duties: &[crate::beacon_node::dto::AttesterDutyDto],
store: &RwLock<ValidatorStore>,
attested: tokio::sync::oneshot::Sender<()>,
) {
// Bound the slot's work by what is left of the slot.
//
Expand All @@ -1218,17 +1241,23 @@ async fn attest_and_aggregate<B: BeaconNodeApi>(
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,
"Attestation duty ran past the end of its slot and was abandoned"
);
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.
Expand Down
21 changes: 21 additions & 0 deletions crates/validator/src/slot_clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down