全部经验 · 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)
- 2026-11-09 · nervosnetwork/ckb-cli · 这个项目的更多经验
更多关于Rust scripts and ckb-std
- Comparing packed epoch values
- Median time vs tip timestamp for deadlines
- Use raw_data(), not as_slice(), when parsing a packed::Bytes witness
引用这条经验
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.