From 93841652f5412643dc1b97583cf1c0e1c776070a Mon Sep 17 00:00:00 2001 From: pk910 Date: Tue, 18 Jan 2022 22:56:09 +0100 Subject: [PATCH] clear cached fee_recipient_file entries before reloading from file content --- validator_client/src/fee_recipient_file.rs | 18 +++-------------- validator_client/src/preparation_service.rs | 22 +++++++-------------- 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/validator_client/src/fee_recipient_file.rs b/validator_client/src/fee_recipient_file.rs index 2c5ac20e0e7..ac924239bc4 100644 --- a/validator_client/src/fee_recipient_file.rs +++ b/validator_client/src/fee_recipient_file.rs @@ -40,21 +40,6 @@ impl FeeRecipientFile { } } - /// Returns the fee-recipient corresponding to the given public key if present, else returns the - /// 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> { - Ok(self - .fee_recipients - .get(public_key) - .copied() - .or(self.default)) - } - /// Loads the fee-recipient file and populates the default fee-recipient and `fee_recipients` hashmap. /// Returns the fee-recipient corresponding to the given public key if present, else returns the /// default fee-recipient. @@ -82,6 +67,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 9eb713ec8ba..6450761a3a4 100644 --- a/validator_client/src/preparation_service.rs +++ b/validator_client/src/preparation_service.rs @@ -172,26 +172,18 @@ impl PreparationService { .validator_store .voting_pubkeys(DoppelgangerStatus::ignored); - if self.fee_recipient_file.is_some() { - self.fee_recipient_file - .clone() - .unwrap() - .read_fee_recipient_file() - .map_err(|e| format!("Error loading fee-recipient file: {:?}", e))?; - } - 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) { - Ok(g) => g, - Err(_e) => None, - }) + let fee_recipient = (if self.fee_recipient_file.is_some() { + self.fee_recipient_file + .clone() + .unwrap() + .load_fee_recipient(&pubkey) + .unwrap() + } else { None }) .or(self.fee_recipient); fee_recipient.map(|fee_recipient| ProposerPreparationData {