Skip to content
Merged
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
2 changes: 1 addition & 1 deletion crates/blockchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ impl Handler<NewAttestation> for BlockChainServer {
// Early aggregation only advances the current slot's group counts, so a
// late- or future-slot attestation can never cross the threshold; skip
// the check unless this attestation is for the store's current slot.
let current_slot = self.store.time().expect("store time exists") / INTERVALS_PER_SLOT;
let current_slot = self.store.current_slot();
if msg.attestation.data.slot == current_slot {
self.maybe_start_early_aggregation(ctx).await;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/blockchain/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ pub fn on_tick(store: &mut Store, timestamp_ms: u64, has_proposal: bool) {
.set_time(store.time().unwrap() + 1)
.expect("set_time should succeed");

let slot = store.time().unwrap() / INTERVALS_PER_SLOT;
let slot = store.current_slot();
let interval = SlotInterval::from_intervals_since_genesis(store.time().unwrap());

trace!(%slot, ?interval, "processing tick");
Expand Down Expand Up @@ -637,7 +637,7 @@ fn on_block_core(
// Horizon is the current slot plus one whole slot of margin, so an intended
// early block still imports (mirrors the attestation future-slot guard, but
// with a whole-slot rather than one-interval margin).
let current_slot = store.time().expect("DB read should succeed") / INTERVALS_PER_SLOT;
let current_slot = store.current_slot();
if slot > current_slot + 1 {
return Err(StoreError::BlockTooFarInFuture {
block_slot: slot,
Expand Down
11 changes: 8 additions & 3 deletions crates/storage/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use ethlambda_types::{
Block, BlockBody, BlockHeader, MultiMessageAggregate, SignedBlock, SingleMessageAggregate,
},
checkpoint::Checkpoint,
constants::INTERVALS_PER_SLOT,
genesis::GenesisConfig,
primitives::{H256, HashTreeRoot as _},
state::{ChainConfig, State, anchor_pair_is_consistent},
Expand Down Expand Up @@ -817,9 +818,8 @@ impl Store {

/// Returns the current store time in interval counts since genesis.
///
/// Each increment represents one 800ms interval. Derive slot/interval as:
/// slot = time() / INTERVALS_PER_SLOT
/// interval = time() % INTERVALS_PER_SLOT
/// Each increment represents one 800ms interval. Use [`Self::current_slot`]
/// for the slot; the interval within it is `time() % INTERVALS_PER_SLOT`.
pub fn time(&self) -> Result<u64, Error> {
self.get_metadata(KEY_TIME)
}
Expand All @@ -829,6 +829,11 @@ impl Store {
self.set_metadata(KEY_TIME, &time)
}

/// The current slot, derived from the store clock.
pub fn current_slot(&self) -> u64 {
self.time().expect("store time exists") / INTERVALS_PER_SLOT
}

// ============ Config ============

/// Returns the chain configuration.
Expand Down