From bab026fbda97df8c5454c97a9ca7155b85c63d34 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Tue, 9 Jan 2024 14:31:04 +1100 Subject: [PATCH] Don't produce attestations when syncing --- .../beacon_chain/src/attestation_simulator.rs | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/beacon_node/beacon_chain/src/attestation_simulator.rs b/beacon_node/beacon_chain/src/attestation_simulator.rs index b0b25aef18c..6453158458a 100644 --- a/beacon_node/beacon_chain/src/attestation_simulator.rs +++ b/beacon_node/beacon_chain/src/attestation_simulator.rs @@ -4,7 +4,11 @@ use slot_clock::SlotClock; use std::sync::Arc; use task_executor::TaskExecutor; use tokio::time::sleep; -use types::Slot; +use types::{EthSpec, Slot}; + +/// Don't run the attestation simulator if the head slot is this many epochs +/// behind the wall-clock slot. +const SYNCING_TOLERANCE_EPOCHS: u64 = 2; /// Spawns a routine which produces an unaggregated attestation at every slot. /// @@ -58,33 +62,43 @@ async fn attestation_simulator_service( } pub fn produce_unaggregated_attestation( - inner_chain: Arc>, + chain: Arc>, current_slot: Slot, ) { + // Don't run the attestation simulator when the head slot is far behind the + // wall-clock slot. + // + // This helps prevent the simulator from becoming a burden by computing + // committees from old states. + let syncing_tolerance_slots = SYNCING_TOLERANCE_EPOCHS * T::EthSpec::slots_per_epoch(); + if chain.best_slot() + syncing_tolerance_slots < current_slot { + return; + } + // Since attestations for different committees are practically identical (apart from the committee index field) // Committee 0 is guaranteed to exist. That means there's no need to load the committee. let beacon_committee_index = 0; // Store the unaggregated attestation in the validator monitor for later processing - match inner_chain.produce_unaggregated_attestation(current_slot, beacon_committee_index) { + match chain.produce_unaggregated_attestation(current_slot, beacon_committee_index) { Ok(unaggregated_attestation) => { let data = &unaggregated_attestation.data; debug!( - inner_chain.log, + chain.log, "Produce unagg. attestation"; "attestation_source" => data.source.root.to_string(), "attestation_target" => data.target.root.to_string(), ); - inner_chain + chain .validator_monitor .write() .set_unaggregated_attestation(unaggregated_attestation); } Err(e) => { debug!( - inner_chain.log, + chain.log, "Failed to simulate attestation"; "error" => ?e );