Skip to content

Conversation

@mrzeszutko
Copy link
Contributor

Summary

Adds clock tolerance for P2P message slot validation, following Ethereum's MAXIMUM_GOSSIP_CLOCK_DISPARITY approach.

Problem: P2P message validators currently reject messages (and penalize peers) if the message slot is not the current or next slot. This causes issues when valid messages are sent at the end of a slot and arrive slightly after the slot boundary due to network latency.

Solution: Add a 500ms tolerance window for messages from the previous slot. If we're within 500ms of the current slot start, we accept messages for the previous slot instead of penalizing the peer.

Why only check the previous slot?

The validators already accept messages for both the current slot and the next slot. This means:

  • Future messages (next slot): Already allowed - no change needed
  • Late messages (previous slot): Now allowed within the 500ms tolerance window
  • Older messages (2+ slots behind): Still rejected - these are too stale

Since we already permit early messages for the next slot, the only gap was handling slightly late messages for the previous slot. This change closes that gap.

Key implementation details

  • MAXIMUM_GOSSIP_CLOCK_DISPARITY_MS = 500 (milliseconds) - hardcoded to match Ethereum's current value. Can be made configurable via environment variables in the future if needed.
  • Uses millisecond precision for accurate boundary checking
  • Both attestation and proposal validators now use the shared isWithinClockTolerance() helper
  • Late messages within tolerance continue normal validation (proposer/attester checks still apply using the message's slot)

Test plan

  • Unit tests for isWithinClockTolerance() with boundary cases (499ms, 500ms, 501ms)
  • Updated attestation validator tests for clock tolerance scenarios
  • Updated proposal validator tests for clock tolerance scenarios
  • All existing tests pass

Fixes A-319

@mrzeszutko mrzeszutko changed the title Adding MAXIMUM_GOSSIP_CLOCK_DISPARITY for p2p validation feat: adding MAXIMUM_GOSSIP_CLOCK_DISPARITY for p2p validation Jan 21, 2026
@mrzeszutko mrzeszutko force-pushed the feature/max-gossip-clock-disparity branch from ef9d4ed to 8828783 Compare January 21, 2026 10:48
Copy link
Contributor

@alexghr alexghr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a couple of questions

}

// Check how far we are into the current slot (in milliseconds)
const { ts: slotStartTs, nowMs } = epochCache.getEpochAndSlotNow();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this check that the epochCache.getEpochAndSlotNow().slot === currentSlot?

const { ts: slotStartTs, nowMs } = epochCache.getEpochAndSlotNow();
// ts is in seconds, convert to ms; nowMs is already in milliseconds
const slotStartMs = slotStartTs * 1000n;
const elapsedMs = Number(nowMs - slotStartMs);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this return a negative number (e.g. in a e2e test since we mess with time)?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants