CKB Pulse

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

Avoid
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)

More about Rust scripts and ckb-std

All 35 in this topic

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.

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.