mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 02:42:38 +00:00
Add support for updating validator graffiti (#4417)
## Issue Addressed #4386 ## Proposed Changes The original proposal described in the issue adds a new endpoint to support updating validator graffiti, but I realized we already have an endpoint that we use for updating various validator fields in memory and in the validator definitions file, so I think that would be the best place to add this to. ### API endpoint `PATCH lighthouse/validators/{validator_pubkey}` This endpoint updates the graffiti in both the [ validator definition file](https://lighthouse-book.sigmaprime.io/graffiti.html#2-setting-the-graffiti-in-the-validator_definitionsyml) and the in memory `InitializedValidators`. In the next block proposal, the new graffiti will be used. Note that the [`--graffiti-file`](https://lighthouse-book.sigmaprime.io/graffiti.html#1-using-the---graffiti-file-flag-on-the-validator-client) flag has a priority over the validator definitions file, so if the caller attempts to update the graffiti while the `--graffiti-file` flag is present, the endpoint will return an error (Bad request 400). ## Tasks - [x] Add graffiti update support to `PATCH lighthouse/validators/{validator_pubkey}` - [x] Return error if user tries to update graffiti while the `--graffiti-flag` is set - [x] Update Lighthouse book
This commit is contained in:
@@ -27,6 +27,7 @@ use std::io::{self, Read};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use types::graffiti::GraffitiString;
|
||||
use types::{Address, Graffiti, Keypair, PublicKey, PublicKeyBytes};
|
||||
use url::{ParseError, Url};
|
||||
use validator_dir::Builder as ValidatorDirBuilder;
|
||||
@@ -147,6 +148,10 @@ impl InitializedValidator {
|
||||
pub fn get_index(&self) -> Option<u64> {
|
||||
self.index
|
||||
}
|
||||
|
||||
pub fn get_graffiti(&self) -> Option<Graffiti> {
|
||||
self.graffiti
|
||||
}
|
||||
}
|
||||
|
||||
fn open_keystore(path: &Path) -> Result<Keystore, Error> {
|
||||
@@ -671,8 +676,8 @@ impl InitializedValidators {
|
||||
self.validators.get(public_key)
|
||||
}
|
||||
|
||||
/// Sets the `InitializedValidator` and `ValidatorDefinition` `enabled`, `gas_limit`, and `builder_proposals`
|
||||
/// values.
|
||||
/// Sets the `InitializedValidator` and `ValidatorDefinition` `enabled`, `gas_limit`,
|
||||
/// `builder_proposals`, and `graffiti` values.
|
||||
///
|
||||
/// ## Notes
|
||||
///
|
||||
@@ -682,7 +687,7 @@ impl InitializedValidators {
|
||||
///
|
||||
/// If a `gas_limit` is included in the call to this function, it will also be updated and saved
|
||||
/// to disk. If `gas_limit` is `None` the `gas_limit` *will not* be unset in `ValidatorDefinition`
|
||||
/// or `InitializedValidator`. The same logic applies to `builder_proposals`.
|
||||
/// or `InitializedValidator`. The same logic applies to `builder_proposals` and `graffiti`.
|
||||
///
|
||||
/// Saves the `ValidatorDefinitions` to file, even if no definitions were changed.
|
||||
pub async fn set_validator_definition_fields(
|
||||
@@ -691,6 +696,7 @@ impl InitializedValidators {
|
||||
enabled: Option<bool>,
|
||||
gas_limit: Option<u64>,
|
||||
builder_proposals: Option<bool>,
|
||||
graffiti: Option<GraffitiString>,
|
||||
) -> Result<(), Error> {
|
||||
if let Some(def) = self
|
||||
.definitions
|
||||
@@ -708,6 +714,9 @@ impl InitializedValidators {
|
||||
if let Some(builder_proposals) = builder_proposals {
|
||||
def.builder_proposals = Some(builder_proposals);
|
||||
}
|
||||
if let Some(graffiti) = graffiti.clone() {
|
||||
def.graffiti = Some(graffiti);
|
||||
}
|
||||
}
|
||||
|
||||
self.update_validators().await?;
|
||||
@@ -723,6 +732,9 @@ impl InitializedValidators {
|
||||
if let Some(builder_proposals) = builder_proposals {
|
||||
val.builder_proposals = Some(builder_proposals);
|
||||
}
|
||||
if let Some(graffiti) = graffiti {
|
||||
val.graffiti = Some(graffiti.into());
|
||||
}
|
||||
}
|
||||
|
||||
self.definitions
|
||||
|
||||
Reference in New Issue
Block a user