CKB Pulse

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

Prefer
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.

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)

More about CKB node, RPC and indexer

All 45 in this topic

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.

Drawn from public commits and checked against the commit each one came from and the project's code today. Read the source before you rely on one. Text under CC BY 4.0: credit LusoCryptoLabs, CKB lessons, with a link to the lesson. Want a lesson changed or removed? Open an issue.