Skip to content

Commit

Permalink
add produce-block-v3
Browse files Browse the repository at this point in the history
  • Loading branch information
eserilev committed Oct 9, 2023
1 parent 33f3411 commit a8ded56
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 12 deletions.
15 changes: 15 additions & 0 deletions lighthouse/tests/validator_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,21 @@ fn no_doppelganger_protection_flag() {
.run()
.with_config(|config| assert!(!config.enable_doppelganger_protection));
}
#[test]
fn produce_block_v3_flag() {
CommandLineTest::new()
.flag("produce-block-v3", None)
.run()
.with_config(|config| assert!(config.produce_block_v3));
}

#[test]
fn no_produce_block_v3_flag() {
CommandLineTest::new()
.run()
.with_config(|config| assert!(!config.produce_block_v3));
}

#[test]
fn block_delay_ms() {
CommandLineTest::new()
Expand Down
15 changes: 3 additions & 12 deletions validator_client/src/block_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,18 +334,8 @@ impl<T: SlotClock + 'static, E: EthSpec> BlockService<T, E> {
)
}

let deneb_fork_activated = self
.context
.eth2_config
.spec
.altair_fork_epoch
.and_then(|fork_epoch| {
let current_epoch = self.slot_clock.now()?.epoch(E::slots_per_epoch());
Some(current_epoch >= fork_epoch)
})
.unwrap_or(false);

if deneb_fork_activated {
// TODO: activate automatically at Deneb
if !self.validator_store.produce_block_v3() {
for validator_pubkey in proposers {
let service = self.clone();
let log = log.clone();
Expand Down Expand Up @@ -457,6 +447,7 @@ impl<T: SlotClock + 'static, E: EthSpec> BlockService<T, E> {
Ok(())
}

#[allow(clippy::too_many_arguments)]
async fn handle_block_response<Payload: AbstractExecPayload<E>>(
&self,
log: &Logger,
Expand Down
8 changes: 8 additions & 0 deletions validator_client/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
.value_name("FEE-RECIPIENT")
.takes_value(true)
)
.arg(
Arg::with_name("produce-block-v3")
.long("produce-block-v3")
.help("Enable block production via the block v3 endpoint for this validator client. \
This should only be enabled when paired with a beacon node \
that has this endpoint implemented.")
.takes_value(false)
)
/* REST API related arguments */
.arg(
Arg::with_name("http")
Expand Down
7 changes: 7 additions & 0 deletions validator_client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ pub struct Config {
pub enable_latency_measurement_service: bool,
/// Defines the number of validators per `validator/register_validator` request sent to the BN.
pub validator_registration_batch_size: usize,
/// Enables block production via the block v3 endpoint. This configuration option can be removed post deneb.
pub produce_block_v3: bool,
}

impl Default for Config {
Expand Down Expand Up @@ -120,6 +122,7 @@ impl Default for Config {
disable_run_on_all: false,
enable_latency_measurement_service: true,
validator_registration_batch_size: 500,
produce_block_v3: false,
}
}
}
Expand Down Expand Up @@ -361,6 +364,10 @@ impl Config {
config.builder_proposals = true;
}

if cli_args.is_present("produce-block-v3") {
config.produce_block_v3 = true;
}

config.gas_limit = cli_args
.value_of("gas-limit")
.map(|gas_limit| {
Expand Down
6 changes: 6 additions & 0 deletions validator_client/src/validator_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pub struct ValidatorStore<T, E: EthSpec> {
fee_recipient_process: Option<Address>,
gas_limit: Option<u64>,
builder_proposals: bool,
produce_block_v3: bool,
task_executor: TaskExecutor,
_phantom: PhantomData<E>,
}
Expand Down Expand Up @@ -128,6 +129,7 @@ impl<T: SlotClock + 'static, E: EthSpec> ValidatorStore<T, E> {
fee_recipient_process: config.fee_recipient,
gas_limit: config.gas_limit,
builder_proposals: config.builder_proposals,
produce_block_v3: config.produce_block_v3,
task_executor,
_phantom: PhantomData,
}
Expand Down Expand Up @@ -336,6 +338,10 @@ impl<T: SlotClock + 'static, E: EthSpec> ValidatorStore<T, E> {
self.spec.fork_at_epoch(epoch)
}

pub fn produce_block_v3(&self) -> bool {
self.produce_block_v3
}

/// Returns a `SigningMethod` for `validator_pubkey` *only if* that validator is considered safe
/// by doppelganger protection.
fn doppelganger_checked_signing_method(
Expand Down

0 comments on commit a8ded56

Please sign in to comment.