Skip to main content
Universal Machine Time (UMT) gives machines a shared time reference: a master clock takes its time from the peaq chain, and devices exchange Precision Time Protocol (PTP) timestamps with it. The SDK’s subscribeToPtp returns the mean one-way network delay of each exchange; it does not adjust the local clock.

PTP on peaq

Block timestamps alone are too coarse for machines that have to agree on when something happened. UMT adds:
  • Network delay estimates and timestamps expressed in nanoseconds
  • A master clock whose time comes from chain state, so any party can check it
  • A delay estimate computed from two timestamp exchanges

Architecture

ptp-image-1

Usage

This runs in any JavaScript project, server or client. Install the SDK first, see Install the peaq SDK.

subscribeToPtp(options, callback)

subscribeToPtp returns a function that stops the subscription.
With the default interval, the callback runs once per second until you unsubscribe.

Sample output

Both values are bigint nanoseconds, and synchronizedTime is a Unix timestamp.
  • offset: the mean one-way network delay between the two exchanges. Clock skew between the local and master clocks cancels out of the formula and is not corrected.
  • synchronizedTime: the local receive timestamp T1' plus offset. This value retains the local clock’s skew and does not represent the master clock time.

Timestamp exchange process

Each round does four things:
  1. Sync message: GET {masterUrl}/sync returns the master timestamp T1. The local timestamp is recorded straight after the response as T1'.
  2. Delay request: the local timestamp T2 is recorded, then POST {masterUrl}/delay_req returns the master timestamp T2'.
  3. Mean network delay: offset = ((T1' - T1) - (T2 - T2')) / 2
  4. Local time plus delay: synchronizedTime = T1' + offset
To correct the local clock against the master, call GET {masterUrl}/sync and POST {masterUrl}/delay_req yourself and compute the PTP offset of the local clock from the same four timestamps: ((T1' - T1) - (T2' - T2)) / 2. Subtract it from the local time to get master-clock time.

Error handling

If a round fails, for example on a network or server error, the SDK logs the error and skips the callback for that round. The subscription stays active and tries again on the next interval.