mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 10:22:38 +00:00
Add graffiti cli flag to the validator client. (#1425)
## Issue Addressed #1419 ## Proposed Changes Creates a `--graffiti` cli flag in the validator client. If the flag is set, it overrides graffiti in the beacon node. ## Additional Info
This commit is contained in:
@@ -7,7 +7,7 @@ use slog::{crit, debug, error, info, trace, warn};
|
||||
use slot_clock::SlotClock;
|
||||
use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
use types::{EthSpec, PublicKey, Slot};
|
||||
use types::{EthSpec, Graffiti, PublicKey, Slot};
|
||||
|
||||
/// Builds a `BlockService`.
|
||||
pub struct BlockServiceBuilder<T, E: EthSpec> {
|
||||
@@ -15,6 +15,7 @@ pub struct BlockServiceBuilder<T, E: EthSpec> {
|
||||
slot_clock: Option<Arc<T>>,
|
||||
beacon_node: Option<RemoteBeaconNode<E>>,
|
||||
context: Option<RuntimeContext<E>>,
|
||||
graffiti: Option<Graffiti>,
|
||||
}
|
||||
|
||||
impl<T: SlotClock + 'static, E: EthSpec> BlockServiceBuilder<T, E> {
|
||||
@@ -24,6 +25,7 @@ impl<T: SlotClock + 'static, E: EthSpec> BlockServiceBuilder<T, E> {
|
||||
slot_clock: None,
|
||||
beacon_node: None,
|
||||
context: None,
|
||||
graffiti: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +49,11 @@ impl<T: SlotClock + 'static, E: EthSpec> BlockServiceBuilder<T, E> {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn graffiti(mut self, graffiti: Option<Graffiti>) -> Self {
|
||||
self.graffiti = graffiti;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(self) -> Result<BlockService<T, E>, String> {
|
||||
Ok(BlockService {
|
||||
inner: Arc::new(Inner {
|
||||
@@ -62,6 +69,7 @@ impl<T: SlotClock + 'static, E: EthSpec> BlockServiceBuilder<T, E> {
|
||||
context: self
|
||||
.context
|
||||
.ok_or_else(|| "Cannot build BlockService without runtime_context")?,
|
||||
graffiti: self.graffiti,
|
||||
}),
|
||||
})
|
||||
}
|
||||
@@ -73,6 +81,7 @@ pub struct Inner<T, E: EthSpec> {
|
||||
slot_clock: Arc<T>,
|
||||
beacon_node: RemoteBeaconNode<E>,
|
||||
context: RuntimeContext<E>,
|
||||
graffiti: Option<Graffiti>,
|
||||
}
|
||||
|
||||
/// Attempts to produce attestations for any block producer(s) at the start of the epoch.
|
||||
@@ -214,7 +223,7 @@ impl<T: SlotClock + 'static, E: EthSpec> BlockService<T, E> {
|
||||
.beacon_node
|
||||
.http
|
||||
.validator()
|
||||
.produce_block(slot, randao_reveal)
|
||||
.produce_block(slot, randao_reveal, self.graffiti)
|
||||
.await
|
||||
.map_err(|e| format!("Error from beacon node when producing block: {:?}", e))?;
|
||||
|
||||
|
||||
@@ -60,4 +60,12 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
|
||||
node is not synced.",
|
||||
),
|
||||
)
|
||||
// This overwrites the graffiti configured in the beacon node.
|
||||
.arg(
|
||||
Arg::with_name("graffiti")
|
||||
.long("graffiti")
|
||||
.help("Specify your custom graffiti to be included in blocks.")
|
||||
.value_name("GRAFFITI")
|
||||
.takes_value(true)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ use clap::ArgMatches;
|
||||
use clap_utils::{parse_optional, parse_path_with_default_in_home_dir};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::path::PathBuf;
|
||||
use types::{Graffiti, GRAFFITI_BYTES_LEN};
|
||||
|
||||
pub const DEFAULT_HTTP_SERVER: &str = "http://localhost:5052/";
|
||||
pub const DEFAULT_DATA_DIR: &str = ".lighthouse/validators";
|
||||
@@ -27,6 +28,8 @@ pub struct Config {
|
||||
pub strict_lockfiles: bool,
|
||||
/// If true, don't scan the validators dir for new keystores.
|
||||
pub disable_auto_discover: bool,
|
||||
/// Graffiti to be inserted everytime we create a block.
|
||||
pub graffiti: Option<Graffiti>,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
@@ -45,6 +48,7 @@ impl Default for Config {
|
||||
allow_unsynced_beacon_node: false,
|
||||
strict_lockfiles: false,
|
||||
disable_auto_discover: false,
|
||||
graffiti: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,6 +84,26 @@ impl Config {
|
||||
config.secrets_dir = secrets_dir;
|
||||
}
|
||||
|
||||
if let Some(input_graffiti) = cli_args.value_of("graffiti") {
|
||||
let graffiti_bytes = input_graffiti.as_bytes();
|
||||
if graffiti_bytes.len() > GRAFFITI_BYTES_LEN {
|
||||
return Err(format!(
|
||||
"Your graffiti is too long! {} bytes maximum!",
|
||||
GRAFFITI_BYTES_LEN
|
||||
));
|
||||
} else {
|
||||
// Default graffiti to all 0 bytes.
|
||||
let mut graffiti = Graffiti::default();
|
||||
|
||||
// Copy the provided bytes over.
|
||||
//
|
||||
// Panic-free because `graffiti_bytes.len()` <= `GRAFFITI_BYTES_LEN`.
|
||||
graffiti[..graffiti_bytes.len()].copy_from_slice(&graffiti_bytes);
|
||||
|
||||
config.graffiti = Some(graffiti);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,6 +216,7 @@ impl<T: EthSpec> ProductionValidatorClient<T> {
|
||||
.validator_store(validator_store.clone())
|
||||
.beacon_node(beacon_node.clone())
|
||||
.runtime_context(context.service_context("block".into()))
|
||||
.graffiti(config.graffiti)
|
||||
.build()?;
|
||||
|
||||
let attestation_service = AttestationServiceBuilder::new()
|
||||
|
||||
Reference in New Issue
Block a user