mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-20 06:18:31 +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:
@@ -1,8 +1,5 @@
|
||||
use crate::beacon_node_fallback::{BeaconNodeFallback, RequireSynced};
|
||||
use crate::{
|
||||
fee_recipient_file::FeeRecipientFile,
|
||||
validator_store::{DoppelgangerStatus, ValidatorStore},
|
||||
};
|
||||
use crate::validator_store::{DoppelgangerStatus, ValidatorStore};
|
||||
use bls::PublicKeyBytes;
|
||||
use environment::RuntimeContext;
|
||||
use parking_lot::RwLock;
|
||||
@@ -31,8 +28,6 @@ pub struct PreparationServiceBuilder<T: SlotClock + 'static, E: EthSpec> {
|
||||
slot_clock: Option<T>,
|
||||
beacon_nodes: Option<Arc<BeaconNodeFallback<T, E>>>,
|
||||
context: Option<RuntimeContext<E>>,
|
||||
fee_recipient: Option<Address>,
|
||||
fee_recipient_file: Option<FeeRecipientFile>,
|
||||
}
|
||||
|
||||
impl<T: SlotClock + 'static, E: EthSpec> PreparationServiceBuilder<T, E> {
|
||||
@@ -42,8 +37,6 @@ impl<T: SlotClock + 'static, E: EthSpec> PreparationServiceBuilder<T, E> {
|
||||
slot_clock: None,
|
||||
beacon_nodes: None,
|
||||
context: None,
|
||||
fee_recipient: None,
|
||||
fee_recipient_file: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,16 +60,6 @@ impl<T: SlotClock + 'static, E: EthSpec> PreparationServiceBuilder<T, E> {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn fee_recipient(mut self, fee_recipient: Option<Address>) -> Self {
|
||||
self.fee_recipient = fee_recipient;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn fee_recipient_file(mut self, fee_recipient_file: Option<FeeRecipientFile>) -> Self {
|
||||
self.fee_recipient_file = fee_recipient_file;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(self) -> Result<PreparationService<T, E>, String> {
|
||||
Ok(PreparationService {
|
||||
inner: Arc::new(Inner {
|
||||
@@ -92,8 +75,6 @@ impl<T: SlotClock + 'static, E: EthSpec> PreparationServiceBuilder<T, E> {
|
||||
context: self
|
||||
.context
|
||||
.ok_or("Cannot build PreparationService without runtime_context")?,
|
||||
fee_recipient: self.fee_recipient,
|
||||
fee_recipient_file: self.fee_recipient_file,
|
||||
validator_registration_cache: RwLock::new(HashMap::new()),
|
||||
}),
|
||||
})
|
||||
@@ -106,8 +87,6 @@ pub struct Inner<T, E: EthSpec> {
|
||||
slot_clock: T,
|
||||
beacon_nodes: Arc<BeaconNodeFallback<T, E>>,
|
||||
context: RuntimeContext<E>,
|
||||
fee_recipient: Option<Address>,
|
||||
fee_recipient_file: Option<FeeRecipientFile>,
|
||||
// Used to track unpublished validator registration changes.
|
||||
validator_registration_cache:
|
||||
RwLock<HashMap<ValidatorRegistrationKey, SignedValidatorRegistrationData>>,
|
||||
@@ -301,23 +280,6 @@ impl<T: SlotClock + 'static, E: EthSpec> PreparationService<T, E> {
|
||||
{
|
||||
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,
|
||||
"Error loading fee-recipient file";
|
||||
"error" => ?e
|
||||
);
|
||||
})
|
||||
.unwrap_or(());
|
||||
fee_recipient_file
|
||||
});
|
||||
|
||||
let all_pubkeys: Vec<_> = self
|
||||
.validator_store
|
||||
.voting_pubkeys(DoppelgangerStatus::ignored);
|
||||
@@ -327,22 +289,7 @@ impl<T: SlotClock + 'static, E: EthSpec> PreparationService<T, E> {
|
||||
.filter_map(|pubkey| {
|
||||
// Ignore fee recipients for keys without indices, they are inactive.
|
||||
let validator_index = self.validator_store.validator_index(&pubkey)?;
|
||||
|
||||
// If there is a `suggested_fee_recipient` in the validator definitions yaml
|
||||
// file, use that value.
|
||||
let fee_recipient = self
|
||||
.validator_store
|
||||
.suggested_fee_recipient(&pubkey)
|
||||
.or_else(|| {
|
||||
// If there's nothing in the validator defs file, check the fee
|
||||
// recipient file.
|
||||
fee_recipient_file
|
||||
.as_ref()?
|
||||
.get_fee_recipient(&pubkey)
|
||||
.ok()?
|
||||
})
|
||||
// If there's nothing in the file, try the process-level default value.
|
||||
.or(self.fee_recipient);
|
||||
let fee_recipient = self.validator_store.get_fee_recipient(&pubkey);
|
||||
|
||||
if let Some(fee_recipient) = fee_recipient {
|
||||
Some(map_fn(pubkey, validator_index, fee_recipient))
|
||||
|
||||
Reference in New Issue
Block a user