Definition
Epoch fencing is a rule that lets a protected resource refuse requests made under authority that has been replaced. Each grant of authority, such as a new owner or a new signing key, gets an epoch: a generation number larger than every earlier one. The resource stores a floor, the smallest epoch it still accepts, and refuses every request whose epoch is below the floor. Stale authority is authority from an epoch below the floor: once valid, now replaced, possibly without its holder knowing.
The idea
A device obeys commands signed by its owner. The owner’s signing key for epoch 41 may have been stolen, so the owner moves to a new key for epoch 42, a key rotation §5.29. Signatures made with the old key still verify: the signature check alone cannot tell that the key has been retired. The device must remember that epoch 41 is over, and must remember it across restarts. The same problem arises without theft: a controller that stalls, loses its lease (a time-limited grant of authority) and resumes still believes it is in charge, and its requests are correctly signed. The Lease and exclusive ownership §13.26 entry follows that case.
Epoch fencing puts the decision at the resource, which needs only one number that never goes down. Picture a building whose locks are being changed: the guard posts a notice that only keys of series 42 or later open the doors, and a genuine series-41 key is refused. The picture stops in one place. In the building, the series-42 keys exist before the notice goes up. In a device, raising the floor and installing the new key are separate writes, a power failure can fall between them, and the order of the writes decides whether the device survives that failure.
How it works
A scheme that ties each epoch to a key keeps three things.
Epoch : an integer that the authority places in every request, inside the bytes its digital signature §5.14 covers, so that nobody can change the epoch of a request without breaking its signature.
Key record for an epoch: the key that verifies that epoch’s requests, stored with the epoch number and a checksum §4.32, a short value computed over the record that shows whether the record was written completely.
Floor : the smallest epoch the resource accepts, kept in durable storage, which survives power loss and restart.
The resource checks each request in this order:
Read the epoch from the request.
Refuse the request if .
Find a complete key record for ; refuse the request if there is none.
Verify the signature with that key; refuse the request if verification fails.
Carry out the request.
The floor plays the same role for authority that a version high-water mark §8.27 plays for software versions.
Replacing epoch 41 with epoch 42 takes three steps, each finished in durable storage before the next begins.
Prepare. Write the key record for epoch 42 beside the record for epoch 41, then read it back and check it. The instruction to move to epoch 42 must itself be authorized, for example by a root key §5.25 that ranks above the epoch keys and is kept offline. If the epoch-41 key may be stolen, its signature alone must not be enough, or the thief could install an epoch-42 key of the thief’s own. The floor is still 41, so the old key still works, and nothing is lost if this step fails.
Commit. Raise the floor to 42 in one atomic write: a write that, after a power failure, is found either complete or not done at all, never half done. From this moment epoch 41 is refused.
Clean up. Erase the epoch-41 key record. The floor already refuses epoch 41, so this step only frees space.
A shorter design writes the new key and the new floor atomically in a single record, so the floor cannot get ahead of its key. Some systems raise the floor implicitly instead: the first verified request with a larger epoch raises it. The same order holds there, because a request of epoch 42 can be verified only once a complete key record for epoch 42 exists. After a restart, a prepared but uncommitted epoch is committed if its stored authorization §1.7 is valid and discarded otherwise, by a rule fixed in advance.
Worked example
The device starts with key record A for epoch 41 and floor . The owner replaces epoch 41 with epoch 42, whose key record is B. A crash cut is the state that a power failure at one point of a sequence of writes leaves behind. Compare two orders of the same writes.
Floor first (wrong). The device writes , then record B, then erases A. Power fails right after the first write. On restart the device holds and only record A. A request of epoch 41 is refused because . A request of epoch 42 passes the floor check, but no record B exists to verify its signature, so it is refused as well. Every request is refused: the device has failed closed and stays locked until someone restores it by a path outside the protocol. A power failure during the write of B ends the same way, because a half-written record B fails its checksum.
Prepare, commit, clean up (right). The crash cuts are:
| Power fails | Floor | Complete records | Accepted epochs |
|---|---|---|---|
| during the write of B | 41 | A | 41 |
| after B, before the floor | 41 | A, B | 41, 42 |
| after the floor | 42 | A, B | 42 |
| after erasing A | 42 | B | 42 |
A power failure during the floor write gives the second or the third row, because that write is atomic. Every row has an accepted epoch, so no crash locks the device. The price is the second row: until the commit, the old key still works. The commit should therefore follow the prepare step at once, and a device that restarts in the second row should complete the commit before it accepts any request.
Stated precisely
Let be the stored floor. For an epoch , let be the key in a complete key record for , or , read as none, if no complete record exists. Let be the epoch carried by a request . The resource accepts only if
Two properties are wanted.
Stale exclusion, a safety property §1.11: once has been durably set to , no request with is ever accepted again, across any number of restarts.
Recoverability, an availability §1.10 property: at every crash cut, some epoch has , and the authorized holder of that epoch can still sign requests for it.
Two ordering rules give recoverability: raise to only after the key record for is durably written and verified; and erase a key record only while another epoch at or above the floor keeps a complete one.
Both properties rest on five assumptions.
Atomic, durable floor writes. After a power failure, the stored floor holds either its old value or its new one.
A floor that never decreases, by any path: no recovery routine, factory reset or second copy of the floor brings it back down.
Authenticated epochs. The epoch lies inside the signed bytes, and only the current authority can authorize a key record for a new epoch or a raise of the floor. Otherwise anyone could raise the floor to an epoch that has no key and lock the owner out, a denial of service §1.28.
Complete mediation §1.16. Every path that acts on the resource performs the check.
No counter wraparound §6.21. The epoch field is wide enough never to return to 0 during the life of the device.
Limits and common mistakes
Fencing protects only what checks the floor. What the stale holder did before the floor rose stays done, and actions outside the resource, such as messages the stale holder sent to other parties, are not fenced.
Fencing does not choose the next authority. It refuses the old one; deciding who holds epoch 42 is the job of the owner, of a lease service, or of an agreement protocol among several machines.
Lowering the floor to restore service reopens the attack the rotation was meant to stop: a recovery routine that readmits epoch 41 hands the device to whoever holds the stolen epoch-41 key. When the protocol itself cannot recover, the safe outcome is to fail closed §1.13 until an authorized recovery outside the protocol, accepting the loss of availability.
A floor that resets, for example when the whole storage is erased, accepts every old epoch again; see the entry on lifecycle reset and replay §19.3.7. A floor kept in two copies needs a rule for choosing between them after a crash; see the entry on redundant copies and split-brain records §19.3.6.
Questions answered
What if the fence is advanced before replacement key state is complete?
Then a power failure at the wrong moment leaves the device with no usable authority. The fence, a stored floor below which every authority epoch is refused, already refuses the old epoch, while the new epoch cannot be used because its key record, the stored key that verifies its requests, is missing or only half written. Every request is refused: the device fails closed and stays locked until an authorized recovery path outside the normal protocol restores it.
Lowering the floor again to restore service is not a repair, because it readmits the old key that the replacement was meant to retire. The correct order is to write the replacement key record durably and verify it, then raise the floor in one atomic write, which after a power failure is found either complete or not done, and only then erase the old record. An equivalent design writes the new key and the new floor together in one atomic record. Either way, every crash leaves at least one epoch at or above the floor with a complete key record.
Related entries: Lease and exclusive ownership (§13.26), Commit record and selector (§8.21), Staging versus commit versus activation (§8.22), Version high-water mark (§8.27), Key rotation (§5.29), Fail closed (§1.13), Prepare before irreversible commit and allocation-free fallback (§19.3.8).