All lessons · CKB node, RPC and indexer · Start here · Glossary
Decoding the packed epoch field (number, index, length)WorkingSeen again
Seen again · Check: right · Checked 2026-11-19
A CKB header epoch field packs the epoch number in the low 24 bits, the index in the next 16 bits (shift 24) and the epoch length in the next 16 bits (shift 40). When estimating time to a target epoch from the tip, subtract the fraction already spent (index * epoch duration / length) and guard against length 0 to avoid division by zero.
Why it matters: Reading the raw epoch hex as a number, or masking it wrongly, gives nonsense epoch numbers for window checks. Ignoring the index fraction makes time-to-epoch estimates off by up to a whole epoch, about four hours.
Pattern
number: v & 0xffffffn, index: (v >> 24n) & 0xffffn, length: (v >> 40n) & 0xffffn,Taken from the commit, shortened.
A test changed in the same commit
It sits next to the fix. We did not run it.
- toastmanAu/daowow:
apps/web/test/model-time.test.js - toastmanAu/daowow:
apps/web/test/round-rules.test.js
- Concepts
- Since and time locks, Data encoding (molecule, hex, bigints)
- Evidence
- Seen again: seen in two or more projects
- First seen
- 2026-11-10
- Last changed
- 2026-11-10
- Last checked
- 2026-11-19
- Check against the commit
- right: the lesson follows from its commit and still holds in the code today
Sources (3)
- 2026-11-10 · toastmanAu/daowow · more from this project
- 2026-10-24 · toastmanAu/ckb-watch-visualiser · more from this project
- 2026-10-13 · toastmanAu/daowow · more from this project
More about CKB node, RPC and indexer
- Validate header and epoch lookups before using timestamps
- Nervos DAO compensation from the header's accumulated rate (AR)
- Nervos DAO phase 1 withdrawing cells keep the DAO type; count deposits by 8 zero bytes of data
Do you maintain a project this lesson came from? Confirm or correct it
Cite this lesson
LusoCryptoLabs, "Decoding the packed epoch field (number, index, length)", CKB lessons, https://pulse.lusocryptolabs.com/learned/node/decoding-the-packed-epoch-field-number-index-length, CC BY 4.0, last changed 2026-11-10.