Chain time (MTP)
Why every covenant decision uses median-time-past, and what that means for deadlines and Dutch decay.
Covenants can't read the wall clock. They can read tx.locktime (the transaction's nLocktime) and check it against the chain via tx.time requirements. The protocol uses median-time-past (MTP), the median timestamp of the last 11 block headers, as its only clock.
The rules
- A transaction is final only if
nLocktime < MTP.nLocktime = MTPis rejected asbad-txns-nonfinal. - The server's
chainClock.finalLocktime()returnsMTP − 1: the latest locktime that is final right now. - Every fill uses that locktime, so the covenant's "now" is
MTP − 1. - Intent times (
expiryTime,startTime) are anchored to the final locktime at creation.
Consequences
- Deadlines move with blocks. An intent becomes refundable only when a new block pushes MTP past its deadline, which is why
new_blockis a refund trigger. - MTP lags wall time. Typically by around an hour. The API returns
refundEligibleAt = covenantDeadline + lagso UIs can show a realistic wall-clock estimate. - Dutch decay is stepwise. The minimum only changes when MTP changes.
- TWAP slices open per block. A slice scheduled at
start + k·intervalopens within about one block of that time.
Note: > If you build fills yourself, never use
Date.now()fornLocktime. Read the last 11 block headers from your Electrum server, take the median timestamp and subtract one.