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

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.
Sample output
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'plusoffset. This value retains the local clock’s skew and does not represent the master clock time.
Timestamp exchange process
Each round does four things:- Sync message:
GET {masterUrl}/syncreturns the master timestampT1. The local timestamp is recorded straight after the response asT1'. - Delay request: the local timestamp
T2is recorded, thenPOST {masterUrl}/delay_reqreturns the master timestampT2'. - Mean network delay:
offset = ((T1' - T1) - (T2 - T2')) / 2 - Local time plus delay:
synchronizedTime = T1' + offset
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.

