Precision Time Sources

v2.0.0

Sub-millisecond synchronization for mesh coordination

YAKMESH integrates with quantum, atomic, GPS, PTP, and NTP time sources to enable precision-grade phase synchronization across the mesh network.

Why Precision Time Matters

YAKMESH uses phase epochs to coordinate network consensus. Higher-precision time sources enable tighter phase windows, reducing attack surfaces and improving network synchronization.

  • • Atomic-tier nodes can serve as time oracles for the network
  • • GPS/PTP nodes can validate tight phase windows
  • • NTP nodes still participate but with wider tolerance margins

Trust Levels

Time sources are classified into trust levels based on their precision and reliability. Higher trust levels enable tighter phase tolerances for consensus operations.

QUANTUM

Level 5 • Stratum 0
±1ms
tolerance

Quantum optical network time sources including White Rabbit PTP (WR-PTP), optical atomic references, and entanglement-based synchronization. Sub-nanosecond capable.

WR-PTP Optical Atomic Entanglement Sync

ATOMIC

Level 4 • Stratum 0
±100ms
tolerance

PCIe atomic clocks including Chip-Scale Atomic Clocks (CSAC) and Rubidium oscillators. Reference-grade timing for infrastructure nodes.

PCIe CSAC Rubidium SA.45s Caesium

GPS

Level 3 • Stratum 1
±500ms
tolerance

Hardware GPS receivers with PPS (Pulse-Per-Second) signal output. Provides globally synchronized timing from satellite constellation.

PPS Signal gpsd u-blox Trimble

PTP

Level 2 • Stratum 1
±500ms
tolerance

IEEE 1588 Precision Time Protocol with hardware timestamping. Network-based synchronization for data center and enterprise deployments.

IEEE 1588 ptp4l phc2sys Meinberg

NTP

Level 1 • Stratum 2
±5000ms
tolerance

Standard Network Time Protocol synchronization. Universal fallback available on all network-connected systems.

chrony ntpd systemd-timesyncd w32tm

UNSYNC

Level 0 • Stratum 16
±30000ms
tolerance

No reliable time source available. Degraded mode with wide tolerance. Node cannot participate in time-critical consensus operations.

Degraded Mode Local Clock Only

Quick Reference Table

Trust Level Rank Stratum Tolerance Epoch Duration Grace Period Use Case
QUANTUM 5 0 ±1ms 1 hour 1 min Research labs, quantum networks
ATOMIC 4 0 ±100ms 1 hour 1 min Time oracles, infrastructure nodes
GPS 3 1 ±500ms 2 hours 5 min Edge nodes, outdoor deployments
PTP 2 1 ±500ms 2 hours 5 min Data centers, enterprise networks
NTP 1 2 ±5000ms 6 hours 15 min Standard nodes, home users
UNSYNC 0 16 ±30000ms 12 hours 30 min Degraded mode, offline operation

TimeSourceDetector Class

The TimeSourceDetector class automatically detects available time sources and selects the highest-quality option.

Basic Usage

import { 
  TimeSourceDetector, 
  TimeTrustLevel, 
  PhaseTolerance 
} from './oracle/time-source.js';

// Create detector with hardware detection enabled
const detector = new TimeSourceDetector({ 
  detectHardware: true,
  checkNtp: true,
  refreshInterval: 60000, // Re-check every minute
  verbose: true
});

// Start continuous monitoring
detector.start();

// Get detection results
const results = detector.detect();
console.log('Primary source:', results.primarySource);
console.log('Trust level:', results.trustLevel);
console.log('Phase tolerance:', results.phaseTolerance, 'ms');

Constructor Options

Option Type Default Description
detectHardware boolean true Enable detection of atomic clocks, GPS, and PTP devices
checkNtp boolean true Check NTP/Chrony synchronization status
customDevices object {} Custom device paths for detection
refreshInterval number 60000 Refresh interval in milliseconds (0 to disable)
verbose boolean false Enable verbose logging of detection results

Key Methods

// Start continuous monitoring
detector.start();

// Stop monitoring
detector.stop();

// Manual detection
const results = detector.detect();

// Get current trust level
const trust = detector.getTrustLevel(); // 'atomic', 'gps', 'ntp', etc.

// Get phase tolerance in milliseconds
const tolerance = detector.getPhaseTolerance(); // e.g., 100

// Get NTP stratum equivalent
const stratum = detector.getStratum(); // e.g., 0, 1, 2, 16

// Check if atomic-tier time is available
if (detector.hasAtomicTime()) {
  console.log('Node can serve as time oracle');
}

// Check if high-precision time is available (atomic, GPS, or PTP)
if (detector.hasHighPrecisionTime()) {
  console.log('Node can validate tight phase windows');
}

// Get full status object for API responses
const status = detector.getStatus();

Event Handling

// Listen for detection events
detector.on('detected', (results) => {
  console.log('Time sources detected:', results);
  console.log('Primary:', results.primarySource);
  console.log('Trust:', results.trustLevel);
  console.log('Tolerance:', results.phaseTolerance, 'ms');
});

Device Paths

The detector checks platform-specific device paths for hardware time sources.

Linux

PPS Devices:
/dev/pps0 /dev/pps1 /dev/pps2
PTP Devices:
/dev/ptp0 /dev/ptp1 /dev/ptp2
GPS Devices:
/dev/ttyUSB0 /dev/ttyACM0 /dev/gps0
Chrony Socket:
/var/run/chrony/chronyd.sock

Windows

Time Service:
w32tm
PTP: Requires vendor-specific drivers (Meinberg, etc.)

macOS (Darwin)

PPS Devices:
/dev/pps0
PTP Devices:
/dev/ptp0
GPS Devices:
/dev/cu.usbserial*

Detection Methods

Atomic Clock Detection

The detector identifies atomic clocks through multiple methods:

GPS Detection

GPS receivers are detected via:

PTP Detection

IEEE 1588 PTP synchronization is detected through:

NTP Detection

NTP status is checked via:

Phase Configuration

Use createPhaseConfig() to generate phase epoch configuration based on detected time source quality.

import { 
  TimeSourceDetector, 
  createPhaseConfig 
} from './oracle/time-source.js';

const detector = new TimeSourceDetector({ detectHardware: true });
detector.detect();

const phaseConfig = createPhaseConfig(detector);

console.log(phaseConfig);
// {
//   trustLevel: 'atomic',
//   toleranceMs: 100,
//   epochDurationHours: 1,
//   gracePeriodMinutes: 1,
//   capabilities: {
//     canBeTimeOracle: true,
//     canValidateTightPhase: true,
//     canParticipateInConsensus: true
//   }
// }

Capabilities by Trust Level

Capability QUANTUM ATOMIC GPS PTP NTP UNSYNC
Can be Time Oracle
Validate Tight Phase
Participate in Consensus

Exported Constants

TimeTrustLevel

export const TimeTrustLevel = {
  QUANTUM: 'quantum',   // Quantum optical network (WR-PTP, optical atomic)
  ATOMIC: 'atomic',     // PCIe atomic clock (CSAC, Rubidium)
  GPS: 'gps',           // GPS with PPS signal
  PTP: 'ptp',           // IEEE 1588 PTP synchronized
  NTP: 'ntp',           // Standard NTP
  UNSYNC: 'unsync',     // No reliable time source
};

PhaseTolerance

export const PhaseTolerance = {
  [TimeTrustLevel.QUANTUM]: 1,       // ±1ms for quantum (sub-nanosecond capable)
  [TimeTrustLevel.ATOMIC]: 100,      // ±100ms for atomic
  [TimeTrustLevel.GPS]: 500,         // ±500ms for GPS
  [TimeTrustLevel.PTP]: 500,         // ±500ms for PTP
  [TimeTrustLevel.NTP]: 5000,        // ±5 seconds for NTP
  [TimeTrustLevel.UNSYNC]: 30000,    // ±30 seconds for unsync (degraded mode)
};

StratumLevel

export const StratumLevel = {
  [TimeTrustLevel.QUANTUM]: 0, // Quantum reference (highest)
  [TimeTrustLevel.ATOMIC]: 0,  // Reference clock
  [TimeTrustLevel.GPS]: 1,     // Primary server
  [TimeTrustLevel.PTP]: 1,     // Primary server
  [TimeTrustLevel.NTP]: 2,     // Secondary server
  [TimeTrustLevel.UNSYNC]: 16, // Unsynchronized
};

Helper Functions

Quick Detection

import { detectTimeSources } from './oracle/time-source.js';

// One-shot detection without continuous monitoring
const results = detectTimeSources();
console.log('Detected:', results.primarySource, 'at', results.trustLevel);

Singleton Instance

import { getTimeSourceDetector } from './oracle/time-source.js';

// Get or create the global detector instance
const detector = getTimeSourceDetector({ verbose: true });
detector.start();

// Subsequent calls return the same instance
const sameDetector = getTimeSourceDetector();
console.log(detector === sameDetector); // true

Related Documentation