All lessons · Rust scripts and ckb-std · Start here · Glossary
Handle None from ckb_sdk Since::extract_metric for invalid since valuesWorkingFrom one fix
From one fix · Check: right · Checked 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".
Why it matters: 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.
Pattern
let (ty, inner_value) = since.extract_metric().unwrap();Taken from the commit, shortened.
- Concepts
- Since and time locks, Data encoding (molecule, hex, bigints)
- Evidence
- From one fix: from one project, checked against its commit
- First seen
- 2026-11-09
- Last changed
- 2026-11-09
- Last checked
- 2026-11-19
- Check against the commit
- right: the lesson follows from its commit and still holds in the code today
Sources (1)
- 2026-11-09 · nervosnetwork/ckb-cli · more from this project
More about 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
Do you maintain a project this lesson came from? Confirm or correct it
Cite this lesson
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.