Skip to content

Commit 239160e

Browse files
committed
Clean up some logs and error handling
1 parent 71ce045 commit 239160e

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

validator_client/validator_services/src/duties_service.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,16 @@ pub struct SubscriptionSlots {
117117
#[derive(Copy, Clone, Debug)]
118118
pub struct SelectionProofConfig {
119119
pub lookahead_slot: u64,
120-
pub computation_offset: Duration, // The seconds to compute the selection proof before a slot
121-
pub selections_endpoint: bool, // whether to call the selections endpoint, true for DVT with middleware
122-
pub parallel_sign: bool, // whether to sign the selection proof in parallel, true in distributed mode
120+
/// The seconds to compute the selection proof before a slot.
121+
pub computation_offset: Duration,
122+
/// Whether to call the selections endpoint, true for DVT with middleware.
123+
pub selections_endpoint: bool,
124+
/// Whether to sign the selection proof in parallel, true in distributed mode.
125+
pub parallel_sign: bool,
123126
}
124127

125-
impl SelectionProofConfig {
126-
// Create a default associated function to be passed in DutiesServiceBuilder::new()
128+
/// The default config for selection proofs covers the non-DVT case.
129+
impl Default for SelectionProofConfig {
127130
fn default() -> Self {
128131
Self {
129132
lookahead_slot: 0,
@@ -175,11 +178,18 @@ async fn make_selection_proof<S: ValidatorStore + 'static, T: SlotClock>(
175178
})
176179
.await;
177180

178-
let response_data = &middleware_response
181+
let response_data = middleware_response
179182
.map_err(|e| {
180183
Error::FailedToProduceSelectionProof(ValidatorStoreError::Middleware(e.to_string()))
181184
})?
182-
.data[0];
185+
.data
186+
.pop()
187+
.ok_or_else(|| {
188+
Error::FailedToProduceSelectionProof(ValidatorStoreError::Middleware(format!(
189+
"attestation selection proof - empty response for validator {}",
190+
duty.validator_index
191+
)))
192+
})?;
183193

184194
debug!(
185195
"validator_index" = response_data.validator_index,
@@ -188,7 +198,7 @@ async fn make_selection_proof<S: ValidatorStore + 'static, T: SlotClock>(
188198
"full selection proof" = ?response_data.selection_proof,
189199
"Received selection from middleware"
190200
);
191-
SelectionProof::from(response_data.selection_proof.clone())
201+
SelectionProof::from(response_data.selection_proof)
192202
} else {
193203
validator_store
194204
.produce_selection_proof(duty.pubkey, duty.slot)

validator_client/validator_services/src/sync.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::duties_service::{DutiesService, Error, SelectionProofConfig};
2-
use eth2::types::{Signature, SyncCommitteeSelection};
2+
use eth2::types::SyncCommitteeSelection;
33
use futures::future::join_all;
44
use futures::stream::{FuturesUnordered, StreamExt};
55
use logging::crit;
@@ -530,7 +530,7 @@ pub async fn make_sync_selection_proof<S: ValidatorStore, T: SlotClock>(
530530
"slot" = %proof_slot,
531531
"subcommittee_index" = *subnet_id,
532532
// This is partial selection proof
533-
"partial selection proof" = ?Signature::from(selection_proof.clone()),
533+
"partial selection proof" = ?selection_proof,
534534
"Sending sync selection to middleware"
535535
);
536536

@@ -557,8 +557,15 @@ pub async fn make_sync_selection_proof<S: ValidatorStore, T: SlotClock>(
557557
.await;
558558

559559
match middleware_response {
560-
Ok(response) => {
561-
let response_data = &response.data[0];
560+
Ok(mut response) => {
561+
let Some(response_data) = response.data.pop() else {
562+
error!(
563+
validator_index = duty.validator_index,
564+
slot = %proof_slot,
565+
"Empty response from sync selection middleware",
566+
);
567+
return None;
568+
};
562569
debug!(
563570
"validator_index" = response_data.validator_index,
564571
"slot" = %response_data.slot,
@@ -570,7 +577,7 @@ pub async fn make_sync_selection_proof<S: ValidatorStore, T: SlotClock>(
570577

571578
// Convert the response to a SyncSelectionProof
572579
let full_selection_proof =
573-
SyncSelectionProof::from(response_data.selection_proof.clone());
580+
SyncSelectionProof::from(response_data.selection_proof);
574581
Some(full_selection_proof)
575582
}
576583
Err(e) => {

0 commit comments

Comments
 (0)