Skip to content

Commit

Permalink
clear cached fee_recipient_file entries before reloading from file co…
Browse files Browse the repository at this point in the history
…ntent
  • Loading branch information
pk910 committed Jan 18, 2022
1 parent 60b9c39 commit 9384165
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 30 deletions.
18 changes: 3 additions & 15 deletions validator_client/src/fee_recipient_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<Address>, 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.
Expand Down Expand Up @@ -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)?;
Expand Down
22 changes: 7 additions & 15 deletions validator_client/src/preparation_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,26 +172,18 @@ impl<T: SlotClock + 'static, E: EthSpec> PreparationService<T, E> {
.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 {
Expand Down

0 comments on commit 9384165

Please sign in to comment.