Skip to content
Draft
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
6 changes: 3 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ crates/

### Tick-Based Validator Duties (4-second slots, 5 intervals per slot)
```
Interval 0: Block proposal → accept attestations if proposal exists
Interval 0: Block published (at the slot boundary). The build+publish code path is merged into the previous slot's interval 4 (see below) and aligned to publish here; no attestation acceptance happens at interval 0.
Interval 1: Attestation production (all validators, including proposer)
Interval 2: Aggregation (aggregators create proofs from gossip signatures)
Interval 3: Safe target update (fork choice)
Interval 4: Accept accumulated attestations
Interval 4: Accept accumulated attestations; build the NEXT slot's block and publish it aligned to that slot's interval 0 (build and publish merged into this tick)
```

### Attestation Pipeline
```
Gossip → Signature verification → new_attestations (pending)
↓ (intervals 0/4)
↓ (interval 4)
promote → known_attestations (fork choice active)
Fork choice head update
Expand Down
33 changes: 33 additions & 0 deletions crates/blockchain/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ pub struct PostBlockCheckpoints {
pub finalized: Checkpoint,
}

/// Whether a pre-build that has just finished has already run into (or past)
/// the start of its target slot — i.e. into the interval-0 publish window.
///
/// When true, the overrun-catch-up in `handle_tick` will have skipped that
/// slot's interval-0 proposal tick, so the freshly built block must be
/// published in place rather than stashed for a tick that will never fire.
///
/// Pure so it can be unit-tested without an actor or store.
pub(crate) fn build_overran_publish_window(now_ms: u64, genesis_time_ms: u64, slot: u64) -> bool {
now_ms >= genesis_time_ms + slot * crate::MILLISECONDS_PER_SLOT
}

/// Build a valid block on top of this state.
///
/// Selects attestations via `select_attestations`, compacts duplicate
Expand Down Expand Up @@ -1336,3 +1348,24 @@ mod tests {
assert_eq!(covered, HashSet::from([0, 1, 2, 3]));
}
}

#[cfg(test)]
mod prebuild_tests {
use super::*;

#[test]
fn overran_only_once_now_reaches_slot_start() {
let genesis = 1000;
let slot = 10;
let slot_start = genesis + slot * crate::MILLISECONDS_PER_SLOT;
// Build finished before the target slot opened: stash for interval 0.
assert!(!build_overran_publish_window(slot_start - 1, genesis, slot));
// Build finished exactly at / past the slot start: publish in place.
assert!(build_overran_publish_window(slot_start, genesis, slot));
assert!(build_overran_publish_window(
slot_start + 5_000,
genesis,
slot
));
}
}
Loading
Loading