mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-09 03:17:55 +00:00
* pass slots_per_epoch at runtime * remove generic E from unrequired types * move `validator_store` to `lighthouse_validator_store` * make validator_store into a trait * further reduce dependencies * remove `environment` dependency on `beacon_node_fallback` * Manually pull in some changes from tracing-integration (thanks sayan!) Co-authored-by: ThreeHrSleep <threehrsleep@gmail.com> * remove `environment` from `validator_services` * unify boost factor accessors * add builder for DutiesService * Manually merge tracing PR for beacon_node_fallback Co-authored-by: ThreeHrSleep <threehrsleep@gmail.com> * Fix chain_spec for BlockService * address review * remove PhantomData from SyncDutiesMap * fix tests * correct test * Add `E` to `ValidatorStore` as associated type * fix tests * derive Clone for ValidatorStore's Error and required sub-errors * switch to enum for block signing to allow differing types --------- Co-authored-by: João Oliveira <hello@jxs.pt> Co-authored-by: ThreeHrSleep <threehrsleep@gmail.com> Co-authored-by: Jimmy Chen <jimmy@sigmaprime.io>
81 lines
3.3 KiB
Rust
81 lines
3.3 KiB
Rust
use bls::PublicKey;
|
|
use lighthouse_validator_store::LighthouseValidatorStore;
|
|
use slot_clock::SlotClock;
|
|
use std::sync::Arc;
|
|
use types::{graffiti::GraffitiString, EthSpec, Graffiti};
|
|
|
|
pub fn get_graffiti<T: 'static + SlotClock + Clone, E: EthSpec>(
|
|
validator_pubkey: PublicKey,
|
|
validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
|
graffiti_flag: Option<Graffiti>,
|
|
) -> Result<Graffiti, warp::Rejection> {
|
|
let initialized_validators_rw_lock = validator_store.initialized_validators();
|
|
let initialized_validators = initialized_validators_rw_lock.read();
|
|
match initialized_validators.validator(&validator_pubkey.compress()) {
|
|
None => Err(warp_utils::reject::custom_not_found(
|
|
"The key was not found on the server".to_string(),
|
|
)),
|
|
Some(_) => {
|
|
let Some(graffiti) = initialized_validators.graffiti(&validator_pubkey.into()) else {
|
|
return graffiti_flag.ok_or(warp_utils::reject::custom_server_error(
|
|
"No graffiti found, unable to return the process-wide default".to_string(),
|
|
));
|
|
};
|
|
Ok(graffiti)
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn set_graffiti<T: 'static + SlotClock + Clone, E: EthSpec>(
|
|
validator_pubkey: PublicKey,
|
|
graffiti: GraffitiString,
|
|
validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
|
) -> Result<(), warp::Rejection> {
|
|
let initialized_validators_rw_lock = validator_store.initialized_validators();
|
|
let mut initialized_validators = initialized_validators_rw_lock.write();
|
|
match initialized_validators.validator(&validator_pubkey.compress()) {
|
|
None => Err(warp_utils::reject::custom_not_found(
|
|
"The key was not found on the server, nothing to update".to_string(),
|
|
)),
|
|
Some(initialized_validator) => {
|
|
if initialized_validator.get_graffiti() == Some(graffiti.clone().into()) {
|
|
Ok(())
|
|
} else {
|
|
initialized_validators
|
|
.set_graffiti(&validator_pubkey, graffiti)
|
|
.map_err(|_| {
|
|
warp_utils::reject::custom_server_error(
|
|
"A graffiti was found, but failed to be updated.".to_string(),
|
|
)
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn delete_graffiti<T: 'static + SlotClock + Clone, E: EthSpec>(
|
|
validator_pubkey: PublicKey,
|
|
validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
|
) -> Result<(), warp::Rejection> {
|
|
let initialized_validators_rw_lock = validator_store.initialized_validators();
|
|
let mut initialized_validators = initialized_validators_rw_lock.write();
|
|
match initialized_validators.validator(&validator_pubkey.compress()) {
|
|
None => Err(warp_utils::reject::custom_not_found(
|
|
"The key was not found on the server, nothing to delete".to_string(),
|
|
)),
|
|
Some(initialized_validator) => {
|
|
if initialized_validator.get_graffiti().is_none() {
|
|
Ok(())
|
|
} else {
|
|
initialized_validators
|
|
.delete_graffiti(&validator_pubkey)
|
|
.map_err(|_| {
|
|
warp_utils::reject::custom_server_error(
|
|
"A graffiti was found, but failed to be removed.".to_string(),
|
|
)
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|