diff --git a/beacon_node/execution_layer/src/lib.rs b/beacon_node/execution_layer/src/lib.rs index 0b07bfbd497..f9427eda797 100644 --- a/beacon_node/execution_layer/src/lib.rs +++ b/beacon_node/execution_layer/src/lib.rs @@ -268,7 +268,7 @@ impl ExecutionLayer { ) -> Result<(), Error> { info!( self.log(), - "Received proposer preperation data"; + "Received proposer preparation data"; "count" => preparation_data.len(), ); diff --git a/validator_client/src/fee_recipient_file.rs b/validator_client/src/fee_recipient_file.rs index 2c5ac20e0e7..637ca6d3d5d 100644 --- a/validator_client/src/fee_recipient_file.rs +++ b/validator_client/src/fee_recipient_file.rs @@ -44,10 +44,7 @@ impl FeeRecipientFile { /// default fee-recipient. /// /// Returns an error if loading from the fee-recipient file fails. - pub fn get_fee_recipient( - &mut self, - public_key: &PublicKeyBytes, - ) -> Result, Error> { + pub fn get_fee_recipient(&self, public_key: &PublicKeyBytes) -> Result, Error> { Ok(self .fee_recipients .get(public_key) @@ -82,6 +79,9 @@ impl FeeRecipientFile { let lines = reader.lines(); + self.default = None; + self.fee_recipients.clear(); + for line in lines { let line = line.map_err(|e| Error::InvalidLine(e.to_string()))?; let (pk_opt, fee_recipient) = read_line(&line)?; diff --git a/validator_client/src/preparation_service.rs b/validator_client/src/preparation_service.rs index a5da2a421a3..0875c00b31c 100644 --- a/validator_client/src/preparation_service.rs +++ b/validator_client/src/preparation_service.rs @@ -141,7 +141,16 @@ impl PreparationService { self.slot_clock.duration_to_next_epoch(E::slots_per_epoch()) { sleep(duration_to_next_epoch).await; - self.prepare_proposers_and_publish().await.unwrap(); + self.prepare_proposers_and_publish() + .await + .map_err(|e| { + error!( + log, + "Error during proposer preparation"; + "error" => format!("{:?}", e), + ) + }) + .unwrap_or(()); } else { error!(log, "Failed to read slot clock"); // If we can't read the slot clock, just wait another slot. @@ -157,29 +166,45 @@ impl PreparationService { /// Prepare proposer preparations and send to beacon node async fn prepare_proposers_and_publish(&self) -> Result<(), String> { + let preparation_data = self.collect_preparation_data().unwrap(); + if !preparation_data.is_empty() { + self.publish_preparation_data(preparation_data).await?; + } + + Ok(()) + } + + fn collect_preparation_data(&self) -> Result, String> { let log = self.context.log(); + let fee_recipient_file = self + .fee_recipient_file + .clone() + .map(|mut fee_recipient_file| { + fee_recipient_file + .read_fee_recipient_file() + .map_err(|e| { + error!( + log, + "{}", format!("Error loading fee-recipient file: {:?}", e); + ); + }) + .unwrap_or(()); + fee_recipient_file + }); + let all_pubkeys: Vec<_> = self .validator_store .voting_pubkeys(DoppelgangerStatus::ignored); - if self.fee_recipient_file.is_some() { - self.fee_recipient_file - .clone() - .unwrap() - .read_fee_recipient_file() - .unwrap(); - } - let preparation_data: Vec<_> = all_pubkeys .into_iter() .filter_map(|pubkey| { let validator_index = self.validator_store.validator_index(&pubkey); if let Some(validator_index) = validator_index { - let fee_recipient = self - .fee_recipient_file - .clone() - .and_then(|mut g| match g.get_fee_recipient(&pubkey) { + let fee_recipient = fee_recipient_file + .as_ref() + .and_then(|g| match g.get_fee_recipient(&pubkey) { Ok(g) => g, Err(_e) => None, }) @@ -195,33 +220,38 @@ impl PreparationService { }) .collect(); - let proposal_preparation = preparation_data.as_slice(); + Ok(preparation_data) + } + + async fn publish_preparation_data( + &self, + preparation_data: Vec, + ) -> Result<(), String> { + let log = self.context.log(); + // Post the proposer preparations to the BN. let preparation_data_len = preparation_data.len(); - if preparation_data_len > 0 { - // Post the proposer preparations to the BN. - match self - .beacon_nodes - .first_success(RequireSynced::Yes, |beacon_node| async move { - beacon_node - .post_validator_prepare_beacon_proposer(proposal_preparation) - .await - }) - .await - { - Ok(()) => info!( - log, - "Successfully published proposer preparation"; - "count" => preparation_data_len, - ), - Err(e) => error!( - log, - "Unable to publish proposer preparation"; - "error" => %e, - ), - } + let preparation_entries = preparation_data.as_slice(); + match self + .beacon_nodes + .first_success(RequireSynced::Yes, |beacon_node| async move { + beacon_node + .post_validator_prepare_beacon_proposer(preparation_entries) + .await + }) + .await + { + Ok(()) => info!( + log, + "Successfully published proposer preparation"; + "count" => preparation_data_len, + ), + Err(e) => error!( + log, + "Unable to publish proposer preparation"; + "error" => %e, + ), } - Ok(()) } }