diff --git a/validator_client/validator_services/src/duties_service.rs b/validator_client/validator_services/src/duties_service.rs index fde5e18f6a..7ae34a22d1 100644 --- a/validator_client/validator_services/src/duties_service.rs +++ b/validator_client/validator_services/src/duties_service.rs @@ -132,7 +132,6 @@ async fn make_selection_proof( spec: &ChainSpec, distributed: bool, beacon_nodes: &Arc>, - duties_service: &DutiesService, ) -> Result, Error> { let selection_proof = if distributed { // Submit a partial selection proof in the data field of the POST HTTP endpoint @@ -147,14 +146,12 @@ async fn make_selection_proof( }; // Call the endpoint /eth/v1/validator/beacon_committee_selections // The middleware should return a full selection proof here - let log = duties_service.context.log(); let response = beacon_nodes .first_success(|beacon_node| { let selections = selection.clone(); debug!( - log, - "Partial selection proof from VC"; - "Selection proof" => ?selections, + "Selection proof" = ?selections, + "Partial selection proof from VC" ); // println!("Selection proof: {:?}", selections); async move { @@ -162,12 +159,7 @@ async fn make_selection_proof( .post_validator_beacon_committee_selections(&[selections]) .await; - debug!( - log, - "Response from middleware"; - "response" => ?response, - - ); + debug!(?response, "Response from middleware"); // println!("Response from middleware {:?}", response); response @@ -1147,7 +1139,6 @@ async fn fill_in_selection_proofs( &duties_service.spec, duties_service.distributed, &duties_service.beacon_nodes, - &duties_service, ) .await?; Ok((duty, opt_selection_proof)) @@ -1163,7 +1154,6 @@ async fn fill_in_selection_proofs( &duties_service.spec, duties_service.distributed, &duties_service.beacon_nodes, - &duties_service, ) .await?; Ok((duty, opt_selection_proof)) diff --git a/validator_client/validator_services/src/sync.rs b/validator_client/validator_services/src/sync.rs index 7f27dd4263..a0a733d7a4 100644 --- a/validator_client/validator_services/src/sync.rs +++ b/validator_client/validator_services/src/sync.rs @@ -524,9 +524,8 @@ pub async fn fill_in_aggregation_proofs( Ok(subnet_ids) => subnet_ids, Err(e) => { crit!( - log, - "Arithmetic error computing subnet IDs"; - "error" => ?e, + "error" = ?e, + "Arithmetic error computing subnet IDs" ); continue; } @@ -563,31 +562,28 @@ pub async fn fill_in_aggregation_proofs( }; // Add log for debugging debug!( - log, - "Partial sync selection proof"; - "validator_index" => duty.validator_index, - "slot" => proof_slot, - "subcommittee_index" => subnet_id, - "partial selection proof" => ?proof, + "validator_index" = duty.validator_index, + "slot" = %proof_slot, + "subcommittee_index" = subnet_id, + "partial selection proof" = ?proof, + "Partial sync selection proof" ); Some(sync_committee_selection) } Err(ValidatorStoreError::UnknownPubkey(pubkey)) => { debug!( - log, - "Missing pubkey for sync selection proof"; - "pubkey" => ?pubkey, - "slot" => proof_slot, + ?pubkey, + "slot" = %proof_slot, + "Missing pubkey for sync selection proof" ); None } Err(e) => { warn!( - log, - "Unable to sign selection proof"; - "error" => ?e, - "pubkey" => ?duty.pubkey, - "slot" => proof_slot, + "error" = ?e, + "pubkey" = ?duty.pubkey, + "slot" = %proof_slot, + "Unable to sign selection proof" ); None } @@ -606,10 +602,8 @@ pub async fn fill_in_aggregation_proofs( // If we have any valid proofs, send them to the middleware if !selection_proofs.is_empty() { debug!( - log, - "Sending batch of partial sync selection proofs"; - "count" => selection_proofs.len(), - "slot" => slot, + "count" = selection_proofs.len(), + %slot, "Sending batch of partial sync selection proofs" ); let response = duties_service @@ -627,20 +621,14 @@ pub async fn fill_in_aggregation_proofs( match response { Ok(response) => { debug!( - log, - "Received batch response from middleware for sync"; - "count" => response.data.len(), - "slot" => slot, + "count" = response.data.len(), + %slot, "Received batch response from middleware for sync" ); // Get the sync map to update duties let sync_map = duties_service.sync_duties.committees.read(); let Some(committee_duties) = sync_map.get(&sync_committee_period) else { - debug!( - log, - "Missing sync duties"; - "period" => sync_committee_period, - ); + debug!("period" = sync_committee_period, "Missing sync duties"); continue; }; @@ -662,13 +650,12 @@ pub async fn fill_in_aggregation_proofs( Ok(true) => { if let Some(Some(duty)) = validators.get(&validator_index) { debug!( - log, - "Validator is sync aggregator"; - "validator_index" => validator_index, - "slot" => slot, - "subnet_id" => subcommittee_index, + validator_index, + %slot, + "subnet_id" = subcommittee_index, // log full selection proof for debugging - "full selection proof" => ?proof, + "full selection proof" = ?proof, + "Validator is sync aggregator" ); // Store the proof @@ -683,11 +670,10 @@ pub async fn fill_in_aggregation_proofs( } Err(e) => { warn!( - log, - "Error determining is_aggregator"; - "validator_index" => validator_index, - "slot" => slot, - "error" => ?e, + validator_index, + %slot, + "error" = ?e, + "Error determining is_aggregator" ); } } @@ -695,10 +681,9 @@ pub async fn fill_in_aggregation_proofs( } Err(e) => { warn!( - log, - "Failed to get sync selection proofs from middleware"; - "error" => %e, - "slot" => slot, + "error" = %e, + %slot, + "Failed to get sync selection proofs from middleware" ); } } @@ -711,112 +696,113 @@ pub async fn fill_in_aggregation_proofs( if slot < *validator_start_slot { continue; } - + let subnet_ids = match duty.subnet_ids::() { - Ok(subnet_ids) => subnet_ids, - Err(e) => { - crit!( - error = ?e, - "Arithmetic error computing subnet IDs" - ); - continue; - } - }; - - // Create futures to produce proofs. - let duties_service_ref = &duties_service; - let futures = subnet_ids.iter().map(|subnet_id| async move { - // Construct proof for prior slot. - let proof_slot = slot - 1; - - let proof = match duties_service_ref - .validator_store - .produce_sync_selection_proof(&duty.pubkey, proof_slot, *subnet_id) - .await - { - Ok(proof) => proof, - Err(ValidatorStoreError::UnknownPubkey(pubkey)) => { - // A pubkey can be missing when a validator was recently - // removed via the API. - debug!( - ?pubkey, - pubkey = ?duty.pubkey, - slot = %proof_slot, - "Missing pubkey for sync selection proof" - ); - return None; - } + Ok(subnet_ids) => subnet_ids, Err(e) => { - warn!( + crit!( error = ?e, - pubkey = ?duty.pubkey, - slot = %proof_slot, - "Unable to sign selection proof" + "Arithmetic error computing subnet IDs" ); - return None; + continue; } }; - match proof.is_aggregator::() { - Ok(true) => { - debug!( - validator_index = duty.validator_index, - slot = %proof_slot, - %subnet_id, - "Validator is sync aggregator" - ); - Some(((proof_slot, *subnet_id), proof)) - } - Ok(false) => None, - Err(e) => { - warn!( - pubkey = ?duty.pubkey, - slot = %proof_slot, - error = ?e, - "Error determining is_aggregator" - ); - None + // Create futures to produce proofs. + let duties_service_ref = &duties_service; + let futures = subnet_ids.iter().map(|subnet_id| async move { + // Construct proof for prior slot. + let proof_slot = slot - 1; + + let proof = match duties_service_ref + .validator_store + .produce_sync_selection_proof(&duty.pubkey, proof_slot, *subnet_id) + .await + { + Ok(proof) => proof, + Err(ValidatorStoreError::UnknownPubkey(pubkey)) => { + // A pubkey can be missing when a validator was recently + // removed via the API. + debug!( + ?pubkey, + pubkey = ?duty.pubkey, + slot = %proof_slot, + "Missing pubkey for sync selection proof" + ); + return None; + } + Err(e) => { + warn!( + error = ?e, + pubkey = ?duty.pubkey, + slot = %proof_slot, + "Unable to sign selection proof" + ); + return None; + } + }; + + match proof.is_aggregator::() { + Ok(true) => { + debug!( + validator_index = duty.validator_index, + slot = %proof_slot, + %subnet_id, + "Validator is sync aggregator" + ); + Some(((proof_slot, *subnet_id), proof)) + } + Ok(false) => None, + Err(e) => { + warn!( + pubkey = ?duty.pubkey, + slot = %proof_slot, + error = ?e, + "Error determining is_aggregator" + ); + None + } } + }); + + // Execute all the futures in parallel, collecting any successful results. + let proofs = join_all(futures) + .await + .into_iter() + .flatten() + .collect::>(); + + validator_proofs.push((duty.validator_index, proofs)); + } + + // Add to global storage (we add regularly so the proofs can be used ASAP). + let sync_map = duties_service.sync_duties.committees.read(); + let Some(committee_duties) = sync_map.get(&sync_committee_period) else { + debug!(period = sync_committee_period, "Missing sync duties"); + continue; + }; + let validators = committee_duties.validators.read(); + let num_validators_updated = validator_proofs.len(); + + for (validator_index, proofs) in validator_proofs { + if let Some(Some(duty)) = validators.get(&validator_index) { + duty.aggregation_duties.proofs.write().extend(proofs); + } else { + debug!( + validator_index, + period = sync_committee_period, + "Missing sync duty to update" + ); } - }); + } - // Execute all the futures in parallel, collecting any successful results. - let proofs = join_all(futures) - .await - .into_iter() - .flatten() - .collect::>(); - - validator_proofs.push((duty.validator_index, proofs)); - } - - // Add to global storage (we add regularly so the proofs can be used ASAP). - let sync_map = duties_service.sync_duties.committees.read(); - let Some(committee_duties) = sync_map.get(&sync_committee_period) else { - debug!(period = sync_committee_period, "Missing sync duties"); - continue; - }; - let validators = committee_duties.validators.read(); - let num_validators_updated = validator_proofs.len(); - - for (validator_index, proofs) in validator_proofs { - if let Some(Some(duty)) = validators.get(&validator_index) { - duty.aggregation_duties.proofs.write().extend(proofs); - } else { + if num_validators_updated > 0 { debug!( - validator_index, - period = sync_committee_period, - "Missing sync duty to update" + %slot, + updated_validators = num_validators_updated, + "Finished computing sync selection proofs" ); } } - - if num_validators_updated > 0 { - debug!( - %slot, - updated_validators = num_validators_updated, - "Finished computing sync selection proofs" - ); - } } }