CKB Pulse

全部经验 · CKB node, RPC and indexer · 从这里开始 · 术语表

Validate header and epoch lookups before using timestamps实践来自一次修复

来自一次修复 · 核对结果:正确 · 核对于 2026-11-19

After get_header_by_number or get_epoch_by_number, treat a null result as unavailable and check that the returned number equals the one you asked for. To get an epoch's start time, read the header at the EpochView's start_number. Then check that this header's epoch field has the epoch number in its low 24 bits and 0 in bits 24 to 39 (the block's index within the epoch), so the block really is the first block of that epoch.

为什么重要: Without these checks a node that answers for a neighbouring block or epoch gets that block's time shown as this one's exact date, and it is then cached as if it were correct.

代码模式

const h = await rpc.call('get_header_by_number',[hex]); if(!h || BigInt(h.number)!==wanted) throw ...; return BigInt(h.timestamp)
readBlockTime(rpc, epoch.start_number) trusted blindly → check (header.epoch & 0xffffff)==epoch && ((header.epoch>>24)&0xffff)==0

同一提交中改动了测试

它与修复在一起,我们没有运行它。

概念
Network and RPC reliability, Since and time locks, Data encoding (molecule, hex, bigints)
证据
来自一次修复: 来自一个项目,已对照其提交核对
首次出现
2026-11-12
最近改动
2026-11-12
最近核对
2026-11-19
对照提交的核对结果
正确:这条经验出自该提交,并且在今天的代码中仍然成立

来源(2)

更多关于CKB node, RPC and indexer

查看此主题的全部 45 条

你维护这条经验的来源项目吗?请确认或纠正

引用这条经验
LusoCryptoLabs, "Validate header and epoch lookups before using timestamps", CKB lessons, https://pulse.lusocryptolabs.com/learned/node/validate-header-and-epoch-lookups-before-using-timestamps, CC BY 4.0, last changed 2026-11-12.

取自公开提交,并对照每条经验的来源提交和项目当前代码做了核对。使用前请先读来源。 文本采用 CC BY 4.0:请署名 LusoCryptoLabs, CKB lessons,并附上经验的链接。 想修改或撤下某条经验?请提交 issue。