mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 18:32:42 +00:00
Split the VC into crates making it more modular (#6453)
* Starting to modularize the VC * Revert changes to eth2 * More progress * More progress * Compiles * Merge latest unstable and make it compile * Fix some lints * Tests compile * Merge latest unstable * Remove unnecessary deps * Merge latest unstable * Correct release tests * Merge latest unstable * Merge remote-tracking branch 'origin/unstable' into modularize-vc * Merge branch 'unstable' into modularize-vc * Revert unnecessary cargo lock changes * Update validator_client/beacon_node_fallback/Cargo.toml * Update validator_client/http_metrics/Cargo.toml * Update validator_client/http_metrics/src/lib.rs * Update validator_client/initialized_validators/Cargo.toml * Update validator_client/signing_method/Cargo.toml * Update validator_client/validator_metrics/Cargo.toml * Update validator_client/validator_services/Cargo.toml * Update validator_client/validator_store/Cargo.toml * Update validator_client/validator_store/src/lib.rs * Merge remote-tracking branch 'origin/unstable' into modularize-vc * Fix format string * Rename doppelganger trait * Don't drop the tempdir * Cargo fmt
This commit is contained in:
80
validator_client/http_api/src/graffiti.rs
Normal file
80
validator_client/http_api/src/graffiti.rs
Normal file
@@ -0,0 +1,80 @@
|
||||
use bls::PublicKey;
|
||||
use slot_clock::SlotClock;
|
||||
use std::sync::Arc;
|
||||
use types::{graffiti::GraffitiString, EthSpec, Graffiti};
|
||||
use validator_store::ValidatorStore;
|
||||
|
||||
pub fn get_graffiti<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
validator_pubkey: PublicKey,
|
||||
validator_store: Arc<ValidatorStore<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<ValidatorStore<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<ValidatorStore<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(),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user