Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions account_manager/src/validator/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub const PRESIGN: &str = "presign";
pub const DEFAULT_BEACON_NODE: &str = "http://localhost:5052/";
pub const CONFIRMATION_PHRASE: &str = "Exit my validator";
pub const WEBSITE_URL: &str = "https://lighthouse-book.sigmaprime.io/validator_voluntary_exit.html";
pub const BASIS_POINTS: u64 = 1000;

pub fn cli_app() -> Command {
Command::new("exit")
Expand Down Expand Up @@ -102,7 +103,7 @@ pub fn cli_run<E: EthSpec>(matches: &ArgMatches, env: Environment<E>) -> Result<
let client = BeaconNodeHttpClient::new(
SensitiveUrl::parse(&server_url)
.map_err(|e| format!("Failed to parse beacon http server: {:?}", e))?,
Timeouts::set_all(Duration::from_secs(env.eth2_config.spec.seconds_per_slot)),
Timeouts::set_all(Duration::from_millis(env.eth2_config.spec.slot_duration_ms)),
);

let eth2_network_config = env
Expand Down Expand Up @@ -230,7 +231,7 @@ async fn publish_voluntary_exit<E: EthSpec>(
loop {
// Sleep for a slot duration and then check if voluntary exit was processed
// by checking the validator status.
sleep(Duration::from_secs(spec.seconds_per_slot)).await;
sleep(Duration::from_millis(spec.slot_duration_ms)).await;

let validator_data = get_validator_data(client, &keypair.pk).await?;
match validator_data.status {
Expand All @@ -251,7 +252,8 @@ async fn publish_voluntary_exit<E: EthSpec>(
eprintln!("Please keep your validator running till exit epoch");
eprintln!(
"Exit epoch in approximately {} secs",
(exit_epoch - current_epoch) * spec.seconds_per_slot * E::slots_per_epoch()
(exit_epoch - current_epoch) * spec.slot_duration_ms / BASIS_POINTS
* E::slots_per_epoch()
);
break;
}
Expand Down Expand Up @@ -350,7 +352,7 @@ fn get_current_epoch<E: EthSpec>(genesis_time: u64, spec: &ChainSpec) -> Option<
let slot_clock = SystemTimeSlotClock::new(
spec.genesis_slot,
Duration::from_secs(genesis_time),
Duration::from_secs(spec.seconds_per_slot),
Duration::from_millis(spec.slot_duration_ms),
);
slot_clock.now().map(|s| s.epoch(E::slots_per_epoch()))
}
Expand Down
4 changes: 3 additions & 1 deletion beacon_node/beacon_chain/src/beacon_block_streamer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ mod tests {
use std::sync::Arc;
use std::sync::LazyLock;
use tokio::sync::mpsc;
use types::consts::bellatrix::BASIS_POINTS;
use types::{
ChainSpec, Epoch, EthSpec, FixedBytesExtended, Hash256, Keypair, MinimalEthSpec, Slot,
};
Expand Down Expand Up @@ -749,7 +750,8 @@ mod tests {
.execution_block_generator()
.move_to_terminal_block()
.expect("should move to terminal block");
let timestamp = harness.get_timestamp_at_slot() + harness.spec.seconds_per_slot;
let timestamp =
harness.get_timestamp_at_slot() + (harness.spec.slot_duration_ms / BASIS_POINTS);
harness
.execution_block_generator()
.modify_last_block(|block| {
Expand Down
13 changes: 8 additions & 5 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4608,7 +4608,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
// 1. It seems we have time to propagate and still receive the proposer boost.
// 2. The current head block was seen late.
// 3. The `get_proposer_head` conditions from fork choice pass.
let proposing_on_time = slot_delay < self.config.re_org_cutoff(self.spec.seconds_per_slot);
let proposing_on_time = slot_delay < self.config.re_org_cutoff(self.spec.slot_duration_ms);
if !proposing_on_time {
debug!(reason = "not proposing on time", "Not attempting re-org");
return None;
Expand Down Expand Up @@ -4904,7 +4904,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
.and_then(|slot_start| {
let now = self.slot_clock.now_duration()?;
let slot_delay = now.saturating_sub(slot_start);
Some(slot_delay <= self.config.re_org_cutoff(self.spec.seconds_per_slot))
Some(slot_delay <= self.config.re_org_cutoff(self.spec.slot_duration_ms))
})
.unwrap_or(false)
} else {
Expand Down Expand Up @@ -5014,9 +5014,12 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
.start_of(slot)
.unwrap_or_else(|| Duration::from_secs(0)),
);
block_delays
.observed
.is_some_and(|delay| delay >= self.slot_clock.unagg_attestation_production_delay())
block_delays.observed.is_some_and(|delay| {
delay
>= self
.spec
.get_slot_component_duration(self.spec.attestation_due_bps)
})
}

/// Produce a block for some `slot` upon the given `state`.
Expand Down
3 changes: 2 additions & 1 deletion beacon_node/beacon_chain/src/bellatrix_readiness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use execution_layer::BlockByNumberQuery;
use serde::{Deserialize, Serialize, Serializer};
use std::fmt;
use std::fmt::Write;
use types::consts::bellatrix::BASIS_POINTS;
use types::*;

/// The time before the Bellatrix fork when we will start issuing warnings about preparation.
Expand Down Expand Up @@ -147,7 +148,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
if let Some(bellatrix_epoch) = self.spec.bellatrix_fork_epoch {
let bellatrix_slot = bellatrix_epoch.start_slot(T::EthSpec::slots_per_epoch());
let bellatrix_readiness_preparation_slots =
BELLATRIX_READINESS_PREPARATION_SECONDS / self.spec.seconds_per_slot;
BELLATRIX_READINESS_PREPARATION_SECONDS / self.spec.slot_duration_ms / BASIS_POINTS;

if self.execution_layer.is_some() {
// The user has already configured an execution layer, start checking for readiness
Expand Down
5 changes: 4 additions & 1 deletion beacon_node/beacon_chain/src/canonical_head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
.as_utf8_lossy(),
&self.slot_clock,
self.event_handler.as_ref(),
&self.spec,
);

if is_epoch_transition || reorg_distance.is_some() {
Expand Down Expand Up @@ -1319,6 +1320,7 @@ fn observe_head_block_delays<E: EthSpec, S: SlotClock>(
head_block_graffiti: String,
slot_clock: &S,
event_handler: Option<&ServerSentEventHandler<E>>,
spec: &ChainSpec,
) {
let Some(block_time_set_as_head) = slot_clock.now_duration() else {
// Practically unreachable: the slot clock's time should not be before the UNIX epoch.
Expand Down Expand Up @@ -1448,7 +1450,8 @@ fn observe_head_block_delays<E: EthSpec, S: SlotClock>(

// Determine whether the block has been set as head too late for proper attestation
// production.
let late_head = attestable_delay >= slot_clock.unagg_attestation_production_delay();
let late_head =
attestable_delay >= spec.get_slot_component_duration(spec.attestation_due_bps);

// If the block was enshrined as head too late for attestations to be created for it,
// log a debug warning and increment a metric.
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/beacon_chain/src/chain_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ impl Default for ChainConfig {

impl ChainConfig {
/// The latest delay from the start of the slot at which to attempt a 1-slot re-org.
pub fn re_org_cutoff(&self, seconds_per_slot: u64) -> Duration {
pub fn re_org_cutoff(&self, slot_duration_ms: u64) -> Duration {
self.re_org_cutoff_millis
.map(Duration::from_millis)
.unwrap_or_else(|| {
Duration::from_secs(seconds_per_slot) / DEFAULT_RE_ORG_CUTOFF_DENOMINATOR
Duration::from_millis(slot_duration_ms) / DEFAULT_RE_ORG_CUTOFF_DENOMINATOR
})
}
}
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/data_availability_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ mod test {
let slot_clock = TestingSlotClock::new(
Slot::new(0),
Duration::from_secs(0),
Duration::from_secs(spec.seconds_per_slot),
Duration::from_millis(spec.slot_duration_ms),
);
let kzg = get_kzg(&spec);
let store = Arc::new(HotColdDB::open_ephemeral(<_>::default(), spec.clone()).unwrap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ impl<T: BeaconChainTypes> VerifiedLightClientFinalityUpdate<T> {
.slot_clock
.start_of(rcv_finality_update.signature_slot())
.ok_or(Error::SigSlotStartIsNone)?;
let one_third_slot_duration = Duration::new(chain.spec.seconds_per_slot / 3, 0);
let one_third_slot_duration = chain
.spec
.get_slot_component_duration(chain.spec.sync_message_due_bps);
if seen_timestamp + chain.spec.maximum_gossip_clock_disparity()
< start_time + one_third_slot_duration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ impl<T: BeaconChainTypes> VerifiedLightClientOptimisticUpdate<T> {
.slot_clock
.start_of(rcv_optimistic_update.signature_slot())
.ok_or(Error::SigSlotStartIsNone)?;
let one_third_slot_duration = Duration::new(chain.spec.seconds_per_slot / 3, 0);

let one_third_slot_duration = chain
.spec
.get_slot_component_duration(chain.spec.sync_message_due_bps);

if seen_timestamp + chain.spec.maximum_gossip_clock_disparity()
< start_time + one_third_slot_duration
{
Expand Down
35 changes: 23 additions & 12 deletions beacon_node/beacon_chain/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ use store::{HotColdDB, ItemStore, MemoryStore, config::StoreConfig};
use task_executor::TaskExecutor;
use task_executor::{ShutdownReason, test_utils::TestRuntime};
use tree_hash::TreeHash;
use types::consts::bellatrix::BASIS_POINTS;
use types::indexed_attestation::IndexedAttestationBase;
use types::payload::BlockProductionVersion;
use types::test_utils::TestRandom;
Expand Down Expand Up @@ -484,21 +485,26 @@ where
.expect("cannot recalculate fork times without spec");
mock.server.execution_block_generator().shanghai_time =
spec.capella_fork_epoch.map(|epoch| {
genesis_time + spec.seconds_per_slot * E::slots_per_epoch() * epoch.as_u64()
genesis_time
+ (spec.slot_duration_ms / BASIS_POINTS) * E::slots_per_epoch() * epoch.as_u64()
});
mock.server.execution_block_generator().cancun_time = spec.deneb_fork_epoch.map(|epoch| {
genesis_time + spec.seconds_per_slot * E::slots_per_epoch() * epoch.as_u64()
genesis_time
+ (spec.slot_duration_ms / BASIS_POINTS) * E::slots_per_epoch() * epoch.as_u64()
});
mock.server.execution_block_generator().prague_time =
spec.electra_fork_epoch.map(|epoch| {
genesis_time + spec.seconds_per_slot * E::slots_per_epoch() * epoch.as_u64()
genesis_time
+ (spec.slot_duration_ms / BASIS_POINTS) * E::slots_per_epoch() * epoch.as_u64()
});
mock.server.execution_block_generator().osaka_time = spec.fulu_fork_epoch.map(|epoch| {
genesis_time + spec.seconds_per_slot * E::slots_per_epoch() * epoch.as_u64()
genesis_time
+ (spec.slot_duration_ms / BASIS_POINTS) * E::slots_per_epoch() * epoch.as_u64()
});
mock.server.execution_block_generator().amsterdam_time =
spec.gloas_fork_epoch.map(|epoch| {
genesis_time + spec.seconds_per_slot * E::slots_per_epoch() * epoch.as_u64()
genesis_time
+ (spec.slot_duration_ms / BASIS_POINTS) * E::slots_per_epoch() * epoch.as_u64()
});

self
Expand Down Expand Up @@ -543,7 +549,7 @@ where
let (shutdown_tx, shutdown_receiver) = futures::channel::mpsc::channel(1);

let spec = self.spec.expect("cannot build without spec");
let seconds_per_slot = spec.seconds_per_slot;
let slot_duration_ms = spec.slot_duration_ms;
let validator_keypairs = self
.validator_keypairs
.expect("cannot build without validator keypairs");
Expand Down Expand Up @@ -587,7 +593,7 @@ where
builder.slot_clock(testing_slot_clock)
} else if builder.get_slot_clock().is_none() {
builder
.testing_slot_clock(Duration::from_secs(seconds_per_slot))
.testing_slot_clock(Duration::from_millis(slot_duration_ms))
.expect("should configure testing slot clock")
} else {
builder
Expand Down Expand Up @@ -623,19 +629,24 @@ pub fn mock_execution_layer_from_parts<E: EthSpec>(
task_executor: TaskExecutor,
) -> MockExecutionLayer<E> {
let shanghai_time = spec.capella_fork_epoch.map(|epoch| {
HARNESS_GENESIS_TIME + spec.seconds_per_slot * E::slots_per_epoch() * epoch.as_u64()
HARNESS_GENESIS_TIME
+ (spec.slot_duration_ms / BASIS_POINTS) * E::slots_per_epoch() * epoch.as_u64()
});
let cancun_time = spec.deneb_fork_epoch.map(|epoch| {
HARNESS_GENESIS_TIME + spec.seconds_per_slot * E::slots_per_epoch() * epoch.as_u64()
HARNESS_GENESIS_TIME
+ (spec.slot_duration_ms / BASIS_POINTS) * E::slots_per_epoch() * epoch.as_u64()
});
let prague_time = spec.electra_fork_epoch.map(|epoch| {
HARNESS_GENESIS_TIME + spec.seconds_per_slot * E::slots_per_epoch() * epoch.as_u64()
HARNESS_GENESIS_TIME
+ (spec.slot_duration_ms / BASIS_POINTS) * E::slots_per_epoch() * epoch.as_u64()
});
let osaka_time = spec.fulu_fork_epoch.map(|epoch| {
HARNESS_GENESIS_TIME + spec.seconds_per_slot * E::slots_per_epoch() * epoch.as_u64()
HARNESS_GENESIS_TIME
+ (spec.slot_duration_ms / BASIS_POINTS) * E::slots_per_epoch() * epoch.as_u64()
});
let amsterdam_time = spec.gloas_fork_epoch.map(|epoch| {
HARNESS_GENESIS_TIME + spec.seconds_per_slot * E::slots_per_epoch() * epoch.as_u64()
HARNESS_GENESIS_TIME
+ (spec.slot_duration_ms / BASIS_POINTS) * E::slots_per_epoch() * epoch.as_u64()
});

let kzg = get_kzg(&spec);
Expand Down
3 changes: 2 additions & 1 deletion beacon_node/beacon_chain/src/validator_custody.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{
collections::{BTreeMap, HashMap},
sync::atomic::{AtomicU64, Ordering},
};
use types::consts::bellatrix::BASIS_POINTS;
use types::data_column_custody_group::{CustodyIndex, compute_columns_for_custody_group};
use types::{ChainSpec, ColumnIndex, Epoch, EthSpec, Slot};

Expand Down Expand Up @@ -87,7 +88,7 @@ impl ValidatorRegistrations {
// the node has enough time to subscribe to subnets etc, and to avoid having
// inconsistent column counts within an epoch.
let effective_delay_slots =
CUSTODY_CHANGE_DA_EFFECTIVE_DELAY_SECONDS / spec.seconds_per_slot;
CUSTODY_CHANGE_DA_EFFECTIVE_DELAY_SECONDS / spec.slot_duration_ms / BASIS_POINTS;
let effective_epoch =
(current_slot + effective_delay_slots).epoch(E::slots_per_epoch()) + 1;
self.epoch_validator_custody_requirements
Expand Down
Loading
Loading