CKB Pulse

全部经验 · Rust scripts and ckb-std · 从这里开始 · 术语表

Handle None from ckb_sdk Since::extract_metric for invalid since values实践来自一次修复

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

A raw since u64 can carry the reserved metric flag 0b11 (e.g. 0x6000_0000_0000_0000), for which ckb_sdk::Since::extract_metric() returns None, and a timestamp metric value can exceed what chrono can represent. Code that formats since values received from RPC should handle both cases instead of unwrapping, as ckb-cli now does by printing "invalid since" or "invalid".

为什么重要: Calling unwrap on extract_metric or on chrono conversions makes a tool panic when it is given a since value with the reserved 0b11 metric flag or a huge timestamp, so it fails instead of showing the value.

代码模式

避免
let (ty, inner_value) = since.extract_metric().unwrap();

摘自提交,已缩短。

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

来源(1)

更多关于Rust scripts and ckb-std

查看此主题的全部 35 条

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

引用这条经验
LusoCryptoLabs, "Handle None from ckb_sdk Since::extract_metric for invalid since values", CKB lessons, https://pulse.lusocryptolabs.com/learned/scripts/handle-none-from-ckb-sdk-since-extract-metric-for-invalid-si, CC BY 4.0, last changed 2026-11-09.

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