Skip to content

expected_current_slot and slot_timestamp hardcode 12-second slots #808

Description

@lovon-spec

ConsensusSpec parameterizes every consensus constant that differs between presets except the slot duration. Three sites assume 12 seconds (master @ 43a8c9f):

  • pub fn expected_current_slot(now: SystemTime, genesis_time: u64) -> u64 {
    let now = now.duration_since(UNIX_EPOCH).unwrap_or_default().as_secs();
    let since_genesis = now - genesis_time;
    since_genesis / 12
    }
    — expected_current_slot computes since_genesis / 12
  • fn slot_timestamp(&self, slot: u64) -> u64 {
    slot * 12 + self.config.chain.genesis_time
    }
    — Inner::slot_timestamp computes slot * 12; used by is_valid_checkpoint and the head-age log line
  • let mut interval = interval_at(start, std::time::Duration::from_secs(12));
    — the advance loop ticks every Duration::from_secs(12), and
    let time_to_next_slot = next_slot_timestamp - now;
    phases each tick 4 s (one third of a 12 s slot) into the slot

A ConsensusSpec for a chain with a different slot time therefore gets wrong wall-clock slots. On a 5-second chain (Gnosis), expected_current_slot is 2.4x too low, so verify_generic_update rejects every fresh update with InvalidTimestamp; and slot_timestamp ages checkpoints 2.4x too fast, so a checkpoint that is 6 days old fails the max_checkpoint_age check as 14.4 days old. The minimal preset the test vectors under testdata/ are built from also declares SECONDS_PER_SLOT: 6, which MinimalConsensusSpec cannot express.

Proposed fix: a ConsensusSpec::seconds_per_slot() default method returning 12, used at those three sites, with MinimalConsensusSpec overriding to 6. Mainnet is unaffected. PR: #809.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions