Skip to content

Commit

Permalink
Add vc --disable-attesting flag
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul committed Feb 25, 2025
1 parent fd1ca8e commit 279afb0
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 0 deletions.
8 changes: 8 additions & 0 deletions validator_client/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ pub struct ValidatorClient {
)]
pub disable_auto_discover: bool,

#[clap(
long,
help = "Disable everything except block proposals",
display_order = 0,
help_heading = FLAG_HEADER
)]
pub disable_attesting: bool,

#[clap(
long,
help = "If present, the validator client will use longer timeouts for requests \
Expand Down
4 changes: 4 additions & 0 deletions validator_client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub struct Config {
/// Configuration for the initialized validators
#[serde(flatten)]
pub initialized_validators: InitializedValidatorsConfig,
pub disable_attesting: bool,
}

impl Default for Config {
Expand Down Expand Up @@ -126,6 +127,7 @@ impl Default for Config {
validator_registration_batch_size: 500,
distributed: false,
initialized_validators: <_>::default(),
disable_attesting: false,
}
}
}
Expand Down Expand Up @@ -379,6 +381,8 @@ impl Config {
true
};

config.disable_attesting = validator_client_config.disable_attesting;

Ok(config)
}
}
Expand Down
2 changes: 2 additions & 0 deletions validator_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ impl<E: EthSpec> ProductionValidatorClient<E> {
context: duties_context,
enable_high_validator_count_metrics: config.enable_high_validator_count_metrics,
distributed: config.distributed,
disable_attesting: config.disable_attesting,
});

// Update the metrics server.
Expand Down Expand Up @@ -507,6 +508,7 @@ impl<E: EthSpec> ProductionValidatorClient<E> {
.validator_store(validator_store.clone())
.beacon_nodes(beacon_nodes.clone())
.runtime_context(context.service_context("attestation".into()))
.disable(config.disable_attesting)
.build()?;

let preparation_service = PreparationServiceBuilder::new()
Expand Down
13 changes: 13 additions & 0 deletions validator_client/validator_services/src/attestation_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct AttestationServiceBuilder<T: SlotClock + 'static, E: EthSpec> {
slot_clock: Option<T>,
beacon_nodes: Option<Arc<BeaconNodeFallback<T, E>>>,
context: Option<RuntimeContext<E>>,
disable: bool,
}

impl<T: SlotClock + 'static, E: EthSpec> AttestationServiceBuilder<T, E> {
Expand All @@ -31,6 +32,7 @@ impl<T: SlotClock + 'static, E: EthSpec> AttestationServiceBuilder<T, E> {
slot_clock: None,
beacon_nodes: None,
context: None,
disable: false,
}
}

Expand Down Expand Up @@ -59,6 +61,11 @@ impl<T: SlotClock + 'static, E: EthSpec> AttestationServiceBuilder<T, E> {
self
}

pub fn disable(mut self, disable: bool) -> Self {
self.disable = disable;
self
}

pub fn build(self) -> Result<AttestationService<T, E>, String> {
Ok(AttestationService {
inner: Arc::new(Inner {
Expand All @@ -77,6 +84,7 @@ impl<T: SlotClock + 'static, E: EthSpec> AttestationServiceBuilder<T, E> {
context: self
.context
.ok_or("Cannot build AttestationService without runtime_context")?,
disable: self.disable,
}),
})
}
Expand All @@ -89,6 +97,7 @@ pub struct Inner<T, E: EthSpec> {
slot_clock: T,
beacon_nodes: Arc<BeaconNodeFallback<T, E>>,
context: RuntimeContext<E>,
disable: bool,
}

/// Attempts to produce attestations for all known validators 1/3rd of the way through each slot.
Expand Down Expand Up @@ -120,6 +129,10 @@ impl<T: SlotClock + 'static, E: EthSpec> AttestationService<T, E> {
/// Starts the service which periodically produces attestations.
pub fn start_update_service(self, spec: &ChainSpec) -> Result<(), String> {
let log = self.context.log().clone();
if self.disable {
info!(log, "Attestation service disabled");
return Ok(());
}

let slot_duration = Duration::from_secs(spec.seconds_per_slot);
let duration_to_next_slot = self
Expand Down
6 changes: 6 additions & 0 deletions validator_client/validator_services/src/duties_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ pub struct DutiesService<T, E: EthSpec> {
pub enable_high_validator_count_metrics: bool,
/// If this validator is running in distributed mode.
pub distributed: bool,
pub disable_attesting: bool,
}

impl<T: SlotClock + 'static, E: EthSpec> DutiesService<T, E> {
Expand Down Expand Up @@ -403,6 +404,11 @@ pub fn start_update_service<T: SlotClock + 'static, E: EthSpec>(
"duties_service_proposers",
);

// Skip starting attestation duties or sync committee services.
if core_duties_service.disable_attesting {
return;
}

/*
* Spawn the task which keeps track of local attestation duties.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ impl<T: SlotClock + 'static, E: EthSpec> SyncCommitteeService<T, E> {

pub fn start_update_service(self, spec: &ChainSpec) -> Result<(), String> {
let log = self.context.log().clone();
if self.duties_service.disable_attesting {
info!(log, "Sync committee service disabled");
return Ok(());
}

let slot_duration = Duration::from_secs(spec.seconds_per_slot);
let duration_to_next_slot = self
.slot_clock
Expand Down

0 comments on commit 279afb0

Please sign in to comment.