address comments

This commit is contained in:
Tan Chee Keong
2025-04-29 16:28:42 +08:00
parent 9d6d1cb654
commit d34a91ac07
3 changed files with 34 additions and 44 deletions

View File

@@ -115,7 +115,6 @@ pub struct SubscriptionSlots {
duty_slot: Slot,
}
#[derive(Clone)]
pub struct SelectionProofConfig {
pub lookahead_slot: u64,
pub computation_offset: Duration, // The seconds to compute the selection proof before a slot
@@ -130,10 +129,10 @@ async fn make_selection_proof<T: SlotClock + 'static, E: EthSpec>(
duty: &AttesterData,
validator_store: &ValidatorStore<T, E>,
spec: &ChainSpec,
duties_service: &DutiesService<T, E>,
beacon_nodes: &Arc<BeaconNodeFallback<T, E>>,
config: &SelectionProofConfig,
) -> Result<Option<SelectionProof>, Error> {
let selection_proof = if duties_service.selection_proof_config.selections_endpoint {
let selection_proof = if config.selections_endpoint {
let beacon_committee_selection = BeaconCommitteeSelection {
validator_index: duty.validator_index,
slot: duty.slot,
@@ -1161,12 +1160,7 @@ async fn fill_in_selection_proofs<T: SlotClock + 'static, E: EthSpec>(
while !duties_by_slot.is_empty() {
if let Some(duration) = slot_clock.duration_to_next_slot() {
sleep(
duration.saturating_sub(
duties_service
.sync_duties
.selection_proof_config
.computation_offset,
),
duration.saturating_sub(duties_service.selection_proof_config.computation_offset),
)
.await;
@@ -1174,18 +1168,11 @@ async fn fill_in_selection_proofs<T: SlotClock + 'static, E: EthSpec>(
continue;
};
let selection_lookahead = duties_service
.sync_duties
.selection_proof_config
.lookahead_slot;
let selection_lookahead = duties_service.selection_proof_config.lookahead_slot;
let lookahead_slot = current_slot + selection_lookahead;
let relevant_duties = if duties_service
.sync_duties
.selection_proof_config
.parallel_sign
{
let relevant_duties = if duties_service.selection_proof_config.parallel_sign {
// Remove old slot duties and only keep current duties in distributed mode
duties_by_slot
.remove(&lookahead_slot)
@@ -1211,11 +1198,7 @@ async fn fill_in_selection_proofs<T: SlotClock + 'static, E: EthSpec>(
// In distributed case, we want to send all partial selection proofs to the middleware to determine aggregation duties,
// as the middleware will need to have a threshold of partial selection proofs to be able to return the full selection proof
// Thus, sign selection proofs in parallel in distributed case; Otherwise, sign them serially in non-distributed (normal) case
if duties_service
.sync_duties
.selection_proof_config
.parallel_sign
{
if duties_service.selection_proof_config.parallel_sign {
let mut duty_and_proof_results = relevant_duties
.into_values()
.flatten()
@@ -1224,8 +1207,8 @@ async fn fill_in_selection_proofs<T: SlotClock + 'static, E: EthSpec>(
&duty,
&duties_service.validator_store,
&duties_service.spec,
&duties_service,
&duties_service.beacon_nodes,
&duties_service.selection_proof_config,
)
.await?;
Ok((duty, opt_selection_proof))
@@ -1252,8 +1235,8 @@ async fn fill_in_selection_proofs<T: SlotClock + 'static, E: EthSpec>(
&duty,
&duties_service.validator_store,
&duties_service.spec,
&duties_service,
&duties_service.beacon_nodes,
&duties_service.selection_proof_config,
)
.await?;
Ok((duty, opt_selection_proof))

View File

@@ -14,11 +14,6 @@ use tracing::{debug, error, info, warn};
use types::{ChainSpec, EthSpec, PublicKeyBytes, Slot, SyncDuty, SyncSelectionProof, SyncSubnetId};
use validator_store::Error as ValidatorStoreError;
/// Number of epochs in advance to compute selection proofs when not in `distributed` mode.
pub const AGGREGATION_PRE_COMPUTE_EPOCHS: u64 = 2;
/// Number of slots in advance to compute selection proofs when in `distributed` mode.
pub const AGGREGATION_PRE_COMPUTE_SLOTS_DISTRIBUTED: u64 = 1;
/// Top-level data-structure containing sync duty information.
///
/// This data is structured as a series of nested `HashMap`s wrapped in `RwLock`s. Fine-grained
@@ -106,15 +101,6 @@ impl<E: EthSpec> SyncDutiesMap<E> {
})
}
/// Number of slots in advance to compute selection proofs
fn aggregation_pre_compute_slots(&self) -> u64 {
if self.selection_proof_config.parallel_sign {
AGGREGATION_PRE_COMPUTE_SLOTS_DISTRIBUTED
} else {
E::slots_per_epoch() * AGGREGATION_PRE_COMPUTE_EPOCHS
}
}
/// Prepare for pre-computation of selection proofs for `committee_period`.
///
/// Return the slot up to which proofs should be pre-computed, as well as a vec of
@@ -130,7 +116,7 @@ impl<E: EthSpec> SyncDutiesMap<E> {
current_slot,
first_slot_of_period::<E>(committee_period, spec),
);
let pre_compute_lookahead_slots = self.aggregation_pre_compute_slots();
let pre_compute_lookahead_slots = self.selection_proof_config.lookahead_slot;
let pre_compute_slot = std::cmp::min(
current_slot + pre_compute_lookahead_slots,
last_slot_of_period::<E>(committee_period, spec),
@@ -382,7 +368,7 @@ pub async fn poll_sync_committee_duties<T: SlotClock + 'static, E: EthSpec>(
}
// Pre-compute aggregator selection proofs for the next period.
let aggregate_pre_compute_lookahead_slots = sync_duties.aggregation_pre_compute_slots();
let aggregate_pre_compute_lookahead_slots = sync_duties.selection_proof_config.lookahead_slot;
if (current_slot + aggregate_pre_compute_lookahead_slots)
.epoch(E::slots_per_epoch())
.sync_committee_period(spec)?