mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-16 19:32:55 +00:00
Implement feerecipient API for keymanager (#3213)
## Issue Addressed * #3173 ## Proposed Changes Moved all `fee_recipient_file` related logic inside the `ValidatorStore` as it makes more sense to have this all together there. I tested this with the validators I have on `mainnet-shadow-fork-5` and everything appeared to work well. Only technicality is that I can't get the method to return `401` when the authorization header is not specified (it returns `400` instead). Fixing this is probably quite difficult given that none of `warp`'s rejections have code `401`.. I don't really think this matters too much though as long as it fails.
This commit is contained in:
@@ -617,6 +617,78 @@ impl InitializedValidators {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Sets the `InitializedValidator` and `ValidatorDefinition` `suggested_fee_recipient` values.
|
||||
///
|
||||
/// ## Notes
|
||||
///
|
||||
/// Setting a validator `fee_recipient` will cause `self.definitions` to be updated and saved to
|
||||
/// disk.
|
||||
///
|
||||
/// Saves the `ValidatorDefinitions` to file, even if no definitions were changed.
|
||||
pub fn set_validator_fee_recipient(
|
||||
&mut self,
|
||||
voting_public_key: &PublicKey,
|
||||
fee_recipient: Address,
|
||||
) -> Result<(), Error> {
|
||||
if let Some(def) = self
|
||||
.definitions
|
||||
.as_mut_slice()
|
||||
.iter_mut()
|
||||
.find(|def| def.voting_public_key == *voting_public_key)
|
||||
{
|
||||
def.suggested_fee_recipient = Some(fee_recipient);
|
||||
}
|
||||
|
||||
if let Some(val) = self
|
||||
.validators
|
||||
.get_mut(&PublicKeyBytes::from(voting_public_key))
|
||||
{
|
||||
val.suggested_fee_recipient = Some(fee_recipient);
|
||||
}
|
||||
|
||||
self.definitions
|
||||
.save(&self.validators_dir)
|
||||
.map_err(Error::UnableToSaveDefinitions)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Removes the `InitializedValidator` and `ValidatorDefinition` `suggested_fee_recipient` values.
|
||||
///
|
||||
/// ## Notes
|
||||
///
|
||||
/// Removing a validator `fee_recipient` will cause `self.definitions` to be updated and saved to
|
||||
/// disk. The fee_recipient for the validator will then fall back to the process level default if
|
||||
/// it is set.
|
||||
///
|
||||
/// Saves the `ValidatorDefinitions` to file, even if no definitions were changed.
|
||||
pub fn delete_validator_fee_recipient(
|
||||
&mut self,
|
||||
voting_public_key: &PublicKey,
|
||||
) -> Result<(), Error> {
|
||||
if let Some(def) = self
|
||||
.definitions
|
||||
.as_mut_slice()
|
||||
.iter_mut()
|
||||
.find(|def| def.voting_public_key == *voting_public_key)
|
||||
{
|
||||
def.suggested_fee_recipient = None;
|
||||
}
|
||||
|
||||
if let Some(val) = self
|
||||
.validators
|
||||
.get_mut(&PublicKeyBytes::from(voting_public_key))
|
||||
{
|
||||
val.suggested_fee_recipient = None;
|
||||
}
|
||||
|
||||
self.definitions
|
||||
.save(&self.validators_dir)
|
||||
.map_err(Error::UnableToSaveDefinitions)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Tries to decrypt the key cache.
|
||||
///
|
||||
/// Returns the decrypted cache if decryption was successful, or an error if a required password
|
||||
|
||||
Reference in New Issue
Block a user