remove subnet for loop

This commit is contained in:
Tan Chee Keong
2025-04-01 19:58:53 +08:00
parent e8ca60ea23
commit e3406becb5

View File

@@ -1,6 +1,6 @@
use crate::duties_service::{DutiesService, Error}; use crate::duties_service::{DutiesService, Error};
use doppelganger_service::DoppelgangerStatus; use doppelganger_service::DoppelgangerStatus;
use eth2::types::SyncCommitteeSelection; use eth2::types::{Signature, SyncCommitteeSelection};
use futures::future::join_all; use futures::future::join_all;
use logging::crit; use logging::crit;
use parking_lot::{MappedRwLockReadGuard, RwLock, RwLockReadGuard, RwLockWriteGuard}; use parking_lot::{MappedRwLockReadGuard, RwLock, RwLockReadGuard, RwLockWriteGuard};
@@ -527,39 +527,33 @@ pub async fn fill_in_aggregation_proofs<T: SlotClock + 'static, E: EthSpec>(
// Construct proof for prior slot. // Construct proof for prior slot.
let proof_slot = slot - 1; let proof_slot = slot - 1;
// Create futures for all subnet IDs for this validator // Store all partial sync selection proofs in partial_proofs so that it can be sent together later
for subnet_id in subnet_ids { sync_committee_selection.extend(subnet_ids.iter().map(|&subnet_id| {
let duties_service = duties_service.clone(); let duties_service = duties_service.clone();
let duty = duty.clone(); let duty = duty.clone();
let subnet_id = *subnet_id; async move {
// Store all partial sync selection proofs in partial_proofs so that it can be sent together later
sync_committee_selection.push(async move {
// Produce partial selection proof // Produce partial selection proof
let partial_sync_selection_proof = duties_service let partial_sync_selection_proof = duties_service
.validator_store .validator_store
.produce_sync_selection_proof( .produce_sync_selection_proof(&duty.pubkey, proof_slot, subnet_id)
&duty.pubkey,
proof_slot,
subnet_id.into(),
)
.await; .await;
match partial_sync_selection_proof { match partial_sync_selection_proof {
Ok(proof) => { Ok(proof) => {
let sync_committee_selection = SyncCommitteeSelection {
validator_index: duty.validator_index,
slot: proof_slot,
subcommittee_index: subnet_id,
selection_proof: proof.clone().into(),
};
debug!( debug!(
"validator_index" = duty.validator_index, "validator_index" = duty.validator_index,
"slot" = %proof_slot, "slot" = %proof_slot,
"subcommittee_index" = subnet_id, "subcommittee_index" = *subnet_id,
"partial selection proof" = ?proof, "partial selection proof" = ?Signature::from(proof.clone()),
"Sending sync selection to middleware" "Sending sync selection to middleware"
); );
let sync_committee_selection = SyncCommitteeSelection {
validator_index: duty.validator_index,
slot: proof_slot,
subcommittee_index: *subnet_id,
selection_proof: proof.clone().into(),
};
Some(sync_committee_selection) Some(sync_committee_selection)
} }
Err(ValidatorStoreError::UnknownPubkey(pubkey)) => { Err(ValidatorStoreError::UnknownPubkey(pubkey)) => {
@@ -580,13 +574,13 @@ pub async fn fill_in_aggregation_proofs<T: SlotClock + 'static, E: EthSpec>(
None None
} }
} }
}); }
} }));
} }
let sync_committee_selection_data = join_all(sync_committee_selection).await; let sync_committee_selection_data = join_all(sync_committee_selection).await;
// Filter out None values and extract the selection proofs // Collect the SyncCommitteeSelection data
let sync_selection_data: Vec<_> = sync_committee_selection_data let sync_selection_data: Vec<_> = sync_committee_selection_data
.into_iter() .into_iter()
.flatten() .flatten()