Timelocks
Relative, measured in blocks, and restarted for each coin the moment it moves.
A timelock stops a spending path from moving a coin before a set moment. In a Liana wallet, only the recovery paths carry one, never the primary spending path.
Bitcoin enforces the wait, not Liana
Liana writes the wait into the script that locks each coin. Here is the policy of a Simple inheritance wallet as its descriptor records it, with the two keys replaced by names:
wsh(or_d(pk(PRIMARY_KEY),and_v(v:pkh(RECOVERY_KEY),older(52596))))pk(PRIMARY_KEY) lets the primary key spend at any time.
and_v(v:pkh(RECOVERY_KEY),older(52596)) lets the recovery key spend too, but
only once the coin is 52,596 blocks old (about 1 year). A Taproot (P2TR) wallet
writes the same path as and_v(v:pk(RECOVERY_KEY),older(52596)) inside tr(...).
Until the coin is old enough, every node on the Bitcoin network rejects a transaction that spends it through that path. The rule holds if you uninstall Liana, if someone takes over the computer that runs it, or if Wizardsardine disappears. Nobody can shorten the wait.
Relative, not absolute
Bitcoin has two kinds of timelock. An absolute timelock opens at a fixed block height or date. A relative timelock opens after a set wait, counted from the block that confirms each coin.
| Absolute | Relative | |
|---|---|---|
| Opens at | A fixed height or date, the same for every coin | A set wait after the coin confirms, in blocks or in steps of 512 seconds |
| Miniscript | after(n) | older(n) |
| Script opcode | OP_CHECKLOCKTIMEVERIFY | OP_CHECKSEQUENCEVERIFY |
| Transaction field | nLockTime, one per transaction | nSequence, one per input |
| In a Liana descriptor | Never | In every recovery path |
A recovery path should open after a period of inactivity, which is the time since a coin last moved. A relative timelock measures exactly that. An absolute one knows only its date, which makes the protection uneven. With a shared deadline of 1 January 2032, a coin received in 2029 is protected for years. A coin received on 30 December 2031 is protected for two days.
A date also goes stale. Near the deadline, you would have to move every coin to
a new script with a later date, which means a new descriptor and a new backup
each time. A relative timelock restarts with one ordinary transaction to the
same descriptor. Liana refuses any descriptor that contains after().
The clock is per coin
A Liana wallet has no single timer. Each coin has its own, started by the block that confirmed it. Say your recovery path waits 52,596 blocks (about 1 year) and a coin confirms in block 900,000. The recovery path can spend that coin from block 952,596, and not one block earlier.
Coins received at different times therefore open at different times. Say one coin confirms on 1 January and another on 1 June. On 1 September, the January coin is eight months into its wait and the June coin three. A coin that no block has confirmed yet has not started its clock at all.
Recovery is never all-or-nothing. When you build a recovery transaction, Liana includes only the coins whose wait is over. The others stay in the wallet until their own wait ends. Recover in Liana shows how to recover the first coins, then the rest.
Every spend restarts the clock
A transaction consumes the coins it spends and creates new ones. Your change is one of these new coins. Its clock starts at the block that confirms the payment. A payment restarts the clock on the change only, never on the coins it leaves untouched.
A coin you never move opens to the recovery keys
Once a coin's wait is over, whoever holds the keys of that recovery path can spend it without you. If that is not what you want yet, refresh the coin before its wait ends.
Refreshing a coin means sending it back to your own wallet with the primary path, so that the new coin starts a full wait. Liana warns you once a coin has 10% of its wait left. A refresh pays a fee. Merging several coins in one refresh links them on-chain. Refresh coins shows how to do it.
The script sets the wait, the transaction declares it
older(52596) turns into two rules that only work as a pair.
- In the script:
older(52596)compiles to<52596> OP_CHECKSEQUENCEVERIFY. The opcode reads no clock. It fails unless the spending input'snSequencedeclares a wait of at least 52,596 blocks. - On the network: Every node compares that declaration with the chain. It
refuses the transaction until the coin is as old as its
nSequencesays.
Without the first rule, a signer could leave the wait out of the transaction. Without the second, nothing would compare the declaration with the coin's age.
lianad fills in nSequence according to the path you spend with:
- Primary path:
0xFFFFFFFDon every input. Its top bit switches the relative timelock off. Its value, below0xFFFFFFFE, signals replace-by-fee. - Recovery path: The timelock of the path you target, in blocks, such as
52596(0x0000CD74) on every input.lianadbuilds version 2 transactions, the first version for which Bitcoin enforces relative timelocks.
Two consequences follow. A single input that is too young invalidates the whole transaction, which is why Liana leaves those coins out. The declaration is also a floor. An earlier path can therefore complete a transaction built for a later one, as the Spending paths page explains.
The ceiling of 65,535 blocks comes from 16 bits
Bitcoin reads only the low 16 bits of nSequence as the wait. The largest value
is therefore 65,535 units. Bit 22 sets the unit, blocks or steps of 512
seconds. Bit 31, when set, turns the relative timelock off.
Liana counts in blocks only. It refuses a descriptor whose older() value falls
outside 1 to 65,535, which excludes the time-based unit. The longest wait is
65,535 blocks (about 1 year and 3 months). You can set any value in that range
when you choose a policy.
A block count is not a date
Bitcoin aims for one block every 10 minutes and retunes the mining difficulty every 2,016 blocks to hold that pace. Between two adjustments the pace drifts. When miners add computing power, blocks come faster, and slower when they leave. For the default of 52,596 blocks, the chain gave these results:
- Confirmed on 1 September 2017 (block 482,885): The recovery path could spend the coin from 6 August 2018, 26 days before the year was up.
- Confirmed on 1 August 2020 (block 641,680): The wait ran until 5 August 2021, four days late.
Liana converts blocks at the target pace: 10 minutes a block, a year of 365.25 days, and a month of a twelfth of a year. The countdown on each coin uses the same conversion. The installer's timelock editor reads these values as follows:
| Blocks | The installer shows |
|---|---|
| 144 | ~ 1 day |
| 1,008 | ~ 7 days |
| 4,383 | ~ 1 month |
| 26,298 | ~ 6 months |
| 52,596 | ~ 1 year |
| 65,535 | ~ 1 year 2 months 28 days |
A recovery path must stay closed until a given date?
Read every duration as an estimate, and set a timelock that ends well after the date.