rearrange

This commit is contained in:
Tan Chee Keong
2025-04-11 19:37:46 +08:00
parent ea13f74c06
commit 44bd5f13f6

View File

@@ -1150,8 +1150,8 @@ 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, // 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 // 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 // Thus, sign selection proofs in parallel in distributed case; Otherwise, sign them serially in non-distributed (normal) case
let duty_and_proof_results = if config.parallel_sign { if config.parallel_sign {
let mut futures = relevant_duties let mut duty_and_proof_results = relevant_duties
.into_values() .into_values()
.flatten() .flatten()
.map(|duty| async { .map(|duty| async {
@@ -1167,7 +1167,7 @@ async fn fill_in_selection_proofs<T: SlotClock + 'static, E: EthSpec>(
}) })
.collect::<FuturesUnordered<_>>(); .collect::<FuturesUnordered<_>>();
while let Some(result) = futures.next().await { while let Some(result) = duty_and_proof_results.next().await {
let mut attesters = duties_service.attesters.write(); let mut attesters = duties_service.attesters.write();
let (duty, selection_proof) = match result { let (duty, selection_proof) = match result {
Ok(duty_and_proof) => duty_and_proof, Ok(duty_and_proof) => duty_and_proof,
@@ -1233,9 +1233,8 @@ async fn fill_in_selection_proofs<T: SlotClock + 'static, E: EthSpec>(
} }
} }
} }
Vec::new()
} else { } else {
stream::iter(relevant_duties.into_values().flatten()) let duty_and_proof_results = stream::iter(relevant_duties.into_values().flatten())
.then(|duty| async { .then(|duty| async {
let opt_selection_proof = make_selection_proof( let opt_selection_proof = make_selection_proof(
&duty, &duty,
@@ -1248,8 +1247,7 @@ async fn fill_in_selection_proofs<T: SlotClock + 'static, E: EthSpec>(
Ok((duty, opt_selection_proof)) Ok((duty, opt_selection_proof))
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
.await .await;
};
// Add to attesters store. // Add to attesters store.
let mut attesters = duties_service.attesters.write(); let mut attesters = duties_service.attesters.write();
@@ -1307,7 +1305,8 @@ async fn fill_in_selection_proofs<T: SlotClock + 'static, E: EthSpec>(
hash_map::Entry::Vacant(entry) => { hash_map::Entry::Vacant(entry) => {
// This probably shouldn't happen, but we have enough info to fill in the // This probably shouldn't happen, but we have enough info to fill in the
// entry so we may as well. // entry so we may as well.
let subscription_slots = SubscriptionSlots::new(duty.slot, current_slot); let subscription_slots =
SubscriptionSlots::new(duty.slot, current_slot);
let duty_and_proof = DutyAndProof { let duty_and_proof = DutyAndProof {
duty, duty,
selection_proof, selection_proof,
@@ -1318,6 +1317,7 @@ async fn fill_in_selection_proofs<T: SlotClock + 'static, E: EthSpec>(
} }
} }
drop(attesters); drop(attesters);
};
let time_taken_ms = let time_taken_ms =
Duration::from_secs_f64(timer.map_or(0.0, |t| t.stop_and_record())).as_millis(); Duration::from_secs_f64(timer.map_or(0.0, |t| t.stop_and_record())).as_millis();